Example #1
0
  /** Do a fresh start then quietly finish the sync, starting another. */
  public void freshStart() {
    final GlobalSession globalSession = this;
    freshStart(
        this,
        new FreshStartDelegate() {

          @Override
          public void onFreshStartFailed(Exception e) {
            globalSession.abort(e, "Fresh start failed.");
          }

          @Override
          public void onFreshStart() {
            try {
              Logger.warn(LOG_TAG, "Fresh start succeeded; restarting global session.");
              globalSession.config.persistToPrefs();
              globalSession.restart();
            } catch (Exception e) {
              Logger.warn(LOG_TAG, "Got exception when restarting sync after freshStart.", e);
              globalSession.abort(e, "Got exception after freshStart.");
            }
          }
        });
  }
Example #2
0
 public void processMissingMetaGlobal(MetaGlobal global) {
   freshStart();
 }
Example #3
0
  /*
   * meta/global callbacks.
   */
  public void processMetaGlobal(MetaGlobal global) {
    config.metaGlobal = global;

    Long storageVersion = global.getStorageVersion();
    if (storageVersion == null) {
      Logger.warn(
          LOG_TAG, "Malformed remote meta/global: could not retrieve remote storage version.");
      freshStart();
      return;
    }
    if (storageVersion < STORAGE_VERSION) {
      Logger.warn(
          LOG_TAG,
          "Outdated server: reported "
              + "remote storage version "
              + storageVersion
              + " < "
              + "local storage version "
              + STORAGE_VERSION);
      freshStart();
      return;
    }
    if (storageVersion > STORAGE_VERSION) {
      Logger.warn(
          LOG_TAG,
          "Outdated client: reported "
              + "remote storage version "
              + storageVersion
              + " > "
              + "local storage version "
              + STORAGE_VERSION);
      requiresUpgrade();
      return;
    }
    String remoteSyncID = global.getSyncID();
    if (remoteSyncID == null) {
      Logger.warn(LOG_TAG, "Malformed remote meta/global: could not retrieve remote syncID.");
      freshStart();
      return;
    }
    String localSyncID = config.syncID;
    if (!remoteSyncID.equals(localSyncID)) {
      Logger.warn(
          LOG_TAG,
          "Remote syncID different from local syncID: resetting client and assuming remote syncID.");
      resetAllStages();
      config.purgeCryptoKeys();
      config.syncID = remoteSyncID;
    }
    // Compare lastModified timestamps for remote/local engine selection times.
    Logger.debug(
        LOG_TAG,
        "Comparing local engine selection timestamp ["
            + config.userSelectedEnginesTimestamp
            + "] to server meta/global timestamp ["
            + config.persistedMetaGlobal().lastModified()
            + "].");
    if (config.userSelectedEnginesTimestamp < config.persistedMetaGlobal().lastModified()) {
      // Remote has later meta/global timestamp. Don't upload engine changes.
      config.userSelectedEngines = null;
    }
    // Persist enabled engine names.
    config.enabledEngineNames = global.getEnabledEngineNames();
    if (config.enabledEngineNames == null) {
      Logger.warn(LOG_TAG, "meta/global reported no enabled engine names!");
    } else {
      if (Logger.shouldLogVerbose(LOG_TAG)) {
        Logger.trace(
            LOG_TAG,
            "Persisting enabled engine names '"
                + Utils.toCommaSeparatedString(config.enabledEngineNames)
                + "' from meta/global.");
      }
    }
    config.persistToPrefs();
    advance();
  }