Bug 827187 - Report default browser flag in Firefox Health Report; r=rnewman
authorGregory Szorc <gps@mozilla.com>
Sun, 06 Jan 2013 18:23:16 -0800
changeset 126954 967ca515b01226cd9f5e4bb635176f5b311d17e1
parent 126953 e261056671168bf16c618978f96ab3bb6c4e147c
child 126955 c5171c231bf486f5c6f27112e815f77bff2fa863
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs827187
milestone20.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 827187 - Report default browser flag in Firefox Health Report; r=rnewman
services/healthreport/providers.jsm
services/healthreport/tests/xpcshell/test_provider_appinfo.js
--- a/services/healthreport/providers.jsm
+++ b/services/healthreport/providers.jsm
@@ -73,16 +73,19 @@ AppInfoMeasurement.prototype = Object.fr
   ],
 
   configureStorage: function () {
     let self = this;
     return Task.spawn(function configureStorage() {
       for (let field of self.LAST_TEXT_FIELDS) {
         yield self.registerStorageField(field, self.storage.FIELD_LAST_TEXT);
       }
+
+      yield self.registerStorageField("isDefaultBrowser",
+                                      self.storage.FIELD_DAILY_LAST_NUMERIC);
     });
   },
 });
 
 
 function AppVersionMeasurement() {
   Metrics.Measurement.call(this);
 }
@@ -215,16 +218,44 @@ AppInfoProvider.prototype = Object.freez
       let locale = Cc["@mozilla.org/chrome/chrome-registry;1"]
                      .getService(Ci.nsIXULChromeRegistry)
                      .getSelectedLocale("global");
       yield m.setLastText("locale", locale);
     } catch (ex) {
       this._log.warn("Could not obtain application locale: " +
                      CommonUtils.exceptionStr(ex));
     }
+
+    // FUTURE this should be retrieved periodically or at upload time.
+    yield this._recordDefaultBrowser(m);
+  },
+
+  _recordDefaultBrowser: function (m) {
+    let shellService;
+    try {
+      shellService = Cc["@mozilla.org/browser/shell-service;1"]
+                       .getService(Ci.nsIShellService);
+    } catch (ex) {
+      this._log.warn("Could not obtain shell service: " +
+                     CommonUtils.exceptionStr(ex));
+    }
+
+    let isDefault = -1;
+
+    if (shellService) {
+      try {
+        // This uses the same set of flags used by the pref pane.
+        isDefault = shellService.isDefaultBrowser(false, true) ? 1 : 0;
+      } catch (ex) {
+        this._log.warn("Could not determine if default browser: " +
+                       CommonUtils.exceptionStr(ex));
+      }
+    }
+
+    return m.setDailyLastNumeric("isDefaultBrowser", isDefault);
   },
 });
 
 
 function SysInfoMeasurement() {
   Metrics.Measurement.call(this);
 }
 
--- a/services/healthreport/tests/xpcshell/test_provider_appinfo.js
+++ b/services/healthreport/tests/xpcshell/test_provider_appinfo.js
@@ -21,16 +21,17 @@ add_test(function test_constructor() {
   run_next_test();
 });
 
 add_task(function test_collect_smoketest() {
   let storage = yield Metrics.Storage("collect_smoketest");
   let provider = new AppInfoProvider();
   yield provider.init(storage);
 
+  let now = new Date();
   yield provider.collectConstantData();
 
   let m = provider.getMeasurement("appinfo", 1);
   let data = yield storage.getMeasurementValues(m.id);
   let serializer = m.serializer(m.SERIALIZE_JSON);
   let d = serializer.singular(data.singular);
 
   do_check_eq(d.vendor, "Mozilla");
@@ -38,16 +39,25 @@ add_task(function test_collect_smoketest
   do_check_eq(d.id, "xpcshell@tests.mozilla.org");
   do_check_eq(d.version, "1");
   do_check_eq(d.appBuildID, "20121107");
   do_check_eq(d.platformVersion, "p-ver");
   do_check_eq(d.platformBuildID, "20121106");
   do_check_eq(d.os, "XPCShell");
   do_check_eq(d.xpcomabi, "noarch-spidermonkey");
 
+  do_check_eq(data.days.size, 1);
+  do_check_true(data.days.hasDay(now));
+  let day = data.days.getDay(now);
+  do_check_eq(day.size, 1);
+  do_check_true(day.has("isDefaultBrowser"));
+
+  // Underlying shell service is not available in xpcshell tests.
+  do_check_eq(day.get("isDefaultBrowser"), -1);
+
   yield provider.shutdown();
   yield storage.close();
 });
 
 add_task(function test_record_version() {
   let storage = yield Metrics.Storage("record_version");
 
   let provider = new AppInfoProvider();