Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | const {interfaces: Ci, utils: Cu} = Components; |
michael@0 | 8 | |
michael@0 | 9 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 10 | Cu.import("resource://gre/modules/Services.jsm"); |
michael@0 | 11 | Cu.import("resource://gre/modules/Preferences.jsm"); |
michael@0 | 12 | |
michael@0 | 13 | XPCOMUtils.defineLazyModuleGetter(this, "Experiments", |
michael@0 | 14 | "resource:///modules/experiments/Experiments.jsm"); |
michael@0 | 15 | XPCOMUtils.defineLazyModuleGetter(this, "OS", |
michael@0 | 16 | "resource://gre/modules/osfile.jsm"); |
michael@0 | 17 | XPCOMUtils.defineLazyModuleGetter(this, "CommonUtils", |
michael@0 | 18 | "resource://services-common/utils.js"); |
michael@0 | 19 | |
michael@0 | 20 | const PREF_EXPERIMENTS_ENABLED = "experiments.enabled"; |
michael@0 | 21 | const PREF_ACTIVE_EXPERIMENT = "experiments.activeExperiment"; // whether we have an active experiment |
michael@0 | 22 | const PREF_HEALTHREPORT_ENABLED = "datareporting.healthreport.service.enabled"; |
michael@0 | 23 | const PREF_TELEMETRY_ENABLED = "toolkit.telemetry.enabled"; |
michael@0 | 24 | const DELAY_INIT_MS = 30 * 1000; |
michael@0 | 25 | |
michael@0 | 26 | XPCOMUtils.defineLazyGetter( |
michael@0 | 27 | this, "gPrefs", () => { |
michael@0 | 28 | return new Preferences(); |
michael@0 | 29 | }); |
michael@0 | 30 | |
michael@0 | 31 | XPCOMUtils.defineLazyGetter( |
michael@0 | 32 | this, "gExperimentsEnabled", () => { |
michael@0 | 33 | return gPrefs.get(PREF_EXPERIMENTS_ENABLED, false) && |
michael@0 | 34 | gPrefs.get(PREF_TELEMETRY_ENABLED, false) && |
michael@0 | 35 | gPrefs.get(PREF_HEALTHREPORT_ENABLED, false); |
michael@0 | 36 | }); |
michael@0 | 37 | |
michael@0 | 38 | XPCOMUtils.defineLazyGetter( |
michael@0 | 39 | this, "gActiveExperiment", () => { |
michael@0 | 40 | return gPrefs.get(PREF_ACTIVE_EXPERIMENT); |
michael@0 | 41 | }); |
michael@0 | 42 | |
michael@0 | 43 | function ExperimentsService() { |
michael@0 | 44 | this._initialized = false; |
michael@0 | 45 | this._delayedInitTimer = null; |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | ExperimentsService.prototype = { |
michael@0 | 49 | classID: Components.ID("{f7800463-3b97-47f9-9341-b7617e6d8d49}"), |
michael@0 | 50 | QueryInterface: XPCOMUtils.generateQI([Ci.nsITimerCallback, Ci.nsIObserver]), |
michael@0 | 51 | |
michael@0 | 52 | notify: function (timer) { |
michael@0 | 53 | if (!gExperimentsEnabled) { |
michael@0 | 54 | return; |
michael@0 | 55 | } |
michael@0 | 56 | if (OS.Constants.Path.profileDir === undefined) { |
michael@0 | 57 | throw Error("Update timer fired before profile was initialized?"); |
michael@0 | 58 | } |
michael@0 | 59 | Experiments.instance().updateManifest(); |
michael@0 | 60 | }, |
michael@0 | 61 | |
michael@0 | 62 | _delayedInit: function () { |
michael@0 | 63 | if (!this._initialized) { |
michael@0 | 64 | this._initialized = true; |
michael@0 | 65 | Experiments.instance(); // for side effects |
michael@0 | 66 | } |
michael@0 | 67 | }, |
michael@0 | 68 | |
michael@0 | 69 | observe: function (subject, topic, data) { |
michael@0 | 70 | switch (topic) { |
michael@0 | 71 | case "profile-after-change": |
michael@0 | 72 | if (gExperimentsEnabled) { |
michael@0 | 73 | Services.obs.addObserver(this, "quit-application", false); |
michael@0 | 74 | Services.obs.addObserver(this, "sessionstore-state-finalized", false); |
michael@0 | 75 | Services.obs.addObserver(this, "EM-loaded", false); |
michael@0 | 76 | |
michael@0 | 77 | if (gActiveExperiment) { |
michael@0 | 78 | this._initialized = true; |
michael@0 | 79 | Experiments.instance(); // for side effects |
michael@0 | 80 | } |
michael@0 | 81 | } |
michael@0 | 82 | break; |
michael@0 | 83 | case "sessionstore-state-finalized": |
michael@0 | 84 | if (!this._initialized) { |
michael@0 | 85 | CommonUtils.namedTimer(this._delayedInit, DELAY_INIT_MS, this, "_delayedInitTimer"); |
michael@0 | 86 | } |
michael@0 | 87 | break; |
michael@0 | 88 | case "EM-loaded": |
michael@0 | 89 | if (!this._initialized) { |
michael@0 | 90 | Experiments.instance(); // for side effects |
michael@0 | 91 | this._initialized = true; |
michael@0 | 92 | |
michael@0 | 93 | if (this._delayedInitTimer) { |
michael@0 | 94 | this._delayedInitTimer.clear(); |
michael@0 | 95 | } |
michael@0 | 96 | } |
michael@0 | 97 | break; |
michael@0 | 98 | case "quit-application": |
michael@0 | 99 | Services.obs.removeObserver(this, "quit-application"); |
michael@0 | 100 | Services.obs.removeObserver(this, "sessionstore-state-finalized"); |
michael@0 | 101 | Services.obs.removeObserver(this, "EM-loaded"); |
michael@0 | 102 | if (this._delayedInitTimer) { |
michael@0 | 103 | this._delayedInitTimer.clear(); |
michael@0 | 104 | } |
michael@0 | 105 | break; |
michael@0 | 106 | } |
michael@0 | 107 | }, |
michael@0 | 108 | }; |
michael@0 | 109 | |
michael@0 | 110 | this.NSGetFactory = XPCOMUtils.generateNSGetFactory([ExperimentsService]); |