Skip to content
Snippets Groups Projects
Commit 60c221fa authored by Alex Thayer's avatar Alex Thayer
Browse files

Bug 1385396 - Cache early setExperimentActive calls r=gfritzsche

Calling setExperimentActive too early during startup can change
the order of some initialization. setExperimentActive probably
shouldn't have this kind of effect, so simply cache early calls
to it until gGlobalEnvironment has been initialized through other
functions.

Additionally, I am speculatively including work to ensure that
setExperimentInactive and getActiveExperiments have the same
behavior, while remaining correct by working from the same cache
that setExperimentActive uses.

MozReview-Commit-ID: IlzT1J0o6gK

--HG--
extra : rebase_source : b39b8d7e7b0970b520ce3f63af9750846d08b0eb
parent fbf0accf
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,11 @@ var Policy = {
now: () => new Date(),
};
// This is used to buffer calls to setExperimentActive and friends, so that we
// don't prematurely initialize our environment if it is called early during
// startup.
var gActiveExperimentStartupBuffer = new Map();
var gGlobalEnvironment;
function getGlobal() {
if (!gGlobalEnvironment) {
......@@ -92,7 +97,11 @@ this.TelemetryEnvironment = {
* @param {String} [options.type=false] The specific experiment type.
*/
setExperimentActive(id, branch, options = {}) {
return getGlobal().setExperimentActive(id, branch, options);
if (gGlobalEnvironment) {
gGlobalEnvironment.setExperimentActive(id, branch, options);
} else {
gActiveExperimentStartupBuffer.set(id, {branch, options});
}
},
/**
......@@ -102,7 +111,11 @@ this.TelemetryEnvironment = {
* @param {String} id The id of the active experiment.
*/
setExperimentInactive(id) {
return getGlobal().setExperimentInactive(id);
if (gGlobalEnvironment) {
gGlobalEnvironment.setExperimentInactive(id);
} else {
gActiveExperimentStartupBuffer.delete(id);
}
},
/**
......@@ -116,7 +129,15 @@ this.TelemetryEnvironment = {
* }
*/
getActiveExperiments() {
return getGlobal().getActiveExperiments();
if (gGlobalEnvironment) {
return gGlobalEnvironment.getActiveExperiments();
}
const result = {};
for (const [id, {branch}] of gActiveExperimentStartupBuffer.entries()) {
result[id] = branch;
}
return result;
},
shutdown() {
......@@ -151,6 +172,7 @@ this.TelemetryEnvironment = {
testCleanRestart() {
getGlobal().shutdown();
gGlobalEnvironment = null;
gActiveExperimentStartupBuffer = new Map();
return getGlobal();
},
};
......@@ -847,6 +869,11 @@ function EnvironmentCache() {
p.push(this._updateAttribution());
}
for (const [id, {branch, options}] of gActiveExperimentStartupBuffer.entries()) {
this.setExperimentActive(id, branch, options);
}
gActiveExperimentStartupBuffer = null;
let setup = () => {
this._initTask = null;
this._startWatchingPrefs();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment