Bug 956138 - Have BrowserUITelemetry wait for sessionstore-windows-restored before gathering measurements. r=jaws, a=bajaj
authorMike Conley <mconley@mozilla.com>
Fri, 03 Jan 2014 12:31:44 -0500
changeset 167820 fd45cf4498d2231f123cb499c91483047f0b85a2
parent 167819 7d87682913a96f88bdbc069bf6b77043bf8bcba7
child 167821 a4ceb800b3dc191b34ae09f17d3fd6bb3a3aefbc
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjaws, bajaj
bugs956138
milestone27.0
Bug 956138 - Have BrowserUITelemetry wait for sessionstore-windows-restored before gathering measurements. r=jaws, a=bajaj
browser/modules/BrowserUITelemetry.jsm
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -231,22 +231,28 @@ const OTHER_MOUSEUP_MONITORED_ITEMS = [
 // exits customization mode, we can determine how long the session
 // lasted.
 const WINDOW_DURATION_MAP = new WeakMap();
 
 this.BrowserUITelemetry = {
   init: function() {
     UITelemetry.addSimpleMeasureFunction("toolbars",
                                          this.getToolbarMeasures.bind(this));
+    Services.obs.addObserver(this, "sessionstore-windows-restored", false);
     Services.obs.addObserver(this, "browser-delayed-startup-finished", false);
   },
 
   observe: function(aSubject, aTopic, aData) {
-    if (aTopic == "browser-delayed-startup-finished") {
-      this._registerWindow(aSubject);
+    switch(aTopic) {
+      case "sessionstore-windows-restored":
+        this._gatherFirstWindowMeasurements();
+        break;
+      case "browser-delayed-startup-finished":
+        this._registerWindow(aSubject);
+        break;
     }
   },
 
   /**
    * For the _countableEvents object, constructs a chain of
    * Javascript Objects with the keys in aKeys, with the final
    * key getting the value in aEndWith. If the final key already
    * exists in the final object, its value is not set. In either
@@ -306,26 +312,33 @@ this.BrowserUITelemetry = {
     if (buttonKey) {
       let countObject =
         this._ensureObjectChain([aCategory, aAction, buttonKey], 0);
       countObject[buttonKey]++;
     }
   },
 
   _firstWindowMeasurements: null,
+  _gatherFirstWindowMeasurements: function() {
+    // We'll gather measurements as soon as the session has restored.
+    // We do this here instead of waiting for UITelemetry to ask for
+    // our measurements because at that point all browser windows have
+    // probably been closed, since the vast majority of saved-session
+    // pings are gathered during shutdown.
+    let win = RecentWindow.getMostRecentBrowserWindow({
+      private: false,
+      allowPopups: false,
+    });
+
+    // If there are no such windows, we're out of luck. :(
+    this._firstWindowMeasurements = win ? this._getWindowMeasurements(win)
+                                        : {};
+  },
+
   _registerWindow: function(aWindow) {
-    // We'll gather measurements on the first non-popup window that opens
-    // after it has painted. We do this here instead of waiting for
-    // UITelemetry to ask for our measurements because at that point
-    // all browser windows have probably been closed, since the vast
-    // majority of saved-session pings are gathered during shutdown.
-    if (!this._firstWindowMeasurements && aWindow.toolbar.visible) {
-      this._firstWindowMeasurements = this._getWindowMeasurements(aWindow);
-    }
-
     aWindow.addEventListener("unload", this);
     let document = aWindow.document;
 
     let toolbars = document.querySelectorAll("toolbar[customizable=true]");
     for (let toolbar of toolbars) {
       toolbar.addEventListener("mouseup", this);
     }