From 2d976c2a3e636ac7d6f256ed56fdc1382e84639f Mon Sep 17 00:00:00 2001 From: Asaf Romano Date: Mon, 7 Apr 2014 12:26:58 +0300 Subject: [PATCH] Bug 981689 - Show a notice to beta users when we turn telemetry on by default on the beta channel - Firefox Desktop --- services/datareporting/datareporting-prefs.js | 3 ++ services/datareporting/policy.jsm | 31 +++++++++++++++---- .../tests/xpcshell/test_policy.js | 5 +-- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/services/datareporting/datareporting-prefs.js b/services/datareporting/datareporting-prefs.js index 11d6a564fbaba..5bbecdc36078d 100644 --- a/services/datareporting/datareporting-prefs.js +++ b/services/datareporting/datareporting-prefs.js @@ -10,3 +10,6 @@ pref("datareporting.policy.dataSubmissionPolicyResponseType", ""); pref("datareporting.policy.dataSubmissionPolicyResponseTime", "0"); pref("datareporting.policy.firstRunTime", "0"); +pref("datareporting.policy.minimumPolicyVersion", 1); +pref("datareporting.policy.minimumPolicyVersion.channel-beta", 2); + diff --git a/services/datareporting/policy.jsm b/services/datareporting/policy.jsm index 3faedf74d50dd..0551fc0f1f08d 100644 --- a/services/datareporting/policy.jsm +++ b/services/datareporting/policy.jsm @@ -26,6 +26,7 @@ const {classes: Cc, interfaces: Ci, utils: Cu} = Components; #endif +Cu.import("resource://gre/modules/Services.jsm"); Cu.import("resource://gre/modules/Promise.jsm"); Cu.import("resource://gre/modules/Log.jsm"); Cu.import("resource://services-common/utils.js"); @@ -36,6 +37,8 @@ const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000; // implemented in 2012, so any earlier dates indicate an incorrect clock. const OLDEST_ALLOWED_YEAR = 2012; +const CURRENT_POLICY_VERSION = 2; + /** * Represents a request to display data policy. * @@ -494,6 +497,18 @@ this.DataReportingPolicy.prototype = Object.freeze({ this._prefs.set("dataSubmissionEnabled", !!value); }, + /** + * The minimum policy version which for dataSubmissionPolicyAccepted to + * to be valid. + */ + get minimumPolicyVersion() { + // First check if the current channel has an ove + let channel = Services.appinfo.defaultUpdateChannel; + let channelPref = this._prefs.get("minimumPolicyVersion.channel-" + channel); + return channelPref !== undefined ? + channelPref : this._prefs.get("minimumPolicyVersion", 1); + }, + /** * Whether the user has accepted that data submission can occur. * @@ -501,15 +516,20 @@ this.DataReportingPolicy.prototype = Object.freeze({ */ get dataSubmissionPolicyAccepted() { // Be conservative and default to false. - return this._prefs.get("dataSubmissionPolicyAccepted", false); + let enabled = this._prefs.get("dataSubmissionPolicyAccepted", false); + if (!enabled) + return false; + + let acceptedVersion = this._prefs.get("dataSubmissionPolicyAcceptedVersion"); + return acceptedVersion >= this.minimumPolicyVersion; }, set dataSubmissionPolicyAccepted(value) { this._prefs.set("dataSubmissionPolicyAccepted", !!value); - }, - - set dataSubmissionPolicyAcceptedVersion(value) { - this._prefs.set("dataSubmissionPolicyAcceptedVersion", value); + if (!!value) + this._prefs.set("dataSubmissionPolicyAcceptedVersion", CURRENT_POLICY_VERSION); + else + this._prefs.reset("dataSubmissionPolicyAcceptedVersion"); }, /** @@ -684,7 +704,6 @@ this.DataReportingPolicy.prototype = Object.freeze({ this.dataSubmissionPolicyResponseDate = this.now(); this.dataSubmissionPolicyResponseType = "accepted-" + reason; this.dataSubmissionPolicyAccepted = true; - this.dataSubmissionPolicyAcceptedVersion = 1; }, /** diff --git a/services/datareporting/tests/xpcshell/test_policy.js b/services/datareporting/tests/xpcshell/test_policy.js index 297fbcd728b7e..54af74beb0e3e 100644 --- a/services/datareporting/tests/xpcshell/test_policy.js +++ b/services/datareporting/tests/xpcshell/test_policy.js @@ -85,9 +85,6 @@ add_test(function test_prefs() { do_check_false(policyPrefs.get("dataSubmissionPolicyAccepted", true)); do_check_false(policy.dataSubmissionPolicyAccepted); - policy.dataSubmissionPolicyAcceptedVersion = 2; - do_check_eq(policyPrefs.get("dataSubmissionPolicyAcceptedVersion"), 2); - do_check_false(policy.dataSubmissionPolicyBypassAcceptance); policyPrefs.set("dataSubmissionPolicyBypassAcceptance", true); do_check_true(policy.dataSubmissionPolicyBypassAcceptance); @@ -274,7 +271,7 @@ add_test(function test_submission_kill_switch() { policy.firstRunDate = new Date(Date.now() - 3 * 24 * 60 * 60 * 1000); policy.nextDataSubmissionDate = new Date(Date.now() - 24 * 60 * 60 * 1000); policy.recordUserAcceptance("accept-old-ack"); - do_check_eq(policyPrefs.get("dataSubmissionPolicyAcceptedVersion"), 1); + do_check_true(policyPrefs.has("dataSubmissionPolicyAcceptedVersion")); policy.checkStateAndTrigger(); do_check_eq(listener.requestDataUploadCount, 1);