def calculate_version_code(values_dict, shift):
  """
  Version Code is calculated based on the four version integers.

  Major is for crosswalk's large update, and minor is for based chromium.
  Major and minor will always be increasing, so use the sum of them is
  enough.
  For each major and minor refresh, build will reset to 0. After that,
  the build will be increasing for 6 weeks (12 weeks if we skip one upstream
  beta rebasing), so 100 numbers for build are enough.
  After we branch it from trunk, the patch will be increasing for the rest of
  this branch's life, 100 numbers are also enough since it will last for most
  24 weeks, but the version increasing will be much less frequent after branch
  point.
  Shift is the last bit for different configurations we want to upload to
  PlayStore.
  """
  try:
    major = values_dict['MAJOR']
    minor = values_dict['MINOR']
    build = values_dict['BUILD']
    patch = values_dict['PATCH']
    return (major + minor) * 100000 +\
           build * 1000 +\
           patch * 10 +\
           shift
  except KeyError:
    return 0