Bug 1382196 - Use the prefs defined in TelemetryUtils.jsm in TelemetryReportingPolicy.jsm. r=dexter
authorAlejandro Rodriguez Salamanca <alexrs95>
Wed, 26 Jul 2017 06:30:00 +0200
changeset 420090 a86a44628486dbe2f350ce6bbdf86564d1fa32d9
parent 420089 312e9e393fd30569fb1cdc3f40a9e9f926794a14
child 420091 de7d3afbe971ea3e26d019d855d6d74d38f5d9ca
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdexter
bugs1382196
milestone56.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 1382196 - Use the prefs defined in TelemetryUtils.jsm in TelemetryReportingPolicy.jsm. r=dexter
toolkit/components/telemetry/TelemetryReportingPolicy.jsm
toolkit/components/telemetry/TelemetryUtils.jsm
--- a/toolkit/components/telemetry/TelemetryReportingPolicy.jsm
+++ b/toolkit/components/telemetry/TelemetryReportingPolicy.jsm
@@ -11,50 +11,32 @@ this.EXPORTED_SYMBOLS = [
 const {classes: Cc, interfaces: Ci, results: Cr, utils: Cu} = Components;
 
 Cu.import("resource://gre/modules/Log.jsm", this);
 Cu.import("resource://gre/modules/Preferences.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/Timer.jsm", this);
 Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
 Cu.import("resource://services-common/observers.js", this);
+Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 
 XPCOMUtils.defineLazyModuleGetter(this, "TelemetrySend",
                                   "resource://gre/modules/TelemetrySend.jsm");
 XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
                                   "resource://gre/modules/UpdateUtils.jsm");
 
 const LOGGER_NAME = "Toolkit.Telemetry";
 const LOGGER_PREFIX = "TelemetryReportingPolicy::";
 
 // Oldest year to allow in date preferences. The FHR infobar was implemented in
 // 2012 and no dates older than that should be encountered.
 const OLDEST_ALLOWED_ACCEPTANCE_YEAR = 2012;
 
 const PREF_BRANCH = "datareporting.policy.";
-// Indicates whether this is the first run or not. This is used to decide when to display
-// the policy.
-const PREF_FIRST_RUN = "toolkit.telemetry.reportingpolicy.firstRun";
-// Allows to skip the datachoices infobar. This should only be used in tests.
-const PREF_BYPASS_NOTIFICATION = PREF_BRANCH + "dataSubmissionPolicyBypassNotification";
-// The submission kill switch: if this preference is disable, no submission will ever take place.
-const PREF_DATA_SUBMISSION_ENABLED = PREF_BRANCH + "dataSubmissionEnabled";
-// This preference holds the current policy version, which overrides
-// DEFAULT_DATAREPORTING_POLICY_VERSION
-const PREF_CURRENT_POLICY_VERSION = PREF_BRANCH + "currentPolicyVersion";
-// This indicates the minimum required policy version. If the accepted policy version
-// is lower than this, the notification bar must be showed again.
-const PREF_MINIMUM_POLICY_VERSION = PREF_BRANCH + "minimumPolicyVersion";
-// The version of the accepted policy.
-const PREF_ACCEPTED_POLICY_VERSION = PREF_BRANCH + "dataSubmissionPolicyAcceptedVersion";
-// The date user accepted the policy.
-const PREF_ACCEPTED_POLICY_DATE = PREF_BRANCH + "dataSubmissionPolicyNotifiedTime";
-// URL of privacy policy to be opened in a background tab on first run instead of showing the
-// data choices infobar.
-const PREF_FIRST_RUN_URL = PREF_BRANCH + "firstRunURL";
+
 // The following preferences are deprecated and will be purged during the preferences
 // migration process.
 const DEPRECATED_FHR_PREFS = [
   PREF_BRANCH + "dataSubmissionPolicyAccepted",
   PREF_BRANCH + "dataSubmissionPolicyBypassAcceptance",
   PREF_BRANCH + "dataSubmissionPolicyResponseType",
   PREF_BRANCH + "dataSubmissionPolicyResponseTime"
 ];
@@ -199,17 +181,17 @@ var TelemetryReportingPolicyImpl = {
     return this._logger;
   },
 
   /**
    * Get the date the policy was notified.
    * @return {Object} A date object or null on errors.
    */
   get dataSubmissionPolicyNotifiedDate() {
-    let prefString = Preferences.get(PREF_ACCEPTED_POLICY_DATE, "0");
+    let prefString = Preferences.get(TelemetryUtils.Preferences.AcceptedPolicyDate, "0");
     let valueInteger = parseInt(prefString, 10);
 
     // Bail out if we didn't store any value yet.
     if (valueInteger == 0) {
       this._log.info("get dataSubmissionPolicyNotifiedDate - No date stored yet.");
       return null;
     }
 
@@ -236,61 +218,61 @@ var TelemetryReportingPolicyImpl = {
   set dataSubmissionPolicyNotifiedDate(aDate) {
     this._log.trace("set dataSubmissionPolicyNotifiedDate - aDate: " + aDate);
 
     if (!aDate || aDate.getFullYear() < OLDEST_ALLOWED_ACCEPTANCE_YEAR) {
       this._log.error("set dataSubmissionPolicyNotifiedDate - Invalid notification date.");
       return;
     }
 
-    Preferences.set(PREF_ACCEPTED_POLICY_DATE, aDate.getTime().toString());
+    Preferences.set(TelemetryUtils.Preferences.AcceptedPolicyDate, aDate.getTime().toString());
   },
 
   /**
    * Whether submission of data is allowed.
    *
    * This is the master switch for remote server communication. If it is
    * false, we never request upload or deletion.
    */
   get dataSubmissionEnabled() {
     // Default is true because we are opt-out.
-    return Preferences.get(PREF_DATA_SUBMISSION_ENABLED, true);
+    return Preferences.get(TelemetryUtils.Preferences.DataSubmissionEnabled, true);
   },
 
   get currentPolicyVersion() {
-    return Preferences.get(PREF_CURRENT_POLICY_VERSION,
+    return Preferences.get(TelemetryUtils.Preferences.CurrentPolicyVersion,
                            TelemetryReportingPolicy.DEFAULT_DATAREPORTING_POLICY_VERSION);
   },
 
   /**
    * The minimum policy version which for dataSubmissionPolicyAccepted to
    * to be valid.
    */
   get minimumPolicyVersion() {
-    const minPolicyVersion = Preferences.get(PREF_MINIMUM_POLICY_VERSION, 1);
+    const minPolicyVersion = Preferences.get(TelemetryUtils.Preferences.MinimumPolicyVersion, 1);
 
     // First check if the current channel has a specific minimum policy version. If not,
     // use the general minimum policy version.
     let channel = "";
     try {
       channel = UpdateUtils.getUpdateChannel(false);
     } catch (e) {
       this._log.error("minimumPolicyVersion - Unable to retrieve the current channel.");
       return minPolicyVersion;
     }
-    const channelPref = PREF_MINIMUM_POLICY_VERSION + ".channel-" + channel;
+    const channelPref = TelemetryUtils.Preferences.MinimumPolicyVersion + ".channel-" + channel;
     return Preferences.get(channelPref, minPolicyVersion);
   },
 
   get dataSubmissionPolicyAcceptedVersion() {
-    return Preferences.get(PREF_ACCEPTED_POLICY_VERSION, 0);
+    return Preferences.get(TelemetryUtils.Preferences.AcceptedPolicyVersion, 0);
   },
 
   set dataSubmissionPolicyAcceptedVersion(value) {
-    Preferences.set(PREF_ACCEPTED_POLICY_VERSION, value);
+    Preferences.set(TelemetryUtils.Preferences.AcceptedPolicyVersion, value);
   },
 
   /**
    * Checks to see if the user has been notified about data submission
    * @return {Bool} True if user has been notified and the notification is still valid,
    *         false otherwise.
    */
   get isUserNotifiedOfCurrentPolicy() {
@@ -360,17 +342,17 @@ var TelemetryReportingPolicyImpl = {
     // If data submission is disabled, there's no point in showing the infobar. Just
     // forbid to upload.
     if (!this.dataSubmissionEnabled) {
       return false;
     }
 
     // Submission is enabled. We enable upload if user is notified or we need to bypass
     // the policy.
-    const bypassNotification = Preferences.get(PREF_BYPASS_NOTIFICATION, false);
+    const bypassNotification = Preferences.get(TelemetryUtils.Preferences.BypassNotification, false);
     return this.isUserNotifiedOfCurrentPolicy || bypassNotification;
   },
 
   isFirstRun() {
     return this._isFirstRun;
   },
 
   /**
@@ -387,17 +369,17 @@ var TelemetryReportingPolicyImpl = {
    * Determine whether the user should be notified.
    */
   _shouldNotify() {
     if (!this.dataSubmissionEnabled) {
       this._log.trace("_shouldNotify - Data submission disabled by the policy.");
       return false;
     }
 
-    const bypassNotification = Preferences.get(PREF_BYPASS_NOTIFICATION, false);
+    const bypassNotification = Preferences.get(TelemetryUtils.Preferences.BypassNotification, false);
     if (this.isUserNotifiedOfCurrentPolicy || bypassNotification) {
       this._log.trace("_shouldNotify - User already notified or bypassing the policy.");
       return false;
     }
 
     if (this._notificationInProgress) {
       this._log.trace("_shouldNotify - User not notified, notification already in progress.");
       return false;
@@ -444,17 +426,17 @@ var TelemetryReportingPolicyImpl = {
   /**
    * Try to open the privacy policy in a background tab instead of showing the infobar.
    */
   _openFirstRunPage() {
     if (!this._shouldNotify()) {
       return false;
     }
 
-    let firstRunPolicyURL = Preferences.get(PREF_FIRST_RUN_URL, "");
+    let firstRunPolicyURL = Preferences.get(TelemetryUtils.Preferences.FirsRunURL, "");
     if (!firstRunPolicyURL) {
       return false;
     }
     firstRunPolicyURL = Services.urlFormatter.formatURL(firstRunPolicyURL);
 
     let win;
     try {
       const { RecentWindow } = Cu.import("resource:///modules/RecentWindow.jsm", {});
@@ -503,20 +485,20 @@ var TelemetryReportingPolicyImpl = {
     return true;
   },
 
   observe(aSubject, aTopic, aData) {
     if (aTopic != "sessionstore-windows-restored") {
       return;
     }
 
-    this._isFirstRun = Preferences.get(PREF_FIRST_RUN, true);
+    this._isFirstRun = Preferences.get(TelemetryUtils.Preferences.FirstRun, true);
     if (this._isFirstRun) {
       // We're performing the first run, flip firstRun preference for subsequent runs.
-      Preferences.set(PREF_FIRST_RUN, false);
+      Preferences.set(TelemetryUtils.Preferences.FirstRun, false);
 
       try {
         if (this._openFirstRunPage()) {
           return;
         }
       } catch (e) {
         this._log.error("Failed to open privacy policy tab: " + e);
       }
--- a/toolkit/components/telemetry/TelemetryUtils.jsm
+++ b/toolkit/components/telemetry/TelemetryUtils.jsm
@@ -48,16 +48,17 @@ this.TelemetryUtils = {
     // Data reporting Preferences
     AcceptedPolicyDate: "datareporting.policy.dataSubmissionPolicyNotifiedTime",
     AcceptedPolicyVersion: "datareporting.policy.dataSubmissionPolicyAcceptedVersion",
     BypassNotification: "datareporting.policy.dataSubmissionPolicyBypassNotification",
     CurrentPolicyVersion: "datareporting.policy.currentPolicyVersion",
     DataSubmissionEnabled: "datareporting.policy.dataSubmissionEnabled",
     FhrUploadEnabled: "datareporting.healthreport.uploadEnabled",
     MinimumPolicyVersion: "datareporting.policy.minimumPolicyVersion",
+    FirstRunURL: "datareporting.policy.firstRunURL",
   }),
 
   /**
    * True if this is a content process.
    */
   get isContentProcess() {
     return IS_CONTENT_PROCESS;
   },