Bug 1317589 - store the most recent hashed UID so we can still report it on transient errors renewing tokens. r=tcsc
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 15 Nov 2016 16:03:41 +1100
changeset 440392 4cd67fad42edc3ab2f0a77ba7a9d356d8254dec1
parent 440391 ca02f30bc3a0f9a53a1675770363603f829981da
child 440393 03c76266ea8075b294fab9074b0c475eda2c9753
push id36216
push userbmo:ato@mozilla.com
push dateThu, 17 Nov 2016 13:57:13 +0000
reviewerstcsc
bugs1317589
milestone53.0a1
Bug 1317589 - store the most recent hashed UID so we can still report it on transient errors renewing tokens. r=tcsc MozReview-Commit-ID: 4qCFBltcPi1
services/sync/modules/browserid_identity.js
--- a/services/sync/modules/browserid_identity.js
+++ b/services/sync/modules/browserid_identity.js
@@ -110,20 +110,20 @@ this.BrowserIDManager.prototype = {
     try {
       return Services.prefs.getBoolPref(PREF_SYNC_SHOW_CUSTOMIZATION);
     } catch (e) {
       return false;
     }
   },
 
   hashedUID() {
-    if (!this._token) {
-      throw new Error("hashedUID: Don't have token");
+    if (!this._hashedUID) {
+      throw new Error("hashedUID: Don't seem to have previously seen a token");
     }
-    return this._token.hashed_fxa_uid
+    return this._hashedUID;
   },
 
   deviceID() {
     return this._signedInUser && this._signedInUser.deviceId;
   },
 
   initialize: function() {
     for (let topic of OBSERVER_TOPICS) {
@@ -243,16 +243,21 @@ this.BrowserIDManager.prototype = {
             // Log out if the user canceled the dialog.
             return this._fxaService.signOut();
           }
         }
       }).then(() => {
         return this._fetchTokenForUser();
       }).then(token => {
         this._token = token;
+        if (token) {
+          // We may not have a token if the master-password is locked - but we
+          // still treat this as "success" so we don't prompt for re-authentication.
+          this._hashedUID = token.hashed_fxa_uid; // see _ensureValidToken for why we do this...
+        }
         this._shouldHaveSyncKeyBundle = true; // and we should actually have one...
         this.whenReadyToAuthenticate.resolve();
         this._log.info("Background fetch for key bundle done");
         Weave.Status.login = LOGIN_SUCCEEDED;
         if (isInitialSync) {
           this._log.info("Doing initial sync actions");
           Svc.Prefs.set("firstSync", "resetClient");
           Services.obs.notifyObservers(null, "weave:service:setup-complete", null);
@@ -408,16 +413,17 @@ this.BrowserIDManager.prototype = {
   },
 
   /**
    * Resets/Drops all credentials we hold for the current user.
    */
   resetCredentials: function() {
     this.resetSyncKey();
     this._token = null;
+    this._hashedUID = null;
     // The cluster URL comes from the token, so resetting it to empty will
     // force Sync to not accidentally use a value from an earlier token.
     Weave.Service.clusterURL = null;
   },
 
   /**
    * Resets/Drops the sync key we hold for the current user.
    */
@@ -687,16 +693,23 @@ this.BrowserIDManager.prototype = {
     const notifyStateChanged =
       () => Services.obs.notifyObservers(null, "weave:service:login:change", null);
     // reset this._token as a safety net to reduce the possibility of us
     // repeatedly attempting to use an invalid token if _fetchTokenForUser throws.
     this._token = null;
     return this._fetchTokenForUser().then(
       token => {
         this._token = token;
+        // we store the hashed UID from the token so that if we see a transient
+        // error fetching a new token we still know the "most recent" hashed
+        // UID for telemetry.
+        if (token) {
+          // We may not have a token if the master-password is locked.
+          this._hashedUID = token.hashed_fxa_uid;
+        }
         notifyStateChanged();
       },
       error => {
         notifyStateChanged();
         throw error
       }
     );
   },