Bug 1516997 p1 - Move hasSyncedThisSession to SyncEngine. r=markh
authorEdouard Oger <eoger@fastmail.com>
Thu, 03 Jan 2019 22:28:15 +0000
changeset 509589 98d8d27b7fdfb53f562ce4372e5b022dbe3f6a37
parent 509588 a1ee2a2f51eaecf36039204880365b5ba6e823eb
child 509590 7be73b4e5299792d47667c8587d56a5b2e36c71e
push id10547
push userffxbld-merge
push dateMon, 21 Jan 2019 13:03:58 +0000
treeherdermozilla-beta@24ec1916bffe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmarkh
bugs1516997
milestone66.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1516997 p1 - Move hasSyncedThisSession to SyncEngine. r=markh Differential Revision: https://phabricator.services.mozilla.com/D15657
services/sync/modules/engines.js
services/sync/modules/engines/tabs.js
--- a/services/sync/modules/engines.js
+++ b/services/sync/modules/engines.js
@@ -780,16 +780,18 @@ SyncEngine.prototype = {
   // If this is false, we'll throw, otherwise, we'll ignore the record and
   // continue. This currently can only happen due to the record being larger
   // than the record upload limit.
   allowSkippedRecord: true,
 
   // Which sortindex to use when retrieving records for this engine.
   _defaultSort: undefined,
 
+  _hasSyncedThisSession: false,
+
   _metadataPostProcessor(json) {
     if (Array.isArray(json)) {
       // Pre-`JSONFile` storage stored an array, but `JSONFile` defaults to
       // an object, so we wrap the array for consistency.
       json = { ids: json };
     }
     if (!json.ids) {
       json.ids = [];
@@ -972,16 +974,24 @@ SyncEngine.prototype = {
     // Store the value as a string to keep floating point precision
     Svc.Prefs.set(this.name + ".lastSync", lastSync.toString());
   },
   async resetLastSync() {
     this._log.debug("Resetting " + this.name + " last sync time");
     await this.setLastSync(0);
   },
 
+  get hasSyncedThisSession() {
+    return this._hasSyncedThisSession;
+  },
+
+  set hasSyncedThisSession(hasSynced) {
+    this._hasSyncedThisSession = hasSynced;
+  },
+
   get toFetch() {
     this._toFetchStorage.ensureDataReady();
     return this._toFetchStorage.data.ids;
   },
 
   set toFetch(ids) {
     if (ids.constructor.name != "SerializableSet") {
       throw new Error("Bug: Attempted to set toFetch to something that isn't a SerializableSet");
@@ -1803,16 +1813,17 @@ SyncEngine.prototype = {
       } else {
         // For many ids, split into chunks of at most 100
         while (val.length > 0) {
           await doDelete(key, val.slice(0, 100));
           val = val.slice(100);
         }
       }
     }
+    this.hasSyncedThisSession = true;
     await this._tracker.asyncObserver.promiseObserversComplete();
   },
 
   async _syncCleanup() {
     this._needWeakUpload.clear();
     if (!this._modified) {
       return;
     }
@@ -1980,16 +1991,17 @@ SyncEngine.prototype = {
    * local user data.
    */
   async resetClient() {
     return this._notify("reset-client", this.name, this._resetClient)();
   },
 
   async _resetClient() {
     await this.resetLastSync();
+    this.hasSyncedThisSession = false;
     this.previousFailed = new SerializableSet();
     this.toFetch = new SerializableSet();
     this._needWeakUpload.clear();
   },
 
   /**
    * Removes all local Sync metadata and user data for this engine.
    */
--- a/services/sync/modules/engines/tabs.js
+++ b/services/sync/modules/engines/tabs.js
@@ -39,21 +39,16 @@ Utils.deferGetSet(TabSetRecord, "clearte
 function TabEngine(service) {
   SyncEngine.call(this, "Tabs", service);
 }
 TabEngine.prototype = {
   __proto__: SyncEngine.prototype,
   _storeObj: TabStore,
   _trackerObj: TabTracker,
   _recordObj: TabSetRecord,
-  // A flag to indicate if we have synced in this session. This is to help
-  // consumers of remote tabs that may want to differentiate between "I've an
-  // empty tab list as I haven't yet synced" vs "I've an empty tab list
-  // as there really are no tabs"
-  hasSyncedThisSession: false,
 
   syncPriority: 3,
 
   async initialize() {
     await SyncEngine.prototype.initialize.call(this);
 
     // Reset the client on every startup so that we fetch recent tabs.
     await this._resetClient();
@@ -76,17 +71,16 @@ TabEngine.prototype = {
   getClientById(id) {
     return this._store._remoteClients[id];
   },
 
   async _resetClient() {
     await SyncEngine.prototype._resetClient.call(this);
     await this._store.wipe();
     this._tracker.modified = true;
-    this.hasSyncedThisSession = false;
   },
 
   async removeClientData() {
     let url = this.engineURL + "/" + this.service.clientsEngine.localID;
     await this.service.resource(url).delete();
   },
 
   async _reconcile(item) {
@@ -94,21 +88,16 @@ TabEngine.prototype = {
     // TabStore.itemExists tests only against our local client ID.
     if ((await this._store.itemExists(item.id))) {
       this._log.trace("Ignoring incoming tab item because of its id: " + item.id);
       return false;
     }
 
     return SyncEngine.prototype._reconcile.call(this, item);
   },
-
-  async _syncFinish() {
-    this.hasSyncedThisSession = true;
-    return SyncEngine.prototype._syncFinish.call(this);
-  },
 };
 
 
 function TabStore(name, engine) {
   Store.call(this, name, engine);
 }
 TabStore.prototype = {
   __proto__: Store.prototype,