Bug 993084 - Don't load experiments module if the feature is preffed off. r=bsmedberg

This commit is contained in:
Georg Fritzsche 2014-04-10 16:56:25 +02:00
parent 30d47b9922
commit 87b9f492e1

View File

@ -8,8 +8,27 @@ const {interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource:///modules/experiments/Experiments.jsm");
Cu.import("resource://gre/modules/osfile.jsm")
XPCOMUtils.defineLazyModuleGetter(this, "Experiments",
"resource:///modules/experiments/Experiments.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "OS",
"resource://gre/modules/osfile.jsm");
const PREF_EXPERIMENTS_ENABLED = "experiments.enabled";
const PREF_HEALTHREPORT_ENABLED = "datareporting.healthreport.service.enabled";
const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled";
XPCOMUtils.defineLazyGetter(
this, "gExperimentsEnabled", () => {
try {
let prefs = Services.prefs;
return prefs.getBoolPref(PREF_EXPERIMENTS_ENABLED) &&
prefs.getBoolPref(PREF_TELEMETRY_ENABLED) &&
prefs.getBoolPref(PREF_HEALTHREPORT_ENABLED);
} catch (e) {
return false;
}
});
function ExperimentsService() {
}
@ -19,6 +38,9 @@ ExperimentsService.prototype = {
QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback, Ci.nsIObserver]),
notify: function (timer) {
if (!gExperimentsEnabled) {
return;
}
if (OS.Constants.Path.profileDir === undefined) {
throw Error("Update timer fired before profile was initialized?");
}
@ -28,7 +50,9 @@ ExperimentsService.prototype = {
observe: function (subject, topic, data) {
switch (topic) {
case "profile-after-change":
Experiments.instance(); // for side effects
if (gExperimentsEnabled) {
Experiments.instance(); // for side effects
}
break;
}
},