diff --git a/browser/experiments/ExperimentsService.js b/browser/experiments/ExperimentsService.js index 516863d2c71..e2b38c99ca2 100644 --- a/browser/experiments/ExperimentsService.js +++ b/browser/experiments/ExperimentsService.js @@ -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; } },