Bug 1364571 - Delay Weave startup. r=kitcambridge
authorEdouard Oger <eoger@fastmail.com>
Fri, 12 May 2017 17:01:25 -0400
changeset 358416 135031bdb7d0907ad0ff867c144ab720eb90492f
parent 358415 de31a15ecd05dc7aa19e51727fbe1043b969141b
child 358417 d6572599cafac7f62d966dd83692fb29b5b2d7ce
push id42697
push usereoger@mozilla.com
push dateMon, 15 May 2017 15:34:37 +0000
treeherderautoland@135031bdb7d0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskitcambridge
bugs1364571
milestone55.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 1364571 - Delay Weave startup. r=kitcambridge MozReview-Commit-ID: 4bm1LXLD7lV
browser/components/nsBrowserGlue.js
services/sync/SyncComponents.manifest
services/sync/Weave.js
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -11,16 +11,19 @@ const XULNS = "http://www.mozilla.org/ke
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/AppConstants.jsm");
 Cu.import("resource://gre/modules/AsyncPrefs.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "WindowsUIUtils", "@mozilla.org/windows-ui-utils;1", "nsIWindowsUIUtils");
 XPCOMUtils.defineLazyServiceGetter(this, "AlertsService", "@mozilla.org/alerts-service;1", "nsIAlertsService");
+XPCOMUtils.defineLazyGetter(this, "WeaveService", () =>
+  Cc["@mozilla.org/weave/service;1"].getService().wrappedJSObject
+);
 
 // lazy module getters
 
 /* global AboutHome:false, AboutNewTab:false, AddonManager:false,
           AsyncShutdown:false, AutoCompletePopup:false, BookmarkHTMLUtils:false,
           BookmarkJSONUtils:false, BrowserUITelemetry:false, BrowserUsageTelemetry:false,
           ContentClick:false, ContentPrefServiceParent:false, ContentSearch:false,
           DateTimePickerHelper:false, DirectoryLinksProvider:false,
@@ -968,16 +971,20 @@ BrowserGlue.prototype = {
         }
       }
     }
 
     this._checkForOldBuildUpdates();
 
     AutoCompletePopup.init();
     DateTimePickerHelper.init();
+    // Check if Sync is configured
+    if (Services.prefs.prefHasUserValue("services.sync.username")) {
+      WeaveService.init();
+    }
 
     this._firstWindowTelemetry(aWindow);
     this._firstWindowLoaded();
 
     this._mediaTelemetryIdleObserver = {
       browserGlue: this,
       observe(aSubject, aTopic, aData) {
         if (aTopic != "idle") {
--- a/services/sync/SyncComponents.manifest
+++ b/services/sync/SyncComponents.manifest
@@ -1,21 +1,9 @@
-# WeaveService has to restrict its registration for the app-startup category
-# to the specific list of apps that use it so it doesn't get loaded in xpcshell.
-# Thus we restrict it to these apps:
-#
-#   b2g:            {3c2e2abc-06d4-11e1-ac3b-374f68613e61}
-#   browser:        {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
-#   mobile/android: {aa3c5121-dab2-40e2-81ca-7ea25febc110}
-#   mobile/xul:     {a23983c0-fd0e-11dc-95ff-0800200c9a66}
-#   suite (comm):   {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
-#   graphene:       {d1bfe7d9-c01e-4237-998b-7b5f960a4314}
-
 # Weave.js
 component {74b89fb0-f200-4ae8-a3ec-dd164117f6de} Weave.js
 contract @mozilla.org/weave/service;1 {74b89fb0-f200-4ae8-a3ec-dd164117f6de}
-category app-startup WeaveService service,@mozilla.org/weave/service;1 application={3c2e2abc-06d4-11e1-ac3b-374f68613e61} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} application={aa3c5121-dab2-40e2-81ca-7ea25febc110} application={a23983c0-fd0e-11dc-95ff-0800200c9a66} application={92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a} application={99bceaaa-e3c6-48c1-b981-ef9b46b67d60} application={d1bfe7d9-c01e-4237-998b-7b5f960a4314}
 component {d28f8a0b-95da-48f4-b712-caf37097be41} Weave.js
 contract @mozilla.org/network/protocol/about;1?what=sync-log {d28f8a0b-95da-48f4-b712-caf37097be41}
 
 # Register resource aliases
 # (Note, for tests these are also set up in addResourceAlias)
 resource services-sync resource://gre/modules/services-sync/
--- a/services/sync/Weave.js
+++ b/services/sync/Weave.js
@@ -89,63 +89,53 @@ WeaveService.prototype = {
         Services.obs.removeObserver(onReady, "weave:service:ready");
         resolve();
       }, "weave:service:ready");
     });
     this.ensureLoaded();
     return onReadyPromise;
   },
 
+  init() {
+    // Force Weave service to load if it hasn't triggered from overlays
+    this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+    this.timer.initWithCallback({
+      notify: () => {
+        let isConfigured = false;
+        // We only load more if it looks like Sync is configured.
+        if (this.enabled) {
+          // We have an associated FxAccount. So, do a more thorough check.
+          // This will import a number of modules and thus increase memory
+          // accordingly. We could potentially copy code performed by
+          // this check into this file if our above code is yielding too
+          // many false positives.
+          Components.utils.import("resource://services-sync/main.js");
+          isConfigured = Weave.Status.checkSetup() != Weave.CLIENT_NOT_CONFIGURED;
+        }
+        let getHistogramById = Services.telemetry.getHistogramById;
+        getHistogramById("WEAVE_CONFIGURED").add(isConfigured);
+        if (isConfigured) {
+          getHistogramById("WEAVE_CONFIGURED_MASTER_PASSWORD").add(Utils.mpEnabled());
+          this.ensureLoaded();
+        }
+      }
+    }, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
+  },
+
   /**
    * 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");
-  },
-
-  observe(subject, topic, data) {
-    switch (topic) {
-    case "app-startup":
-      let os = Cc["@mozilla.org/observer-service;1"].
-               getService(Ci.nsIObserverService);
-      os.addObserver(this, "final-ui-startup", true);
-      break;
-
-    case "final-ui-startup":
-      // Force Weave service to load if it hasn't triggered from overlays
-      this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-      this.timer.initWithCallback({
-        notify: () => {
-          let isConfigured = false;
-          // We only load more if it looks like Sync is configured.
-          if (this.enabled) {
-            // We have an associated FxAccount. So, do a more thorough check.
-            // This will import a number of modules and thus increase memory
-            // accordingly. We could potentially copy code performed by
-            // this check into this file if our above code is yielding too
-            // many false positives.
-            Components.utils.import("resource://services-sync/main.js");
-            isConfigured = Weave.Status.checkSetup() != Weave.CLIENT_NOT_CONFIGURED;
-          }
-          let getHistogramById = Services.telemetry.getHistogramById;
-          getHistogramById("WEAVE_CONFIGURED").add(isConfigured);
-          if (isConfigured) {
-            getHistogramById("WEAVE_CONFIGURED_MASTER_PASSWORD").add(Utils.mpEnabled());
-            this.ensureLoaded();
-          }
-        }
-      }, 10000, Ci.nsITimer.TYPE_ONE_SHOT);
-      break;
-    }
   }
 };
 
 function AboutWeaveLog() {}
 AboutWeaveLog.prototype = {
   classID: Components.ID("{d28f8a0b-95da-48f4-b712-caf37097be41}"),
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIAboutModule,