Bug 1390478 - never block the UI waiting for the FxA profile. r=eoger
☠☠ backed out by d063918c34f8 ☠ ☠
authorMark Hammond <mhammond@skippinet.com.au>
Fri, 08 Dec 2017 11:27:40 +1100
changeset 448604 0e26ab46cbb7a6cff4fc129bf11c3d3cd86b6ab5
parent 448603 ac65e767c4f870bf8dbfe9c09fcbe5d13e76f2a8
child 448605 87b1dff0ae24b786976cc9e8ded643729575da01
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseoger
bugs1390478
milestone59.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 1390478 - never block the UI waiting for the FxA profile. r=eoger MozReview-Commit-ID: 4MNqo9AUuOz
services/fxaccounts/FxAccounts.jsm
services/fxaccounts/FxAccountsProfile.jsm
--- a/services/fxaccounts/FxAccounts.jsm
+++ b/services/fxaccounts/FxAccounts.jsm
@@ -1556,17 +1556,21 @@ FxAccountsInternal.prototype = {
     let reason = new Error(aError);
     if (aDetails) {
       reason.details = aDetails;
     }
     return reason;
   },
 
   /**
-   * Get the user's account and profile data
+   * Get the user's account and profile data if it is locally cached. If
+   * not cached it will return null, but cause the profile data to be fetched
+   * in the background, after which a ON_PROFILE_CHANGE_NOTIFICATION
+   * observer notification will be sent, at which time this can be called
+   * again to obtain the most recent profile info.
    *
    * @param options
    *        {
    *          contentUrl: (string) Used by the FxAccountsWebChannel.
    *            Defaults to pref identity.fxaccounts.settings.uri
    *          profileServerUrl: (string) Used by the FxAccountsWebChannel.
    *            Defaults to pref identity.fxaccounts.remote.profile.uri
    *        }
--- a/services/fxaccounts/FxAccountsProfile.jsm
+++ b/services/fxaccounts/FxAccountsProfile.jsm
@@ -109,23 +109,28 @@ this.FxAccountsProfile.prototype = {
 
   _fetchAndCacheProfile() {
     if (!this._currentFetchPromise) {
       this._currentFetchPromise = this._fetchAndCacheProfileInternal();
     }
     return this._currentFetchPromise;
   },
 
-  // Returns cached data right away if available, then fetches the latest profile
-  // data in the background. After data is fetched a notification will be sent
-  // out if the profile has changed.
+  // Returns cached data right away if available, otherwise returns null - if
+  // it returns null, or if the profile is possibly stale, it attempts to
+  // fetch the latest profile data in the background. After data is fetched a
+  // notification will be sent out if the profile has changed.
   async getProfile() {
     const profileCache = await this.fxa.getProfileCache();
     if (!profileCache) {
-      return this._fetchAndCacheProfile();
+      // fetch and cache it in the background.
+      this._fetchAndCacheProfile().catch(err => {
+        log.error("Background refresh of initial profile failed", err);
+      });
+      return null;
     }
     if (Date.now() > this._cachedAt + this.PROFILE_FRESHNESS_THRESHOLD) {
       // Note that _fetchAndCacheProfile isn't returned, so continues
       // in the background.
       this._fetchAndCacheProfile().catch(err => {
         log.error("Background refresh of profile failed", err);
       });
     } else {