Bug 1576507 - add new FirstStartup service and --first-startup post-install flag. r=mconley
authorRobert Helmer <rhelmer@mozilla.com>
Sat, 31 Aug 2019 16:14:20 +0000
changeset 551549 c547b758be35c62a4a2311443afaa7ac8dbe892e
parent 551548 83dba42b1853525e59efe05f361bd244937580d3
child 551550 c0422b67e5d01c87ea78ed36985dfb01c2c56a24
push id11865
push userbtara@mozilla.com
push dateMon, 02 Sep 2019 08:54:37 +0000
treeherdermozilla-beta@37f59c4671b3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmconley
bugs1576507
milestone70.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 1576507 - add new FirstStartup service and --first-startup post-install flag. r=mconley FirstStartup provides an optional mechanism to run synchronous services before the UI appears. This is intended to be called as a post-install action from an installer, such as the Windows Stub Installer, to allow for downloading critical data and performance tuning before the first run of a new Firefox install. Differential Revision: https://phabricator.services.mozilla.com/D43364
browser/components/BrowserContentHandler.jsm
toolkit/modules/FirstStartup.jsm
toolkit/modules/moz.build
--- a/browser/components/BrowserContentHandler.jsm
+++ b/browser/components/BrowserContentHandler.jsm
@@ -14,16 +14,17 @@ const { Services } = ChromeUtils.import(
 const { AppConstants } = ChromeUtils.import(
   "resource://gre/modules/AppConstants.jsm"
 );
 
 XPCOMUtils.defineLazyModuleGetters(this, {
   BrowserWindowTracker: "resource:///modules/BrowserWindowTracker.jsm",
   HeadlessShell: "resource:///modules/HeadlessShell.jsm",
   HomePage: "resource:///modules/HomePage.jsm",
+  FirstStartup: "resource://gre/modules/FirstStartup.jsm",
   LaterRun: "resource:///modules/LaterRun.jsm",
   PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
   SessionStartup: "resource:///modules/sessionstore/SessionStartup.jsm",
   ShellService: "resource:///modules/ShellService.jsm",
   UpdatePing: "resource://gre/modules/UpdatePing.jsm",
   RemotePages:
     "resource://gre/modules/remotepagemanager/RemotePageManagerParent.jsm",
 });
@@ -553,16 +554,20 @@ nsBrowserContentHandler.prototype = {
           ).usePrivateBrowsing = true;
         }
       }
     }
     if (cmdLine.handleFlag("setDefaultBrowser", false)) {
       ShellService.setDefaultBrowser(true, true);
     }
 
+    if (cmdLine.handleFlag("first-startup", false)) {
+      FirstStartup.init();
+    }
+
     var fileParam = cmdLine.handleFlagWithParam("file", false);
     if (fileParam) {
       var file = cmdLine.resolveFile(fileParam);
       var fileURI = Services.io.newFileURI(file);
       openBrowserWindow(cmdLine, gSystemPrincipal, fileURI.spec);
       cmdLine.preventDefault = true;
     }
 
@@ -594,16 +599,18 @@ nsBrowserContentHandler.prototype = {
     }
     info +=
       "  --screenshot [<path>] Save screenshot to <path> or in working directory.\n";
     info +=
       "  --window-size width[,height] Width and optionally height of screenshot.\n";
     info +=
       "  --search <term>    Search <term> with your default search engine.\n";
     info += "  --setDefaultBrowser Set this app as the default browser.\n";
+    info +=
+      "  --first-startup    Run post-install actions before opening a new window.\n";
     return info;
   },
 
   /* nsIBrowserHandler */
 
   get defaultArgs() {
     return this.getArgs();
   },
new file mode 100644
--- /dev/null
+++ b/toolkit/modules/FirstStartup.jsm
@@ -0,0 +1,36 @@
+/* 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/. */
+
+var EXPORTED_SYMBOLS = ["FirstStartup"];
+
+/**
+ * Service for blocking application startup, to be used on the first install. The intended
+ * use case is for `FirstStartup` to be invoked when the application is called by an installer,
+ * such as the Windows Stub Installer, to allow the application to do some first-install tasks
+ * such as performance tuning and downloading critical data.
+ *
+ * In this scenario, the installer does not exit until the first application window appears,
+ * which gives the user experience of the application starting up quickly on first install.
+ */
+var FirstStartup = {
+  NOT_STARTED: 0,
+  IN_PROGRESS: 1,
+  TIMED_OUT: 2,
+  SUCCESS: 3,
+  UNSUPPORTED: 4,
+
+  _state: this.NOT_STARTED,
+  /**
+   * Initialize and run first-startup services. This will always run synchronously
+   * and spin the event loop until either all required services have
+   * completed, or until a timeout is reached.
+   *
+   * In the latter case, services are expected to run post-UI instead as usual.
+   */
+  init() {},
+
+  get state() {
+    return this._state;
+  },
+};
--- a/toolkit/modules/moz.build
+++ b/toolkit/modules/moz.build
@@ -183,16 +183,17 @@ EXTRA_JS_MODULES += [
     'E10SUtils.jsm',
     'EventEmitter.jsm',
     'FileUtils.jsm',
     'FindBarContent.jsm',
     'Finder.jsm',
     'FinderHighlighter.jsm',
     'FinderIterator.jsm',
     'FinderParent.jsm',
+    'FirstStartup.jsm',
     'FormLikeFactory.jsm',
     'Geometry.jsm',
     'GMPExtractorWorker.js',
     'GMPInstallManager.jsm',
     'GMPUtils.jsm',
     'HiddenFrame.jsm',
     'Http.jsm',
     'IgnoreLists.jsm',