Bug 1064333 - Only add the stable user id to the ping when FHR upload is enabled. r=froydnj, a=lmandel
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Fri, 17 Oct 2014 17:24:05 +0200
changeset 225902 ec67776fc5e3
parent 225901 ad6d502a38c9
child 225903 efb3c956dfef
push id4063
push usergeorg.fritzsche@googlemail.com
push date2014-11-02 23:54 +0000
treeherdermozilla-beta@1ca39da5df9d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, lmandel
bugs1064333
milestone34.0
Bug 1064333 - Only add the stable user id to the ping when FHR upload is enabled. r=froydnj, a=lmandel
toolkit/components/telemetry/TelemetryPing.jsm
toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
toolkit/components/telemetry/tests/unit/test_TelemetryPingBuildID.js
--- a/toolkit/components/telemetry/TelemetryPing.jsm
+++ b/toolkit/components/telemetry/TelemetryPing.jsm
@@ -27,16 +27,17 @@ const PAYLOAD_VERSION = 1;
 // This is the HG changeset of the Histogram.json file, used to associate
 // submitted ping data with its histogram definition (bug 832007)
 #expand const HISTOGRAMS_FILE_VERSION = "__HISTOGRAMS_FILE_VERSION__";
 
 const PREF_BRANCH = "toolkit.telemetry.";
 const PREF_SERVER = PREF_BRANCH + "server";
 const PREF_ENABLED = PREF_BRANCH + "enabled";
 const PREF_PREVIOUS_BUILDID = PREF_BRANCH + "previousBuildID";
+const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
 
 // Do not gather data more than once a minute
 const TELEMETRY_INTERVAL = 60000;
 // Delay before intializing telemetry (ms)
 const TELEMETRY_DELAY = 60000;
 // Delay before initializing telemetry if we're testing (ms)
 const TELEMETRY_TEST_DELAY = 100;
 
@@ -698,25 +699,35 @@ let Impl = {
       chromeHangs: Telemetry.chromeHangs,
       threadHangStats: this.getThreadHangStats(Telemetry.threadHangStats),
       lateWrites: Telemetry.lateWrites,
       addonHistograms: this.getAddonHistograms(),
       addonDetails: AddonManagerPrivate.getTelemetryDetails(),
       UIMeasurements: UITelemetry.getUIMeasurements(),
       log: TelemetryLog.entries(),
       info: info,
-      clientID: this._clientID,
     };
 
     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) {
+      payloadObj.clientID = this._clientID;
+    }
+
     return payloadObj;
   },
 
   getSessionPayload: function getSessionPayload(reason) {
     let measurements = this.getSimpleMeasurements(reason == "saved-session");
     let info = this.getMetadata(reason);
     return this.assemblePayloadWithMeasurements(measurements, info);
   },
@@ -954,20 +965,22 @@ let Impl = {
           // since it's never sent to the server. All that this.send does with
           // the reason is check to make sure it's not a test-ping.
           yield this.send("overdue-flush", this._server);
         }
 
         this.attachObservers();
         this.gatherMemory();
 
-        let drs = Cc["@mozilla.org/datareporting/service;1"]
-                    .getService(Ci.nsISupports)
-                    .wrappedJSObject;
-        this._clientID = yield drs.getClientID();
+        if ("@mozilla.org/datareporting/service;1" in Cc) {
+          let drs = Cc["@mozilla.org/datareporting/service;1"]
+                      .getService(Ci.nsISupports)
+                      .wrappedJSObject;
+          this._clientID = yield drs.getClientID();
+        }
 
         Telemetry.asyncFetchTelemetryData(function () {});
         delete this._timer;
         deferred.resolve();
       }.bind(this));
     }
 
     this._timer.initWithCallback(timerCallback.bind(this),
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPing.js
@@ -38,16 +38,17 @@ const PR_CREATE_FILE = 0x8;
 const PR_TRUNCATE = 0x20;
 const RW_OWNER = 0600;
 
 const NUMBER_OF_THREADS_TO_LAUNCH = 30;
 let gNumberOfThreadsLaunched = 0;
 
 const PREF_BRANCH = "toolkit.telemetry.";
 const PREF_ENABLED = PREF_BRANCH + "enabled";
+const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
 
 const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
 
 let gHttpServer = new HttpServer();
 let gServerStarted = false;
 let gRequestIterator = null;
 let gDataReportingClientID = null;
 
@@ -162,19 +163,22 @@ function checkPayloadInfo(payload, reaso
   }
 
   do_check_eq(payload.info.reason, reason);
   do_check_true("appUpdateChannel" in payload.info);
   do_check_true("locale" in payload.info);
   do_check_true("revision" in payload.info);
   do_check_true(payload.info.revision.startsWith("http"));
 
-  do_check_true("clientID" in payload);
-  do_check_neq(payload.clientID, null);
-  do_check_eq(payload.clientID, gDataReportingClientID);
+  if ("@mozilla.org/datareporting/service;1" in Cc &&
+      Services.prefs.getBoolPref(PREF_FHR_UPLOAD_ENABLED)) {
+    do_check_true("clientID" in payload);
+    do_check_neq(payload.clientID, null);
+    do_check_eq(payload.clientID, gDataReportingClientID);
+  }
 
   try {
     // If we've not got nsIGfxInfoDebug, then this will throw and stop us doing
     // this test.
     let gfxInfo = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfoDebug);
     let isWindows = ("@mozilla.org/windows-registry-key;1" in Components.classes);
     let isOSX = ("nsILocalFileMac" in Components.interfaces);
 
@@ -366,21 +370,24 @@ function run_test() {
     // If we can't test gfxInfo, that's fine, we'll note it later.
   }
 
   // Addon manager needs a profile directory
   do_get_profile();
   createAppInfo("xpcshell@tests.mozilla.org", "XPCShell", "1", "1.9.2");
 
   Services.prefs.setBoolPref(PREF_ENABLED, true);
+  Services.prefs.setBoolPref(PREF_FHR_UPLOAD_ENABLED, true);
 
   // Send the needed startup notifications to the datareporting service
   // to ensure that it has been initialized.
-  gDatareportingService.observe(null, "app-startup", null);
-  gDatareportingService.observe(null, "profile-after-change", null);
+  if ("@mozilla.org/datareporting/service;1" in Cc) {
+    gDatareportingService.observe(null, "app-startup", null);
+    gDatareportingService.observe(null, "profile-after-change", null);
+  }
 
   // Make it look like we've previously failed to lock a profile a couple times.
   write_fake_failedprofilelocks_file();
 
   // Make it look like we've shutdown before.
   write_fake_shutdown_file();
 
   let currentMaxNumberOfThreads = Telemetry.maximalNumberOfConcurrentThreads;
@@ -421,17 +428,19 @@ function actualTest() {
   registerFakePluginHost();
 
   run_next_test();
 }
 
 add_task(function* asyncSetup() {
   yield TelemetryPing.setup();
 
-  gDataReportingClientID = yield gDatareportingService.getClientID();
+  if ("@mozilla.org/datareporting/service;1" in Cc) {
+    gDataReportingClientID = yield gDatareportingService.getClientID();
+  }
 });
 
 // Ensure that not overwriting an existing file fails silently
 add_task(function* test_overwritePing() {
   let ping = {slug: "foo"}
   yield TelemetryFile.savePing(ping, true);
   yield TelemetryFile.savePing(ping, false);
   yield TelemetryFile.cleanupPingFile(ping);
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryPingBuildID.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryPingBuildID.js
@@ -69,13 +69,15 @@ add_task(function* test_newBuild() {
 
 
 function run_test() {
   // Make sure we have a profile directory.
   do_get_profile();
 
   // Send the needed startup notifications to the datareporting service
   // to ensure that it has been initialized.
-  gDatareportingService.observe(null, "app-startup", null);
-  gDatareportingService.observe(null, "profile-after-change", null);
+  if ("@mozilla.org/datareporting/service;1" in Cc) {
+    gDatareportingService.observe(null, "app-startup", null);
+    gDatareportingService.observe(null, "profile-after-change", null);
+  }
 
   run_next_test();
 }