Bug 1190837 - MozSelfsupport.healthReportDataSubmissionEnabled does not work when turning off DRS/FHR. r=gfritzsche
authorGeorg Fritzsche <georg.fritzsche@googlemail.com>
Tue, 04 Aug 2015 16:47:22 +0200
changeset 260855 d3d166232d2d5244a89bbf16b0de23d4227d846a
parent 260779 65e92b72d58451d7920a25c6186cd4426a3f2e37
child 260856 3a6613c338c266d7d18837a8eb6b1b7f5c037708
push id29328
push userkwierso@gmail.com
push dateFri, 04 Sep 2015 22:13:38 +0000
treeherdermozilla-central@d41fa6f2f1da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1190837
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1190837 - MozSelfsupport.healthReportDataSubmissionEnabled does not work when turning off DRS/FHR. r=gfritzsche
browser/components/selfsupport/SelfSupportService.js
--- a/browser/components/selfsupport/SelfSupportService.js
+++ b/browser/components/selfsupport/SelfSupportService.js
@@ -3,21 +3,30 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 "use strict";
 
 const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/Preferences.jsm");
 
-const policy = Cc["@mozilla.org/datareporting/service;1"]
-                 .getService(Ci.nsISupports)
-                 .wrappedJSObject
-                 .policy;
+const PREF_FHR_UPLOAD_ENABLED = "datareporting.healthreport.uploadEnabled";
+
+XPCOMUtils.defineLazyGetter(this, "gPolicy", () => {
+  try {
+    return Cc["@mozilla.org/datareporting/service;1"]
+             .getService(Ci.nsISupports)
+             .wrappedJSObject
+             .policy;
+  } catch (e) {
+    return undefined;
+  }
+});
 
 XPCOMUtils.defineLazyGetter(this, "reporter", () => {
   return Cc["@mozilla.org/datareporting/service;1"]
            .getService(Ci.nsISupports)
            .wrappedJSObject
            .healthReporter;
 });
 
@@ -39,24 +48,35 @@ MozSelfSupportInterface.prototype = {
 
   _window: null,
 
   init: function (window) {
     this._window = window;
   },
 
   get healthReportDataSubmissionEnabled() {
-    return policy.healthReportUploadEnabled;
+    if (gPolicy) {
+      return gPolicy.healthReportUploadEnabled;
+    }
+
+    // The datareporting service is unavailable or disabled.
+    return Preferences.get(PREF_FHR_UPLOAD_ENABLED, false);
   },
 
   set healthReportDataSubmissionEnabled(enabled) {
-    let reason = "Self-support interface sent " +
-                 (enabled ? "opt-in" : "opt-out") +
-                 " command.";
-    policy.recordHealthReportUploadEnabled(enabled, reason);
+    if (gPolicy) {
+      let reason = "Self-support interface sent " +
+                   (enabled ? "opt-in" : "opt-out") +
+                   " command.";
+      gPolicy.recordHealthReportUploadEnabled(enabled, reason);
+      return;
+    }
+
+    // The datareporting service is unavailable or disabled.
+    Preferences.set(PREF_FHR_UPLOAD_ENABLED, enabled);
   },
 
   getHealthReportPayload: function () {
     return new this._window.Promise(function (aResolve, aReject) {
       if (reporter) {
         let resolvePayload = function () {
           reporter.collectAndObtainJSONPayload(true).then(aResolve, aReject);
         };