Bug 1317589 - store the most recent hashed UID so we can still report it on transient errors renewing tokens. r?tcsc draft
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 15 Nov 2016 16:03:41 +1100
changeset 439460 d07e727d5e7d3d7a06d34d4f9a408835d126576e
parent 439386 7bb9038dbee47fe9275de09c3cb9b9ff08d504f2
child 537166 46aa4f0d12dc3a7219acba55c6724400919b352e
push id36003
push userbmo:markh@mozilla.com
push dateWed, 16 Nov 2016 01:50:21 +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
       }
     );
   },