Bug 1473631: Part 15 - Use a single pref observer for all telemetry environmernt preferences. r?gfritzsche draft
authorKris Maglione <maglione.k@gmail.com>
Thu, 05 Jul 2018 15:26:37 -0700
changeset 818487 aef52a1776f85abbe2aeacb41166ad0c7f3e8262
parent 818486 c74f5185dc3d2680ac76e83106680d5f781474f4
push id116269
push usermaglione.k@gmail.com
push dateSat, 14 Jul 2018 02:18:47 +0000
reviewersgfritzsche
bugs1473631
milestone63.0a1
Bug 1473631: Part 15 - Use a single pref observer for all telemetry environmernt preferences. r?gfritzsche MozReview-Commit-ID: dGJDjUP4Vm
toolkit/components/telemetry/TelemetryEnvironment.jsm
--- 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.