Bug 1268921 - Allow non-integer values to be specified for e10srollout cohort samples. r=mconley draft
authorFelipe Gomes <felipc@gmail.com>
Fri, 29 Apr 2016 16:42:20 -0300
changeset 357881 0d4a90387c44d50daf3d94d676089a2a66addb18
parent 357771 8c3fd523d75bd30f691ca2d6cfdad18d576392a1
child 519732 e2fcc8d52d936ad9ff972c7fd8b1241ed0d2b4f8
push id16878
push userfelipc@gmail.com
push dateFri, 29 Apr 2016 19:47:33 +0000
reviewersmconley
bugs1268921
milestone49.0a1
Bug 1268921 - Allow non-integer values to be specified for e10srollout cohort samples. r=mconley MozReview-Commit-ID: Jgk3RRqgMUm
browser/extensions/e10srollout/bootstrap.js
--- 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);
     }