From 31972cbeb6c20441ac0da84be5d3f810d17d956c Mon Sep 17 00:00:00 2001 From: Gregory Szorc Date: Sun, 6 Jan 2013 18:23:16 -0800 Subject: [PATCH] Bug 827187 - Report default browser flag in Firefox Health Report; r=rnewman --- services/healthreport/providers.jsm | 31 +++++++++++++++++++ .../tests/xpcshell/test_provider_appinfo.js | 10 ++++++ 2 files changed, 41 insertions(+) diff --git a/services/healthreport/providers.jsm b/services/healthreport/providers.jsm index 449fffdf2e6..7aa1b0c1d56 100644 --- a/services/healthreport/providers.jsm +++ b/services/healthreport/providers.jsm @@ -78,6 +78,9 @@ AppInfoMeasurement.prototype = Object.freeze({ 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); }); }, }); @@ -220,6 +223,34 @@ AppInfoProvider.prototype = Object.freeze({ 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); }, }); diff --git a/services/healthreport/tests/xpcshell/test_provider_appinfo.js b/services/healthreport/tests/xpcshell/test_provider_appinfo.js index 664cd8cde2b..ad3200be10a 100644 --- a/services/healthreport/tests/xpcshell/test_provider_appinfo.js +++ b/services/healthreport/tests/xpcshell/test_provider_appinfo.js @@ -26,6 +26,7 @@ add_task(function test_collect_smoketest() { let provider = new AppInfoProvider(); yield provider.init(storage); + let now = new Date(); yield provider.collectConstantData(); let m = provider.getMeasurement("appinfo", 1); @@ -43,6 +44,15 @@ add_task(function test_collect_smoketest() { 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(); });