Bug 1427850 - Check that sync is ready directly instead of reading the sync username to determine it r?markh draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Wed, 03 Jan 2018 15:22:43 -0500
changeset 715361 48eb42b61c8a50debab3ad27813fc833fbd52bd7
parent 715271 ac93fdadf1022211eec62258ad22b42cb37a6d14
child 744787 34ef1aa6eccc159655eb47c569826b7a1f77786a
push id94154
push userbmo:tchiovoloni@mozilla.com
push dateWed, 03 Jan 2018 20:43:10 +0000
reviewersmarkh
bugs1427850
milestone59.0a1
Bug 1427850 - Check that sync is ready directly instead of reading the sync username to determine it r?markh MozReview-Commit-ID: LnQ6Em0GCvM
services/sync/Weave.js
toolkit/components/places/PlacesRemoteTabsAutocompleteProvider.jsm
--- a/services/sync/Weave.js
+++ b/services/sync/Weave.js
@@ -9,18 +9,17 @@ const Cu = Components.utils;
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "FileUtils",
                                   "resource://gre/modules/FileUtils.jsm");
 XPCOMUtils.defineLazyGetter(this, "Utils", () => {
   return Cu.import("resource://services-sync/util.js", {}).Utils;
 });
 
-const SYNC_PREFS_BRANCH = "services.sync.";
-
+XPCOMUtils.defineLazyPreferenceGetter(this, "syncUsername", "services.sync.username");
 
 /**
  * Sync's XPCOM service.
  *
  * It is named "Weave" for historical reasons.
  *
  * It's worth noting how Sync is lazily loaded. We register a timer that
  * loads Sync a few seconds after app startup. This is so Sync does not
@@ -123,18 +122,17 @@ WeaveService.prototype = {
    * Whether Sync appears to be enabled.
    *
    * This returns true if we have an associated FxA account
    *
    * It does *not* perform a robust check to see if the client is working.
    * For that, you'll want to check Weave.Status.checkSetup().
    */
   get enabled() {
-    let prefs = Services.prefs.getBranch(SYNC_PREFS_BRANCH);
-    return prefs.prefHasUserValue("username");
+    return !!syncUsername;
   }
 };
 
 function AboutWeaveLog() {}
 AboutWeaveLog.prototype = {
   classID: Components.ID("{d28f8a0b-95da-48f4-b712-caf37097be41}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule,
--- a/toolkit/components/places/PlacesRemoteTabsAutocompleteProvider.jsm
+++ b/toolkit/components/places/PlacesRemoteTabsAutocompleteProvider.jsm
@@ -111,18 +111,17 @@ Services.obs.addObserver(observe, "weave
 Services.prefs.addObserver(PREF_SHOW_REMOTE_ICONS, observe);
 observe(null, "nsPref:changed", PREF_SHOW_REMOTE_ICONS);
 
 // This public object is a static singleton.
 this.PlacesRemoteTabsAutocompleteProvider = {
   // a promise that resolves with an array of matching remote tabs.
   getMatches(searchString) {
     // If Sync isn't configured we bail early.
-    if (Weave === null ||
-        !Services.prefs.prefHasUserValue("services.sync.username")) {
+    if (!weaveXPCService.ready || !weaveXPCService.enabled) {
       return Promise.resolve([]);
     }
 
     let re = new RegExp(escapeRegExp(searchString), "i");
     let matches = [];
     let { tabs, clients } = ensureItems();
     for (let [url, { clientId, tab }] of tabs) {
       let title = tab.title;