Skip to content

Commit

Permalink
Bug 981689 - Show a notice to beta users when we turn telemetry on by…
Browse files Browse the repository at this point in the history
… default on the beta channel - Firefox Desktop
  • Loading branch information
Asaf Romano committed Apr 7, 2014
1 parent c7798ee commit 2d976c2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
3 changes: 3 additions & 0 deletions services/datareporting/datareporting-prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

31 changes: 25 additions & 6 deletions services/datareporting/policy.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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.
*
Expand Down Expand Up @@ -494,22 +497,39 @@ 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.
*
* This overrides dataSubmissionEnabled.
*/
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");
},

/**
Expand Down Expand Up @@ -684,7 +704,6 @@ this.DataReportingPolicy.prototype = Object.freeze({
this.dataSubmissionPolicyResponseDate = this.now();
this.dataSubmissionPolicyResponseType = "accepted-" + reason;
this.dataSubmissionPolicyAccepted = true;
this.dataSubmissionPolicyAcceptedVersion = 1;
},

/**
Expand Down
5 changes: 1 addition & 4 deletions services/datareporting/tests/xpcshell/test_policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 2d976c2

Please sign in to comment.