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
--- 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,19 @@ 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) {
+ 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 +411,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 +691,22 @@ 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) {
+ this._hashedUID = token.hashed_fxa_uid;
+ }
notifyStateChanged();
},
error => {
notifyStateChanged();
throw error
}
);
},