Bug 952180 - BrowserUITelemetry is mostly returning empty toolbar data. r=jaws, a=lsblakk.
authorMike Conley <mconley@mozilla.com>
Fri, 20 Dec 2013 11:38:49 -0500
changeset 167791 fa4b83484b568fd9719ea92d189f9bbbd5fd6300
parent 167790 b45852a5f6dfcf8b8053788ee6c798ac18326833
child 167792 2d1a46b92459a2fc0ea56d87a72f9590feefb377
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, lsblakk
bugs952180
milestone27.0
Bug 952180 - BrowserUITelemetry is mostly returning empty toolbar data. r=jaws, a=lsblakk.
browser/modules/BrowserUITelemetry.jsm
--- a/browser/modules/BrowserUITelemetry.jsm
+++ b/browser/modules/BrowserUITelemetry.jsm
@@ -305,17 +305,27 @@ this.BrowserUITelemetry = {
     let buttonKey = BUTTONS[aButton];
     if (buttonKey) {
       let countObject =
         this._ensureObjectChain([aCategory, aAction, buttonKey], 0);
       countObject[buttonKey]++;
     }
   },
 
+  _firstWindowMeasurements: null,
   _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);
     }
 
@@ -468,30 +478,18 @@ this.BrowserUITelemetry = {
     let durationMap = WINDOW_DURATION_MAP.get(aWindow);
     if ("customization" in durationMap) {
       let duration = aWindow.performance.now() - durationMap.customization;
       this._durations.customization.push(duration);
       delete durationMap.customization;
     }
   },
 
-  getToolbarMeasures: function() {
-    // Grab the most recent non-popup, non-private browser window for us to
-    // analyze the toolbars in...
-    let win = RecentWindow.getMostRecentBrowserWindow({
-      private: false,
-      allowPopups: false
-    });
-
-    // If there are no such windows, we're out of luck. :(
-    if (!win) {
-      return {};
-    }
-
-    let document = win.document;
+  _getWindowMeasurements: function(aWindow) {
+    let document = aWindow.document;
     let result = {};
 
     // Determine if the add-on bar is currently visible
     let addonBar = document.getElementById("addon-bar");
     result.addonBarEnabled = addonBar && !addonBar.collapsed;
 
     // Determine if the Bookmarks bar is currently visible
     let bookmarksBar = document.getElementById("PersonalToolbar");
@@ -547,51 +545,55 @@ this.BrowserUITelemetry = {
       // Finally, let's see if this is a custom toolbar.
       if (toolbar.hasAttribute("customindex")) {
         customToolbars++;
       }
     }
 
     // Now go through the items in the palette to see what default
     // items are in there.
-    let paletteChildren = win.gNavToolbox.palette.childNodes;
+    let paletteChildren = aWindow.gNavToolbox.palette.childNodes;
     let defaultRemoved = [node.id for (node of paletteChildren)
                           if (DEFAULT_ITEMS.indexOf(node.id) != -1)];
 
     let addonToolbars = toolbars.length - DEFAULT_TOOLBARS.length - customToolbars;
 
     result.defaultKept = defaultKept;
     result.defaultMoved = defaultMoved;
     result.nondefaultAdded = nondefaultAdded;
     result.defaultRemoved = defaultRemoved;
     result.customToolbars = customToolbars;
     result.addonToolbars = addonToolbars;
     result.addonBarItems = addonBarItems;
 
-    result.smallIcons = win.gNavToolbox.getAttribute("iconsize") == "small";
-    result.buttonMode = win.gNavToolbox.getAttribute("mode");
+    result.smallIcons = aWindow.gNavToolbox.getAttribute("iconsize") == "small";
+    result.buttonMode = aWindow.gNavToolbox.getAttribute("mode");
 
     // Find out how many open tabs we have in each window
     let winEnumerator = Services.wm.getEnumerator("navigator:browser");
     let visibleTabs = [];
     let hiddenTabs = [];
     while (winEnumerator.hasMoreElements()) {
       let someWin = winEnumerator.getNext();
       if (someWin.gBrowser) {
         let visibleTabsNum = someWin.gBrowser.visibleTabs.length;
         visibleTabs.push(visibleTabsNum);
         hiddenTabs.push(someWin.gBrowser.tabs.length - visibleTabsNum);
       }
     }
     result.visibleTabs = visibleTabs;
     result.hiddenTabs = hiddenTabs;
 
+    return result;
+  },
+
+  getToolbarMeasures: function() {
+    let result = this._firstWindowMeasurements || {};
     result.countableEvents = this._countableEvents;
     result.durations = this._durations;
-
     return result;
   },
 };
 
 /**
  * Returns the id of the first ancestor of aNode that has an id, with
  * ":child" appended to it. If aNode has no parent, or no ancestor has an
  * id, returns null.
@@ -619,9 +621,9 @@ function getIDBasedOnFirstIDedAncestor(a
  * our "special" items (spring, spacer, separator).
  *
  * @param aItemID the item ID to check.
  */
 function isSpecialToolbarItem(aItemID) {
   return aItemID == "spring" ||
          aItemID == "spacer" ||
          aItemID == "separator";
-}
\ No newline at end of file
+}