Bug 830489 - Delay initializing FHR database on first run; r=rnewman
authorGregory Szorc <gps@mozilla.com>
Tue, 05 Feb 2013 20:25:48 -0800
changeset 130813 42abb7556fd9fbe1de3ac897b62e651863d104f5
parent 130812 d5390130b80e142196a70412acef6da4b0149c80
child 130814 1ed20e6b41c2be5467bab8e2f0709f6a5ff67c28
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs830489
milestone21.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 830489 - Delay initializing FHR database on first run; r=rnewman
services/datareporting/DataReportingService.js
services/healthreport/healthreport-prefs.js
--- a/services/datareporting/DataReportingService.js
+++ b/services/datareporting/DataReportingService.js
@@ -12,16 +12,17 @@ Cu.import("resource://services-common/ut
 
 
 const ROOT_BRANCH = "datareporting.";
 const POLICY_BRANCH = ROOT_BRANCH + "policy.";
 const SESSIONS_BRANCH = ROOT_BRANCH + "sessions.";
 const HEALTHREPORT_BRANCH = ROOT_BRANCH + "healthreport.";
 const HEALTHREPORT_LOGGING_BRANCH = HEALTHREPORT_BRANCH + "logging.";
 const DEFAULT_LOAD_DELAY_MSEC = 10 * 1000;
+const DEFAULT_LOAD_DELAY_FIRST_RUN_MSEC = 60 * 1000;
 
 /**
  * The Firefox Health Report XPCOM service.
  *
  * External consumers will be interested in the "reporter" property of this
  * service. This property is a `HealthReporter` instance that powers the
  * service. The property may be null if the Health Report service is not
  * enabled.
@@ -39,17 +40,20 @@ const DEFAULT_LOAD_DELAY_MSEC = 10 * 100
  * }
  *
  * IMPLEMENTATION NOTES
  * ====================
  *
  * In order to not adversely impact application start time, the `HealthReporter`
  * instance is not initialized until a few seconds after "final-ui-startup."
  * The exact delay is configurable via preferences so it can be adjusted with
- * a hotfix extension if the default value is ever problematic.
+ * a hotfix extension if the default value is ever problematic. Because of the
+ * overhead with the initial creation of the database, the first run is delayed
+ * even more than subsequent runs. This does mean that the first moments of
+ * browser activity may be lost by FHR.
  *
  * Shutdown of the `HealthReporter` instance is handled completely within the
  * instance (it registers observers on initialization). See the notes on that
  * type for more.
  */
 this.DataReportingService = function () {
   this.wrappedJSObject = this;
 
@@ -131,18 +135,26 @@ DataReportingService.prototype = Object.
         this.policy.startPolling();
 
         // Don't initialize Firefox Health Reporter collection and submission
         // service unless it is enabled.
         if (!this._prefs.get("service.enabled", true)) {
           return;
         }
 
-        let delayInterval = this._prefs.get("service.loadDelayMsec") ||
-                            DEFAULT_LOAD_DELAY_MSEC;
+        let haveFirstRun = this._prefs.get("service.firstRun", false);
+        let delayInterval;
+
+        if (haveFirstRun) {
+          delayInterval = this._prefs.get("service.loadDelayMsec") ||
+                          DEFAULT_LOAD_DELAY_MSEC;
+        } else {
+          delayInterval = this._prefs.get("service.loadDelayFirstRunMsec") ||
+                          DEFAULT_LOAD_DELAY_FIRST_RUN_MSEC;
+        }
 
         // Delay service loading a little more so things have an opportunity
         // to cool down first.
         this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
         this.timer.initWithCallback({
           notify: function notify() {
             delete this.timer;
 
@@ -234,16 +246,22 @@ DataReportingService.prototype = Object.
         logger.addAppender(appender);
       }
     }
 
     // The reporter initializes in the background.
     this._healthReporter = new ns.HealthReporter(HEALTHREPORT_BRANCH,
                                                  this.policy,
                                                  this.sessionRecorder);
+
+    // Wait for initialization to finish so if a shutdown occurs before init
+    // has finished we don't adversely affect app startup on next run.
+    this._healthReporter.onInit().then(function onInit() {
+      this._prefs.set("service.firstRun", true);
+    }.bind(this));
   },
 });
 
 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DataReportingService]);
 
 #define MERGED_COMPARTMENT
 
 #include ../common/observers.js
--- a/services/healthreport/healthreport-prefs.js
+++ b/services/healthreport/healthreport-prefs.js
@@ -14,12 +14,13 @@ pref("datareporting.healthreport.lastDat
 pref("datareporting.healthreport.nextDataSubmissionTime", "0");
 pref("datareporting.healthreport.pendingDeleteRemoteData", false);
 
 // Health Report is enabled by default on all channels.
 pref("datareporting.healthreport.uploadEnabled", true);
 
 pref("datareporting.healthreport.service.enabled", true);
 pref("datareporting.healthreport.service.loadDelayMsec", 10000);
+pref("datareporting.healthreport.service.loadDelayFirstRunMsec", 60000);
 pref("datareporting.healthreport.service.providerCategories", "healthreport-js-provider");
 
 pref("datareporting.healthreport.about.glossaryUrl", "https://services.mozilla.com/healthreport/glossary.html");
 pref("datareporting.healthreport.about.reportUrl",   "https://services.mozilla.com/healthreport/placeholder.html");