Bug 1473631: Part 15 - Use a single pref observer for all telemetry environmernt preferences. r?gfritzsche
MozReview-Commit-ID: dGJDjUP4Vm
--- a/toolkit/components/telemetry/TelemetryEnvironment.jsm
+++ b/toolkit/components/telemetry/TelemetryEnvironment.jsm
@@ -1121,41 +1121,33 @@ EnvironmentCache.prototype = {
QueryInterface: ChromeUtils.generateQI([Ci.nsISupportsWeakReference]),
/**
* Start watching the preferences.
*/
_startWatchingPrefs() {
this._log.trace("_startWatchingPrefs - " + this._watchedPrefs);
- for (let [pref, options] of this._watchedPrefs) {
- if (!("requiresRestart" in options) || !options.requiresRestart) {
- Services.prefs.addObserver(pref, this, true);
- }
- }
+ Services.prefs.addObserver("", this, true);
},
_onPrefChanged(aData) {
this._log.trace("_onPrefChanged");
let oldEnvironment = Cu.cloneInto(this._currentEnvironment, myScope);
this._currentEnvironment.settings.userPrefs[aData] = this._getPrefValue(aData, this._watchedPrefs.get(aData).what);
this._onEnvironmentChange("pref-changed", oldEnvironment);
},
/**
* Do not receive any more change notifications for the preferences.
*/
_stopWatchingPrefs() {
this._log.trace("_stopWatchingPrefs");
- for (let [pref, options] of this._watchedPrefs) {
- if (!("requiresRestart" in options) || !options.requiresRestart) {
- Services.prefs.removeObserver(pref, this);
- }
- }
+ Services.prefs.removeObserver("", this);
},
_addObservers() {
// Watch the search engine change and service topics.
Services.obs.addObserver(this, SESSIONSTORE_WINDOWS_RESTORED_TOPIC);
Services.obs.addObserver(this, COMPOSITOR_CREATED_TOPIC);
Services.obs.addObserver(this, COMPOSITOR_PROCESS_ABORTED_TOPIC);
Services.obs.addObserver(this, DISTRIBUTION_CUSTOMIZATION_COMPLETE_TOPIC);
@@ -1217,17 +1209,18 @@ EnvironmentCache.prototype = {
// Make sure to initialize the search service once we've done restoring
// the windows, so that we don't risk loosing search data.
Services.search.init();
// The default browser check could take some time, so just call it after
// the session was restored.
this._updateDefaultBrowser();
break;
case PREF_CHANGED_TOPIC:
- if (this._watchedPrefs.has(aData)) {
+ let options = this._watchedPrefs.get(aData);
+ if (options && !options.requiresRestart) {
this._onPrefChanged(aData);
}
break;
}
},
/**
* Get the default search engine.