Bug 1101487 - Bonus: Use Preferences.jsm in TelemetryPing for cleaner default values. r=vladan, a=sledru
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Wed, 17 Dec 2014 18:21:37 +0100
changeset 242508 a0f19d8c4bd66b255de8e82d704929495b010875
parent 242507 71075cc6d27d17773279ab7d56eb6df3d7cba1b1
child 242509 a6f176bb961f229255d31f46bccbe1aa2488b6f2
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvladan, sledru
bugs1101487
milestone36.0a2
Bug 1101487 - Bonus: Use Preferences.jsm in TelemetryPing for cleaner default values. r=vladan, a=sledru
toolkit/components/telemetry/TelemetryPing.jsm
--- a/toolkit/components/telemetry/TelemetryPing.jsm
+++ b/toolkit/components/telemetry/TelemetryPing.jsm
@@ -735,24 +735,17 @@ let Impl = {
     };
 
     if (Object.keys(this._slowSQLStartup).length != 0 &&
         (Object.keys(this._slowSQLStartup.mainThread).length ||
          Object.keys(this._slowSQLStartup.otherThreads).length)) {
       payloadObj.slowSQLStartup = this._slowSQLStartup;
     }
 
-    let fhrUploadEnabled = false;
-    try {
-      fhrUploadEnabled = Services.prefs.getBoolPref(PREF_FHR_UPLOAD_ENABLED);
-    } catch (e) {
-      // Pref not set.
-    }
-
-    if (this._clientID && fhrUploadEnabled) {
+    if (this._clientID && Preferences.get(PREF_FHR_UPLOAD_ENABLED, false)) {
       payloadObj.clientID = this._clientID;
     }
 
     return payloadObj;
   },
 
   getSessionPayload: function getSessionPayload(reason) {
     let measurements = this.getSimpleMeasurements(reason == "saved-session");
@@ -915,46 +908,37 @@ let Impl = {
    */
   setup: function setup(aTesting) {
     // Initialize some probes that are kept in their own modules
     this._thirdPartyCookies = new ThirdPartyCookieProbe();
     this._thirdPartyCookies.init();
 
     // Record old value and update build ID preference if this is the first
     // run with a new build ID.
-    let previousBuildID = undefined;
-    try {
-      previousBuildID = Services.prefs.getCharPref(PREF_PREVIOUS_BUILDID);
-    } catch (e) {
-      // Preference was not set.
-    }
+    let previousBuildID = Preferences.get(PREF_PREVIOUS_BUILDID, undefined);
     let thisBuildID = Services.appinfo.appBuildID;
     // If there is no previousBuildID preference, this._previousBuildID remains
     // undefined so no value is sent in the telemetry metadata.
     if (previousBuildID != thisBuildID) {
       this._previousBuildID = previousBuildID;
-      Services.prefs.setCharPref(PREF_PREVIOUS_BUILDID, thisBuildID);
+      Preferences.set(PREF_PREVIOUS_BUILDID, thisBuildID);
     }
 
 #ifdef MOZILLA_OFFICIAL
     if (!Telemetry.canSend && !aTesting) {
       // We can't send data; no point in initializing observers etc.
       // Only do this for official builds so that e.g. developer builds
       // still enable Telemetry based on prefs.
       Telemetry.canRecord = false;
       return;
     }
 #endif
-    let enabled = false;
-    try {
-      enabled = Services.prefs.getBoolPref(PREF_ENABLED);
-      this._server = Services.prefs.getCharPref(PREF_SERVER);
-    } catch (e) {
-      // Prerequesite prefs aren't set
-    }
+
+    let enabled = Preferences.get(PREF_ENABLED, false);
+    this._server = Preferences.get(PREF_SERVER, undefined);
     if (!enabled) {
       // Turn off local telemetry if telemetry is disabled.
       // This may change once about:telemetry is added.
       Telemetry.canRecord = false;
       return;
     }
 
     // For very short session durations, we may never load the client