Bug 1524688: Part 16 - Convert push components to static registration. r=baku
☠☠ backed out by 3b1b94e39795 ☠ ☠
authorKris Maglione <maglione.k@gmail.com>
Tue, 29 Jan 2019 20:50:16 -0800
changeset 458989 28670fdc418d
parent 458988 38e1e42a0fb0
child 458990 911689ef9f33
push id111909
push usermaglione.k@gmail.com
push dateThu, 14 Feb 2019 02:30:40 +0000
treeherdermozilla-inbound@81dc12cc9257 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1524688
milestone67.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 1524688: Part 16 - Convert push components to static registration. r=baku
browser/base/content/test/performance/browser_startup.js
browser/installer/package-manifest.in
dom/push/Push.js
dom/push/Push.jsm
dom/push/Push.manifest
dom/push/PushComponents.js
dom/push/PushComponents.jsm
dom/push/components.conf
dom/push/moz.build
mobile/android/installer/package-manifest.in
--- a/browser/base/content/test/performance/browser_startup.js
+++ b/browser/base/content/test/performance/browser_startup.js
@@ -21,29 +21,27 @@ const kDumpAllStacks = false;
 
 const startupPhases = {
   // For app-startup, we have a whitelist of acceptable JS files.
   // Anything loaded during app-startup must have a compelling reason
   // to run before we have even selected the user profile.
   // Consider loading your code after first paint instead,
   // eg. from BrowserGlue.jsm' _onFirstWindowLoaded method).
   "before profile selection": {whitelist: {
-    components: new Set([
-      // Bugs to fix: The following components shouldn't be initialized that early.
-      "PushComponents.js", // bug 1369436
-    ]),
     modules: new Set([
       "resource:///modules/BrowserGlue.jsm",
       "resource://gre/modules/AppConstants.jsm",
       "resource://gre/modules/ActorManagerParent.jsm",
       "resource://gre/modules/CustomElementsListener.jsm",
       "resource://gre/modules/ExtensionUtils.jsm",
       "resource://gre/modules/MainProcessSingleton.jsm",
       "resource://gre/modules/XPCOMUtils.jsm",
       "resource://gre/modules/Services.jsm",
+      // Bugs to fix: The following components shouldn't be initialized that early.
+      "resource://gre/modules/PushComponents.jsm", // bug 1369436
     ]),
   }},
 
   // For the following phases of startup we have only a black list for now
 
   // We are at this phase after creating the first browser window (ie. after final-ui-startup).
   "before opening first browser window": {blacklist: {
     modules: new Set([
--- a/browser/installer/package-manifest.in
+++ b/browser/installer/package-manifest.in
@@ -252,19 +252,17 @@
 @RESPATH@/components/XULStore.manifest
 @RESPATH@/components/recording-cmdline.js
 @RESPATH@/components/recording-cmdline.manifest
 @RESPATH@/components/htmlMenuBuilder.js
 @RESPATH@/components/htmlMenuBuilder.manifest
 
 @RESPATH@/components/NotificationStorage.js
 @RESPATH@/components/NotificationStorage.manifest
-@RESPATH@/components/Push.js
 @RESPATH@/components/Push.manifest
-@RESPATH@/components/PushComponents.js
 
 @RESPATH@/components/remotebrowserutils.manifest
 @RESPATH@/components/RemoteWebNavigation.js
 
 @RESPATH@/components/ProcessSelector.js
 @RESPATH@/components/ProcessSelector.manifest
 
 @RESPATH@/components/SlowScriptDebug.manifest
rename from dom/push/Push.js
rename to dom/push/Push.jsm
--- a/dom/push/Push.js
+++ b/dom/push/Push.jsm
@@ -280,9 +280,9 @@ PushSubscriptionCallback.prototype = {
           "Error retrieving push subscription.",
           "AbortError"
         );
     }
     this.reject(error);
   },
 };
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([Push]);
+var EXPORTED_SYMBOLS = ["Push"];
--- a/dom/push/Push.manifest
+++ b/dom/push/Push.manifest
@@ -1,11 +1,4 @@
-# DOM API
-component {cde1d019-fad8-4044-b141-65fb4fb7a245} Push.js
-contract @mozilla.org/push/PushManager;1 {cde1d019-fad8-4044-b141-65fb4fb7a245}
-
-# XPCOM components.
-component {daaa8d73-677e-4233-8acd-2c404bd01658} PushComponents.js
-contract @mozilla.org/push/Service;1 {daaa8d73-677e-4233-8acd-2c404bd01658}
 category app-startup PushServiceParent @mozilla.org/push/Service;1 process=main
 
 # For immediate loading of PushService instead of delayed loading.
 category android-push-service PushServiceParent @mozilla.org/push/Service;1 process=main
rename from dom/push/PushComponents.js
rename to dom/push/PushComponents.jsm
--- a/dom/push/PushComponents.js
+++ b/dom/push/PushComponents.jsm
@@ -108,28 +108,32 @@ PushServiceBase.prototype = {
   },
 };
 
 /**
  * The parent process implementation of `nsIPushService`. This version loads
  * `PushService.jsm` at startup and calls its methods directly. It also
  * receives and responds to requests from the content process.
  */
+let parentInstance;
 function PushServiceParent() {
+  if (parentInstance) {
+    return parentInstance;
+  }
+  parentInstance = this;
+
   PushServiceBase.call(this);
 }
 
 PushServiceParent.prototype = Object.create(PushServiceBase.prototype);
 
 XPCOMUtils.defineLazyServiceGetter(PushServiceParent.prototype, "_mm",
   "@mozilla.org/parentprocessmessagemanager;1", "nsISupports");
 
 Object.assign(PushServiceParent.prototype, {
-  _xpcom_factory: XPCOMUtils.generateSingletonFactory(PushServiceParent),
-
   _messages: [
     "Push:Register",
     "Push:Registration",
     "Push:Unregister",
     "Push:Clear",
     "Push:NotificationForOriginShown",
     "Push:NotificationForOriginClosed",
     "Push:ReportError",
@@ -301,37 +305,41 @@ Object.defineProperty(PushServiceParent.
   get() {
     return this._service || PushService;
   },
   set(impl) {
     this._service = impl;
   },
 });
 
+let contentInstance;
 /**
  * The content process implementation of `nsIPushService`. This version
  * uses the child message manager to forward calls to the parent process.
  * The parent Push service instance handles the request, and responds with a
  * message containing the result.
  */
 function PushServiceContent() {
+  if (contentInstance) {
+    return contentInstance;
+  }
+  contentInstance = this;
+
   PushServiceBase.apply(this, arguments);
   this._requests = new Map();
   this._requestId = 0;
 }
 
 PushServiceContent.prototype = Object.create(PushServiceBase.prototype);
 
 XPCOMUtils.defineLazyServiceGetter(PushServiceContent.prototype,
   "_mm", "@mozilla.org/childprocessmessagemanager;1",
   "nsISupports");
 
 Object.assign(PushServiceContent.prototype, {
-  _xpcom_factory: XPCOMUtils.generateSingletonFactory(PushServiceContent),
-
   _messages: [
     "PushService:Register:OK",
     "PushService:Register:KO",
     "PushService:Registration:OK",
     "PushService:Registration:KO",
     "PushService:Unregister:OK",
     "PushService:Unregister:KO",
     "PushService:Clear:OK",
@@ -543,13 +551,13 @@ PushSubscription.prototype = {
     let rawKey = new Uint8Array(key);
     if (outKeyLen) {
       outKeyLen.value = rawKey.length;
     }
     return rawKey;
   },
 };
 
-this.NSGetFactory = XPCOMUtils.generateNSGetFactory([
-  // Export the correct implementation depending on whether we're running in
-  // the parent or content process.
-  isParent ? PushServiceParent : PushServiceContent,
-]);
+// Export the correct implementation depending on whether we're running in
+// the parent or content process.
+let Service = isParent ? PushServiceParent : PushServiceContent;
+
+var EXPORTED_SYMBOLS = ["Service"];
new file mode 100644
--- /dev/null
+++ b/dom/push/components.conf
@@ -0,0 +1,20 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+Classes = [
+    {
+        'cid': '{cde1d019-fad8-4044-b141-65fb4fb7a245}',
+        'contract_ids': ['@mozilla.org/push/PushManager;1'],
+        'jsm': 'resource://gre/modules/Push.jsm',
+        'constructor': 'Push',
+    },
+    {
+        'cid': '{daaa8d73-677e-4233-8acd-2c404bd01658}',
+        'contract_ids': ['@mozilla.org/push/Service;1'],
+        'jsm': 'resource://gre/modules/PushComponents.jsm',
+        'constructor': 'Service',
+    },
+]
--- a/dom/push/moz.build
+++ b/dom/push/moz.build
@@ -2,23 +2,23 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 
 with Files("**"):
     BUG_COMPONENT = ("Core", "DOM: Push Notifications")
 
 EXTRA_COMPONENTS += [
-    'Push.js',
     'Push.manifest',
-    'PushComponents.js',
 ]
 
 EXTRA_JS_MODULES += [
+    'Push.jsm',
     'PushBroadcastService.jsm',
+    'PushComponents.jsm',
     'PushCrypto.jsm',
     'PushDB.jsm',
     'PushRecord.jsm',
     'PushService.jsm',
 ]
 
 if CONFIG['MOZ_BUILD_APP'] != 'mobile/android':
     # Everything but Fennec.
@@ -27,16 +27,20 @@ if CONFIG['MOZ_BUILD_APP'] != 'mobile/an
         'PushServiceWebSocket.jsm',
     ]
 else:
     # Fennec only.
     EXTRA_JS_MODULES += [
         'PushServiceAndroidGCM.jsm',
     ]
 
+XPCOM_MANIFESTS += [
+    'components.conf',
+]
+
 MOCHITEST_MANIFESTS += [
     'test/mochitest.ini',
 ]
 
 XPCSHELL_TESTS_MANIFESTS += [
     'test/xpcshell/xpcshell.ini',
 ]
 
--- a/mobile/android/installer/package-manifest.in
+++ b/mobile/android/installer/package-manifest.in
@@ -101,19 +101,17 @@
 @BINPATH@/components/components.manifest
 
 ; JavaScript components
 @BINPATH@/components/ConsoleAPI.manifest
 @BINPATH@/components/ConsoleAPIStorage.js
 @BINPATH@/components/NotificationStorage.js
 @BINPATH@/components/NotificationStorage.manifest
 #ifdef MOZ_ANDROID_GCM
-@BINPATH@/components/Push.js
 @BINPATH@/components/Push.manifest
-@BINPATH@/components/PushComponents.js
 #endif
 @BINPATH@/components/BrowserElementParent.manifest
 @BINPATH@/components/BrowserElementParent.js
 @BINPATH@/components/UAOverridesBootstrapper.js
 @BINPATH@/components/UAOverridesBootstrapper.manifest
 @BINPATH@/components/WellKnownOpportunisticUtils.js
 @BINPATH@/components/WellKnownOpportunisticUtils.manifest
 @BINPATH@/components/mozProtocolHandler.js