B2G/gecko/services/sync/modules/engines.js
// Any setup that needs to happen at the beginning of each sync.
Any setup that needs to happen at the beginning of each sync.
Any setup that needs to happen at the beginning of each sync .
function SyncEngine__syncStartup() {
    let metaGlobal = Records.get(this.metaURL);
    let engines = metaGlobal.payload.engines || {};
    let engineData = engines[this.name] || {};
    let needsWipe = false;
    if ((engineData.version || 0) < this.version) {
      this._log.debug("Old engine data: " + [engineData.version, this.version]);
      needsWipe = true;
      this.syncID = "";
      engineData.version = this.version;
      engineData.syncID = this.syncID;
      engines[this.name] = engineData;
      metaGlobal.payload.engines = engines;
      metaGlobal.changed = true;
    }
    else if (engineData.version > this.version) {
      let error = new String("New data: " + [engineData.version, this.version]);
      error.failureCode = VERSION_OUT_OF_DATE;
      throw error;
    }
    else if (engineData.syncID != this.syncID) {
      this._log.debug("Engine syncIDs: " + [engineData.syncID, this.syncID]);
      this.syncID = engineData.syncID;
      this._resetClient();
    };
    if (needsWipe) {
      this.wipeServer();
    }
    this.lastSyncLocal = Date.now();
    if (this.lastSync) {
      this._modified = this.getChangedIDs();
    } else {
      this._log.debug("First sync, uploading all items");
      this._modified = {};
      for (let id in this._store.getAllIDs()) {
        this._modified[id] = 0;
      }
    }
    this._tracker.clearChangedIDs();
    this._log.info(Object.keys(this._modified).length +
                   " outgoing items pre-reconciliation");
    this._delete = {};
  }
function SyncEngine__syncStartup ( ) { let metaGlobal = Records . get ( this . metaURL ) ; let engines = metaGlobal . payload . engines || { } ; let engineData = engines [ this . name ] || { } ; let needsWipe = false ; if ( ( engineData . version || 0 ) < this . version ) { this . _log . debug ( "Old engine data: " + [ engineData . version , this . version ] ) ; needsWipe = true ; this . syncID = "" ; engineData . version = this . version ; engineData . syncID = this . syncID ; engines [ this . name ] = engineData ; metaGlobal . payload . engines = engines ; metaGlobal . changed = true ; } else if ( engineData . version > this . version ) { let error = new String ( "New data: " + [ engineData . version , this . version ] ) ; error . failureCode = VERSION_OUT_OF_DATE ; throw error ; } else if ( engineData . syncID != this . syncID ) { this . _log . debug ( "Engine syncIDs: " + [ engineData . syncID , this . syncID ] ) ; this . syncID = engineData . syncID ; this . _resetClient ( ) ; } ; if ( needsWipe ) { this . wipeServer ( ) ; } this . lastSyncLocal = Date . now ( ) ; if ( this . lastSync ) { this . _modified = this . getChangedIDs ( ) ; } else { this . _log . debug ( "First sync, uploading all items" ) ; this . _modified = { } ; for ( let id in this . _store . getAllIDs ( ) ) { this . _modified [ id ] = 0 ; } } this . _tracker . clearChangedIDs ( ) ; this . _log . info ( Object . keys ( this . _modified ) . length + " outgoing items pre-reconciliation" ) ; this . _delete = { } ; }
Any setup that needs to happen at the beginning of each sync.
Any setup that needs to happen at the beginning of each sync .
// Determine if we need to wipe on outdated versions // Assume missing versions are 0 and wipe the server // Prepare to clear the server and upload everything // Set the newer version and newly generated syncID // Put the new data back into meta/global and mark for upload // Don't sync this engine if the server has newer data // Changes to syncID mean we'll need to upload everything // Delete any existing data and reupload on bad version or missing meta. // No crypto component here...? We could regenerate per-collection keys... // Save objects that need to be uploaded in this._modified. We also save // the timestamp of this fetch in this.lastSyncLocal. As we successfully // upload objects we remove them from this._modified. If an error occurs // or any objects fail to upload, they will remain in this._modified. At // the end of a sync, or after an error, we add all objects remaining in // this._modified to the tracker. // Mark all items to be uploaded, but treat them as changed from long ago // Clear the tracker now. If the sync fails we'll add the ones we failed // to upload back. // Keep track of what to delete at the end of sync