Bug 1268921 - Allow non-integer values to be specified for e10srollout cohort samples. r=mconley
MozReview-Commit-ID: Jgk3RRqgMUm
--- a/browser/extensions/e10srollout/bootstrap.js
+++ b/browser/extensions/e10srollout/bootstrap.js
@@ -4,20 +4,19 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/UpdateUtils.jsm");
- // The amount of people to be part of e10s, in %
+ // The amount of people to be part of e10s
const TEST_THRESHOLD = {
- "beta" : 50,
- "release" : 0,
+ "beta" : 0.5, // 50%
};
const PREF_COHORT_SAMPLE = "e10s.rollout.cohortSample";
const PREF_COHORT_NAME = "e10s.rollout.cohort";
const PREF_E10S_OPTED_IN = "browser.tabs.remote.autostart";
const PREF_E10S_FORCE_ENABLED = "browser.tabs.remote.force-enable";
const PREF_E10S_FORCE_DISABLED = "browser.tabs.remote.force-disable";
const PREF_TOGGLE_E10S = "browser.tabs.remote.autostart.2";
@@ -74,24 +73,33 @@ function defineCohort() {
function shutdown(data, reason) {
}
function uninstall() {
}
function getUserSample() {
- let existingVal = Preferences.get(PREF_COHORT_SAMPLE, undefined);
- if (typeof(existingVal) == "number") {
- return existingVal;
+ let prefValue = Preferences.get(PREF_COHORT_SAMPLE, undefined);
+ let value = 0.0;
+
+ if (typeof(prefValue) == "string") {
+ value = parseFloat(prefValue, 10);
+ return value;
}
- let val = Math.floor(Math.random() * 100);
- Preferences.set(PREF_COHORT_SAMPLE, val);
- return val;
+ if (typeof(prefValue) == "number") {
+ // convert old integer value
+ value = prefValue / 100;
+ } else {
+ value = Math.random();
+ }
+
+ Preferences.set(PREF_COHORT_SAMPLE, val.toString().substr(0, 8));
+ return value;
}
function setCohort(cohortName) {
Preferences.set(PREF_COHORT_NAME, cohortName);
try {
if (Ci.nsICrashReporter) {
Services.appinfo.QueryInterface(Ci.nsICrashReporter).annotateCrashReport("E10SCohort", cohortName);
}