Bug 1034836 - Lazily load some modules in Startup.jsm. r=myk
authorMarco Castelluccio <mar.castelluccio@studenti.unina.it>
Sat, 12 Jul 2014 02:15:35 +0200
changeset 215634 44776990ebd01fada385c16d9944337828032f54
parent 215633 89076de4e3c3e10ec5f22cdc85a9f737b65888f8
child 215635 4625ba9d9a0915bc0bbb84c8f588fb1163eb078e
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmyk
bugs1034836
milestone33.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 1034836 - Lazily load some modules in Startup.jsm. r=myk
webapprt/Startup.jsm
--- a/webapprt/Startup.jsm
+++ b/webapprt/Startup.jsm
@@ -7,27 +7,34 @@
  * stuff here that you want to happen once on startup before the webapp is
  * loaded.  */
 
 this.EXPORTED_SYMBOLS = ["startup"];
 
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
+/* We load here modules that are needed to perform the application startup.
+ * We lazily load modules that aren't needed on every startup.
+ * We load modules that aren't used here but that need to perform some
+ * initialization steps later in the startup function. */
+
+Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
-Cu.import("resource://gre/modules/AppsUtils.jsm");
-Cu.import("resource://gre/modules/PermissionsInstaller.jsm");
-Cu.import('resource://gre/modules/Payment.jsm');
-Cu.import('resource://gre/modules/AlarmService.jsm');
 Cu.import("resource://gre/modules/Task.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/osfile.jsm");
 
 Cu.import("resource://webapprt/modules/WebappRT.jsm");
-Cu.import("resource://webapprt/modules/WebRTCHandler.jsm");
+
+// Lazily load these modules because we don't need them at every
+// startup, but only during first run or runtime update.
+
+XPCOMUtils.defineLazyModuleGetter(this, "PermissionsInstaller",
+  "resource://gre/modules/PermissionsInstaller.jsm");
 
 const PROFILE_DIR = OS.Constants.Path.profileDir;
 
 function isFirstRunOrUpdate() {
   let savedBuildID = null;
   try {
     savedBuildID = Services.prefs.getCharPref("webapprt.buildID");
   } catch (e) {}
@@ -130,16 +137,22 @@ this.startup = function(window) {
 
     Services.io.getProtocolHandler("resource")
                .QueryInterface(Ci.nsIResProtocolHandler)
                .setSubstitution("webappbranding", aliasURI);
 
     // Wait for XUL window loading
     yield deferredWindowLoad.promise;
 
+    // Load these modules here because they aren't needed right at startup,
+    // but they need to be loaded to perform some initialization steps.
+    Cu.import("resource://gre/modules/Payment.jsm");
+    Cu.import("resource://gre/modules/AlarmService.jsm");
+    Cu.import("resource://webapprt/modules/WebRTCHandler.jsm");
+
     // Get the <browser> element in the webapp.xul window.
     let appBrowser = window.document.getElementById("content");
 
     // Set the principal to the correct appID and launch the application.
     appBrowser.docShell.setIsApp(WebappRT.appID);
     appBrowser.setAttribute("src", WebappRT.launchURI);
 
     if (appData.manifest.fullscreen) {