1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 * Class for enabling experimental features.
12 /** @suppress {duplicate} */
13 var remoting = remoting || {};
17 var kExperimentsStorageName = 'remoting-experiments';
18 var ACTIVE_FIELD_TRIALS = {'ChromotingQUIC': 'quic', 'ChromotingVP9': 'vp9'};
21 * @param {Array.<string>} list
25 storageMap[kExperimentsStorageName] = list;
26 chrome.storage.local.set(storageMap);
30 remoting.experiments = {};
33 * Enables an experiment.
35 * @param {string} experiment to enable.
37 remoting.experiments.enable = function(experiment) {
38 remoting.experiments.get().then(function(/** Array.<string> */list) {
39 if (list.indexOf(experiment) == -1) {
40 list.push(experiment);
47 * Disables an experiment.
49 * @param {string} experiment to disable.
51 remoting.experiments.disable = function(experiment) {
52 remoting.experiments.get().then(function(/** Array.<string> */list) {
53 list = list.filter(function(e) { return e !== experiment; });
59 * Determines if the field-trial is enabled for this session.
61 * @param {string} trialName The FieldTrial to check for enabling.
64 function getTrialState(trialName) {
65 var deferred = new base.Deferred();
66 chrome.metricsPrivate.getFieldTrial(trialName,
67 function(/** string */ group) {
68 if (group == 'Enabled') {
69 deferred.resolve(true);
71 deferred.resolve(false);
74 return deferred.promise();
78 * Returns list of all enabled experiments.
81 remoting.experiments.get = function() {
83 var localStorageList = new Promise(function(resolve, reject) {
84 chrome.storage.local.get(kExperimentsStorageName, function(items) {
85 /** @type {Array<string>} */
86 var experiments = new Array();
87 if (items.hasOwnProperty(kExperimentsStorageName)) {
88 experiments = /** @type {Array<string>} */
89 (items[kExperimentsStorageName]);
95 var trialNames = Object.keys(ACTIVE_FIELD_TRIALS);
97 return Promise.all([localStorageList].concat(
98 trialNames.map(function(/** string */ trialName) {
99 return getTrialState(trialName);
101 .then(function(results) {
102 /** @type {Array<string>} */
103 var list = results[0];
104 for (var i = 0; i < trialNames.length; ++i) {
105 if (results[i + 1]) {
106 list.push(ACTIVE_FIELD_TRIALS[trialNames[i]]);