From 1e2f53713b9bbe9c5d315113460e04eede71eea9 Mon Sep 17 00:00:00 2001 From: Mike Conley Date: Thu, 2 Jan 2014 19:02:46 -0500 Subject: [PATCH] Bug 956138 - [Australis] Have BrowserUITelemetry wait for sessionstore-windows-restored before gathering measurements. r=jaws. --- browser/modules/BrowserUITelemetry.jsm | 37 +++++++++++++++++--------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/browser/modules/BrowserUITelemetry.jsm b/browser/modules/BrowserUITelemetry.jsm index 5bfae91f630..17f07dd8ccb 100644 --- a/browser/modules/BrowserUITelemetry.jsm +++ b/browser/modules/BrowserUITelemetry.jsm @@ -130,12 +130,18 @@ 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; } }, @@ -200,16 +206,23 @@ this.BrowserUITelemetry = { }, _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); - } + _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) { aWindow.addEventListener("unload", this); let document = aWindow.document; @@ -419,4 +432,4 @@ function getIDBasedOnFirstIDedAncestor(aNode) { } return aNode.id; -} \ No newline at end of file +}