Skip to content

Commit

Permalink
Bug 828829 - Refactor Health Report policy out of services/healthrepo…
Browse files Browse the repository at this point in the history
…rt; r=rnewman

--HG--
rename : services/healthreport/HealthReportService.js => services/datareporting/DataReportingService.js
rename : services/healthreport/modules-testing/mocks.jsm => services/datareporting/modules-testing/mocks.jsm
rename : services/healthreport/policy.jsm => services/datareporting/policy.jsm
rename : services/healthreport/tests/xpcshell/test_policy.js => services/datareporting/tests/xpcshell/test_policy.js
extra : rebase_source : cf766bc99ff843f2d31f82b1c4be71313fbc65a8
  • Loading branch information
indygreg committed Jan 11, 2013
1 parent 7939b69 commit 57f274b
Show file tree
Hide file tree
Showing 24 changed files with 391 additions and 254 deletions.
6 changes: 3 additions & 3 deletions browser/installer/package-manifest.in
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@
@BINPATH@/components/AitcComponents.manifest
@BINPATH@/components/Aitc.js
#endif
#ifdef MOZ_SERVICES_HEALTHREPORT
@BINPATH@/components/HealthReportComponents.manifest
@BINPATH@/components/HealthReportService.js
#ifdef MOZ_DATA_REPORTING
@BINPATH@/components/DataReporting.manifest
@BINPATH@/components/DataReportingService.js
#endif
#ifdef MOZ_SERVICES_SYNC
@BINPATH@/components/SyncComponents.manifest
Expand Down
1 change: 1 addition & 0 deletions browser/installer/removed-files.in
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,7 @@ xpicleanup@BIN_SUFFIX@
components/GPSDGeolocationProvider.js
components/interfaces.manifest
components/jsconsole-clhandler.js
components/MetricsCollectionService.js
components/NetworkGeolocationProvider.js
components/NotificationsComponents.manifest
components/nsBadCertHandler.js
Expand Down
9 changes: 9 additions & 0 deletions configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -8719,6 +8719,15 @@ if test "$MOZ_TELEMETRY_REPORTING"; then
fi
fi

dnl If we have any service that uploads data (and requires data submission
dnl policy alert), set MOZ_DATA_REPORTING.
dnl We need SUBST for build system and DEFINE for xul preprocessor.
if test -n "$MOZ_TELEMETRY_REPORTING" || test -n "$MOZ_SERVICES_HEALTHREPORT" || test -n "MOZ_CRASHREPORTER"; then
MOZ_DATA_REPORTING=1
AC_DEFINE(MOZ_DATA_REPORTING)
AC_SUBST(MOZ_DATA_REPORTING)
fi

dnl win32 options
AC_SUBST(MOZ_MAPINFO)
AC_SUBST(MOZ_BROWSE_INFO)
Expand Down
4 changes: 4 additions & 0 deletions modules/libpref/src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ GARBAGE += greprefs.js
# TODO bug 813259 external files should be defined near their location in the source tree.
grepref_files = $(topsrcdir)/netwerk/base/public/security-prefs.js $(srcdir)/init/all.js

ifdef MOZ_DATA_REPORTING
grepref_files += $(topsrcdir)/services/datareporting/datareporting-prefs.js
endif

ifdef MOZ_SERVICES_HEALTHREPORT
grepref_files += $(topsrcdir)/services/healthreport/healthreport-prefs.js
endif
Expand Down
11 changes: 8 additions & 3 deletions services/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ VPATH = @srcdir@

include $(DEPTH)/config/autoconf.mk

PARALLEL_DIRS += common

PARALLEL_DIRS += crypto
PARALLEL_DIRS += \
common \
crypto \
$(NULL)

ifdef MOZ_SERVICES_AITC
PARALLEL_DIRS += aitc
Expand All @@ -21,6 +22,10 @@ ifdef MOZ_SERVICES_HEALTHREPORT
PARALLEL_DIRS += healthreport
endif

ifdef MOZ_DATA_REPORTING
PARALLEL_DIRS += datareporting
endif

ifdef MOZ_SERVICES_METRICS
PARALLEL_DIRS += metrics
endif
Expand Down
16 changes: 16 additions & 0 deletions services/datareporting/DataReporting.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# b2g: {3c2e2abc-06d4-11e1-ac3b-374f68613e61}
# browser: {ec8030f7-c20a-464f-9b0e-13a3a9e97384}
# mobile/android: {aa3c5121-dab2-40e2-81ca-7ea25febc110}
# mobile/xul: {a23983c0-fd0e-11dc-95ff-0800200c9a66}
# suite (comm): {92650c4d-4b8e-4d2a-b7eb-24ecf4f6b63a}
# metro browser: {99bceaaa-e3c6-48c1-b981-ef9b46b67d60}

# The Data Reporting Service drives collection and submission of metrics
# and other useful data to Mozilla. It drives the display of the data
# submission notification info bar and thus is required by Firefox Health
# Report and Telemetry.

component {41f6ae36-a79f-4613-9ac3-915e70f83789} DataReportingService.js
contract @mozilla.org/datareporting/service;1 {41f6ae36-a79f-4613-9ac3-915e70f83789}
category app-startup DataReportingService service,@mozilla.org/datareporting/service;1 application={3c2e2abc-06d4-11e1-ac3b-374f68613e61} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384} application={aa3c5121-dab2-40e2-81ca-7ea25febc110} application={a23983c0-fd0e-11dc-95ff-0800200c9a66}

Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@

const {classes: Cc, interfaces: Ci, utils: Cu} = Components;

Cu.import("resource://gre/modules/services/datareporting/policy.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://services-common/observers.js");
Cu.import("resource://services-common/preferences.js");


const BRANCH = "healthreport.";
const ROOT_BRANCH = "datareporting.";
const POLICY_BRANCH = ROOT_BRANCH + "policy.";
const HEALTHREPORT_BRANCH = ROOT_BRANCH + "healthreport.";
const HEALTHREPORT_LOGGING_BRANCH = HEALTHREPORT_BRANCH + "logging.";
const DEFAULT_LOAD_DELAY_MSEC = 10 * 1000;

/**
Expand All @@ -27,7 +32,7 @@ const DEFAULT_LOAD_DELAY_MSEC = 10 * 1000;
* let reporter = Cc["@mozilla.org/healthreport/service;1"]
* .getService(Ci.nsISupports)
* .wrappedJSObject
* .reporter;
* .healthReporter;
*
* if (reporter.haveRemoteData) {
* // ...
Expand All @@ -45,36 +50,77 @@ const DEFAULT_LOAD_DELAY_MSEC = 10 * 1000;
* instance (it registers observers on initialization). See the notes on that
* type for more.
*/
this.HealthReportService = function HealthReportService() {
this.DataReportingService = function () {
this.wrappedJSObject = this;

this._prefs = new Preferences(BRANCH);

this._reporter = null;
this._os = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
}

HealthReportService.prototype = {
classID: Components.ID("{e354c59b-b252-4040-b6dd-b71864e3e35c}"),
DataReportingService.prototype = Object.freeze({
classID: Components.ID("{41f6ae36-a79f-4613-9ac3-915e70f83789}"),

QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver,
Ci.nsISupportsWeakReference]),

observe: function observe(subject, topic, data) {
// If the background service is disabled, don't do anything.
if (!this._prefs.get("service.enabled", true)) {
//---------------------------------------------
// Start of policy listeners.
//---------------------------------------------

/**
* Called when policy requests data upload.
*/
onRequestDataUpload: function (request) {
if (!this.healthReporter) {
return;
}

let os = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
this.healthReporter.requestDataUpload(request);
},

onNotifyDataPolicy: function (request) {
Observers.notify("datareporting:notify-data-policy:request", request);
},

onRequestRemoteDelete: function (request) {
if (!this.healthReporter) {
return;
}

this.healthReporter.deleteRemoteData(request);
},

//---------------------------------------------
// End of policy listeners.
//---------------------------------------------

observe: function observe(subject, topic, data) {
switch (topic) {
case "app-startup":
os.addObserver(this, "sessionstore-windows-restored", true);
this._os.addObserver(this, "profile-after-change", true);
break;

case "profile-after-change":
this._os.removeObserver(this, "profile-after-change");
this._os.addObserver(this, "sessionstore-windows-restored", true);

// We can't interact with prefs until after the profile is present.
let policyPrefs = new Preferences(POLICY_BRANCH);
this._prefs = new Preferences(HEALTHREPORT_BRANCH);
this.policy = new DataReportingPolicy(policyPrefs, this._prefs, this);
break;

case "sessionstore-windows-restored":
os.removeObserver(this, "sessionstore-windows-restored");
this._os.removeObserver(this, "sessionstore-windows-restored");
this._os.addObserver(this, "quit-application", false);

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;
Expand All @@ -86,12 +132,17 @@ HealthReportService.prototype = {
notify: function notify() {
// Side effect: instantiates the reporter instance if not already
// accessed.
let reporter = this.reporter;
let reporter = this.healthReporter;
delete this.timer;
}.bind(this),
}, delayInterval, this.timer.TYPE_ONE_SHOT);

break;

case "quit-application":
this._os.removeObserver(this, "quit-application");
this.policy.stopPolling();
break;
}
},

Expand All @@ -102,33 +153,46 @@ HealthReportService.prototype = {
*
* The obtained instance may not be fully initialized.
*/
get reporter() {
get healthReporter() {
if (!this._prefs.get("service.enabled", true)) {
return null;
}

if (this._reporter) {
return this._reporter;
if ("_healthReporter" in this) {
return this._healthReporter;
}

try {
this._loadHealthReporter();
} catch (ex) {
dump("Error loading health reporter: " + ex);
this._healthReporter = null;
}

return this._healthReporter;
},

_loadHealthReporter: function () {
let ns = {};
// Lazy import so application startup isn't adversely affected.

Cu.import("resource://gre/modules/Task.jsm", ns);
Cu.import("resource://gre/modules/services/healthreport/healthreporter.jsm", ns);
Cu.import("resource://services-common/log4moz.js", ns);

// How many times will we rewrite this code before rolling it up into a
// generic module? See also bug 451283.
const LOGGERS = [
"Services.DataReporting",
"Services.HealthReport",
"Services.Metrics",
"Services.BagheeraClient",
"Sqlite.Connection.healthreport",
];

let prefs = new Preferences(BRANCH + "logging.");
if (prefs.get("consoleEnabled", true)) {
let level = prefs.get("consoleLevel", "Warn");
let loggingPrefs = new Preferences(HEALTHREPORT_LOGGING_BRANCH);
if (loggingPrefs.get("consoleEnabled", true)) {
let level = loggingPrefs.get("consoleLevel", "Warn");
let appender = new ns.Log4Moz.ConsoleAppender();
appender.level = ns.Log4Moz.Level[level] || ns.Log4Moz.Level.Warn;

Expand All @@ -139,13 +203,10 @@ HealthReportService.prototype = {
}

// The reporter initializes in the background.
this._reporter = new ns.HealthReporter(BRANCH);

return this._reporter;
this._healthReporter = new ns.HealthReporter(HEALTHREPORT_BRANCH,
this.policy);
},
};

Object.freeze(HealthReportService.prototype);
});

this.NSGetFactory = XPCOMUtils.generateNSGetFactory([HealthReportService]);
this.NSGetFactory = XPCOMUtils.generateNSGetFactory([DataReportingService]);

26 changes: 26 additions & 0 deletions services/datareporting/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

DEPTH = @DEPTH@
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@

include $(DEPTH)/config/autoconf.mk

TEST_DIRS += tests

MODULES_FILES := policy.jsm
MODULES_DEST = $(FINAL_TARGET)/modules/services/datareporting
INSTALL_TARGETS += MODULES

TESTING_JS_MODULES := $(addprefix modules-testing/,mocks.jsm)
TESTING_JS_MODULE_DIR := services/datareporting

EXTRA_COMPONENTS := \
DataReporting.manifest \
DataReportingService.js \
$(NULL)

include $(topsrcdir)/config/rules.mk
12 changes: 12 additions & 0 deletions services/datareporting/datareporting-prefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

pref("datareporting.policy.dataSubmissionEnabled", true);
pref("datareporting.policy.dataSubmissionPolicyAccepted", false);
pref("datareporting.policy.dataSubmissionPolicyBypassAcceptance", false);
pref("datareporting.policy.dataSubmissionPolicyNotifiedTime", "0");
pref("datareporting.policy.dataSubmissionPolicyResponseType", "");
pref("datareporting.policy.dataSubmissionPolicyResponseTime", "0");
pref("datareporting.policy.firstRunTime", "0");

Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Cu.import("resource://services-common/log4moz.js");


this.MockPolicyListener = function MockPolicyListener() {
this._log = Log4Moz.repository.getLogger("HealthReport.Testing.MockPolicyListener");
this._log = Log4Moz.repository.getLogger("Services.DataReporting.Testing.MockPolicyListener");
this._log.level = Log4Moz.Level["Debug"];

this.requestDataUploadCount = 0;
Expand Down Expand Up @@ -44,3 +44,4 @@ MockPolicyListener.prototype = {
this.lastNotifyRequest = request;
},
};

Loading

0 comments on commit 57f274b

Please sign in to comment.