Bug 1119078 - only pre-fetch the sync migration sentinel if using a legacy identity. r=rnewman
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 08 Jan 2015 15:47:51 +1100
changeset 235638 a405fef5be0343fd5e01176679bf6ff61c7ceebe
parent 235637 2c7833c612e0fd0c90c2a9ca7bcd9f416e629332
child 235639 66b114f7c0389a5e0fa5dd8aa35e8e367c6adf0c
push id366
push usercmanchester@mozilla.com
push dateThu, 08 Jan 2015 16:40:24 +0000
reviewersrnewman
bugs1119078
milestone37.0a1
Bug 1119078 - only pre-fetch the sync migration sentinel if using a legacy identity. r=rnewman
services/sync/modules/browserid_identity.js
services/sync/modules/identity.js
services/sync/modules/service.js
--- a/services/sync/modules/browserid_identity.js
+++ b/services/sync/modules/browserid_identity.js
@@ -395,16 +395,26 @@ this.BrowserIDManager.prototype = {
   resetSyncKey: function() {
     this._syncKey = null;
     this._syncKeyBundle = null;
     this._syncKeyUpdated = true;
     this._shouldHaveSyncKeyBundle = false;
   },
 
   /**
+   * Pre-fetches any information that might help with migration away from this
+   * identity.  Called after every sync and is really just an optimization that
+   * allows us to avoid a network request for when we actually need the
+   * migration info.
+   */
+  prefetchMigrationSentinel: function(service) {
+    // nothing to do here until we decide to migrate away from FxA.
+  },
+
+  /**
     * Return credentials hosts for this identity only.
     */
   _getSyncCredentialsHosts: function() {
     return Utils.getSyncCredentialsHostsFxA();
   },
 
   /**
    * The current state of the auth credentials.
--- a/services/sync/modules/identity.js
+++ b/services/sync/modules/identity.js
@@ -442,16 +442,32 @@ IdentityManager.prototype = {
   },
 
   hasBasicCredentials: function hasBasicCredentials() {
     // Because JavaScript.
     return this.username && this.basicPassword && true;
   },
 
   /**
+   * Pre-fetches any information that might help with migration away from this
+   * identity.  Called after every sync and is really just an optimization that
+   * allows us to avoid a network request for when we actually need the
+   * migration info.
+   */
+  prefetchMigrationSentinel: function(service) {
+    // Try and fetch the migration sentinel - it will end up in the recordManager
+    // cache.
+    try {
+      service.recordManager.get(service.storageURL + "meta/fxa_credentials");
+    } catch (ex) {
+      this._log.warn("Failed to pre-fetch the migration sentinel", ex);
+    }
+  },
+
+  /**
    * Obtains the array of basic logins from nsiPasswordManager.
    */
   _getLogins: function _getLogins(realm) {
     return Services.logins.findLogins({}, PWDMGR_HOST, null, realm);
   },
 
   /**
    * Set a login in the password manager.
--- a/services/sync/modules/service.js
+++ b/services/sync/modules/service.js
@@ -1276,22 +1276,22 @@ Sync11Service.prototype = {
       // wait() throws if the first argument is truthy, which is exactly what
       // we want.
       let result = cb.wait();
 
       histogram = Services.telemetry.getHistogramById("WEAVE_COMPLETE_SUCCESS_COUNT");
       histogram.add(1);
 
       // We successfully synchronized.
-      // Try and fetch the migration sentinel - it will end up in the recordManager
-      // cache, so a sync migration doesn't need a server round-trip.
+      // Check if the identity wants to pre-fetch a migration sentinel from
+      // the server.
       // If we have no clusterURL, we are probably doing a node reassignment
-      // do don't attempt to get the credentials.
+      // so don't attempt to get it in that case.
       if (this.clusterURL) {
-        this.recordManager.get(this.storageURL + "meta/fxa_credentials");
+        this.identity.prefetchMigrationSentinel(this);
       }
 
       // Now let's update our declined engines.
       let meta = this.recordManager.get(this.metaURL);
       if (!meta) {
         this._log.warn("No meta/global; can't update declined state.");
         return;
       }