Bug 1458375 - Make TalosPowersContent.goQuitApplication wait for browser-idle-startup-tasks-finished to fire before quitting. r=rwood
authorMike Conley <mconley@mozilla.com>
Tue, 29 May 2018 12:54:45 -0400
changeset 479094 7b152fdfbb4ab2b5b0f1bfbfa7a70a362fee9dd7
parent 479093 06ebd23a33bfe2760f9160c9979b16e3c0f31e68
child 479095 5a342be8a03e4a667168c0b823b4b089c93fcc4b
push id1757
push userffxbld-merge
push dateFri, 24 Aug 2018 17:02:43 +0000
treeherdermozilla-release@736023aebdb1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrwood
bugs1458375
milestone62.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 1458375 - Make TalosPowersContent.goQuitApplication wait for browser-idle-startup-tasks-finished to fire before quitting. r=rwood browser-idle-startup-tasks-finished will kick off some caching that can influence future runs in the same profile. We want to make sure that we properly create that cache when running Talos. MozReview-Commit-ID: 9Ydt1ur3tsj
testing/talos/talos/talos-powers/bootstrap.js
--- a/testing/talos/talos/talos-powers/bootstrap.js
+++ b/testing/talos/talos/talos-powers/bootstrap.js
@@ -2,16 +2,18 @@
  * 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/. */
 
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 ChromeUtils.defineModuleGetter(this, "Services",
   "resource://gre/modules/Services.jsm");
 ChromeUtils.defineModuleGetter(this, "OS",
   "resource://gre/modules/osfile.jsm");
+ChromeUtils.defineModuleGetter(this, "BrowserWindowTracker",
+  "resource:///modules/BrowserWindowTracker.jsm");
 
 Cu.importGlobalProperties(["TextEncoder"]);
 
 const Cm = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
 
 const FRAME_SCRIPT = "chrome://talos-powers/content/talos-powers-content.js";
 
 function TalosPowersService() {
@@ -207,27 +209,45 @@ TalosPowersService.prototype = {
 
       case "Profiler:Marker": {
         this.profilerMarker(data.marker);
         mm.sendAsyncMessage(ACK_NAME, { name });
       }
     }
   },
 
-  forceQuit(messageData) {
+  async forceQuit(messageData) {
     if (messageData && messageData.waitForSafeBrowsing) {
       let SafeBrowsing = ChromeUtils.import("resource://gre/modules/SafeBrowsing.jsm", {}).SafeBrowsing;
 
-      let whenDone = () => {
-        this.forceQuit();
-      };
-      SafeBrowsing.addMozEntriesFinishedPromise.then(whenDone, whenDone);
       // Speed things up in case nobody else called this:
       SafeBrowsing.init();
-      return;
+
+      try {
+        await SafeBrowsing.addMozEntriesFinishedPromise;
+      } catch (e) {
+        // We don't care if things go wrong here - let's just shut down.
+      }
+    }
+
+    // Check to see if the top-most browser window still needs to fire its
+    // idle tasks notification. If so, we'll wait for it before shutting
+    // down, since some caching that can influence future runs in this profile
+    // keys off of that notification.
+    let topWin = BrowserWindowTracker.getTopWindow();
+    if (topWin &&
+        topWin.gBrowserInit &&
+        !topWin.gBrowserInit.idleTasksFinished) {
+      await new Promise(resolve => {
+        let obs = (subject, topic, data) => {
+          Services.obs.removeObserver(obs, "browser-idle-startup-tasks-finished");
+          resolve();
+        };
+        Services.obs.addObserver(obs, "browser-idle-startup-tasks-finished");
+      });
     }
 
     let enumerator = Services.wm.getEnumerator(null);
     while (enumerator.hasMoreElements()) {
       let domWindow = enumerator.getNext();
       domWindow.close();
     }