diff options
author | imcheng <imcheng@chromium.org> | 2016-02-10 18:06:53 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-02-11 02:09:24 +0000 |
commit | 7c91fae3f88773af47a79f4a3bceaccfa1b27ea5 (patch) | |
tree | 89f4dbfa44555dc5a6d2a6ba327ca313084e3b61 /extensions/common | |
parent | 338a3bb9656e66896c4b28dc08a24c28579ee5f5 (diff) | |
download | chromium_src-7c91fae3f88773af47a79f4a3bceaccfa1b27ea5.zip chromium_src-7c91fae3f88773af47a79f4a3bceaccfa1b27ea5.tar.gz chromium_src-7c91fae3f88773af47a79f4a3bceaccfa1b27ea5.tar.bz2 |
[Feature Switch][Media Router] Add required field trials to MR switch.
Add a generic required_field_trials to FeatureSwitch that takes the
place of a singular field_trial_name. When deciding whether to enable or
disable a feature with field trials, all field trials will be queried
(though short circuiting can occur):
- If user is in "Enabled" group for all field trials, then enable
feature.
- If user is in "Disabled group for any field trials, then disable
feature.
- Otherwise, fall back to default value.
Change the MR FeatureSwitches to depend on the EAR field trial. Per
discussion, we will change the interpretation of MR field trial to
be "X% of users that have EAR field trial enabled".
BUG=541315
Review URL: https://codereview.chromium.org/1680823004
Cr-Commit-Position: refs/heads/master@{#374834}
Diffstat (limited to 'extensions/common')
-rw-r--r-- | extensions/common/feature_switch.cc | 85 | ||||
-rw-r--r-- | extensions/common/feature_switch.h | 15 |
2 files changed, 77 insertions, 23 deletions
diff --git a/extensions/common/feature_switch.cc b/extensions/common/feature_switch.cc index d8c6b98..ca73db0 100644 --- a/extensions/common/feature_switch.cc +++ b/extensions/common/feature_switch.cc @@ -15,11 +15,21 @@ namespace extensions { namespace { +// The switch media-router is defined in chrome/common/chrome_switches.cc, but +// we can't depend on chrome here. +const char kMediaRouterFlag[] = "media-router"; + const char kEnableMediaRouterExperiment[] = "EnableMediaRouter"; const char kEnableMediaRouterWithCastExtensionExperiment[] = "EnableMediaRouterWithCastExtension"; const char kExtensionActionRedesignExperiment[] = "ExtensionActionRedesign"; +const char* kMediaRouterRequiredExperiments[] = { + kEnableMediaRouterExperiment, kExtensionActionRedesignExperiment}; +const char* kMediaRouterWithCastExtensionRequiredExperiments[] = { + kEnableMediaRouterWithCastExtensionExperiment, + kExtensionActionRedesignExperiment}; + class CommonSwitches { public: CommonSwitches() @@ -51,14 +61,19 @@ class CommonSwitches { FeatureSwitch::DEFAULT_DISABLED), trace_app_source(switches::kTraceAppSource, FeatureSwitch::DEFAULT_ENABLED), - // The switch media-router is defined in - // chrome/common/chrome_switches.cc, but we can't depend on chrome here. - media_router("media-router", - kEnableMediaRouterExperiment, + media_router(kMediaRouterFlag, + std::vector<std::string>( + kMediaRouterRequiredExperiments, + kMediaRouterRequiredExperiments + + arraysize(kMediaRouterRequiredExperiments)), FeatureSwitch::DEFAULT_DISABLED), media_router_with_cast_extension( - "media-router", - kEnableMediaRouterWithCastExtensionExperiment, + kMediaRouterFlag, + std::vector<std::string>( + kMediaRouterWithCastExtensionRequiredExperiments, + kMediaRouterWithCastExtensionRequiredExperiments + + arraysize( + kMediaRouterWithCastExtensionRequiredExperiments)), FeatureSwitch::DEFAULT_DISABLED) { } @@ -107,6 +122,9 @@ FeatureSwitch* FeatureSwitch::extension_action_redesign() { // Force-enable the redesigned extension action toolbar when the Media Router // is enabled. Should be removed when the toolbar redesign is used by default. // See crbug.com/514694 + // Note that if Media Router is enabled by experiment, it implies that the + // extension action redesign is also enabled by experiment. Thus it is fine + // to return the override switch. // TODO(kmarshall): Remove this override. if (media_router()->IsEnabled()) return &g_common_switches.Get().extension_action_redesign_override; @@ -152,24 +170,39 @@ FeatureSwitch::FeatureSwitch(const char* switch_name, DefaultValue default_value) : FeatureSwitch(base::CommandLine::ForCurrentProcess(), switch_name, - field_trial_name, + std::vector<std::string>(1, field_trial_name), default_value) {} -FeatureSwitch::FeatureSwitch(const base::CommandLine* command_line, - const char* switch_name, - DefaultValue default_value) - : FeatureSwitch(command_line, switch_name, nullptr, default_value) {} +FeatureSwitch::FeatureSwitch( + const char* switch_name, + const std::vector<std::string>& required_field_trials, + DefaultValue default_value) + : FeatureSwitch(base::CommandLine::ForCurrentProcess(), + switch_name, + required_field_trials, + default_value) {} FeatureSwitch::FeatureSwitch(const base::CommandLine* command_line, const char* switch_name, - const char* field_trial_name, DefaultValue default_value) + : FeatureSwitch(command_line, + switch_name, + std::vector<std::string>(), + default_value) {} + +FeatureSwitch::FeatureSwitch( + const base::CommandLine* command_line, + const char* switch_name, + const std::vector<std::string>& required_field_trials, + DefaultValue default_value) : command_line_(command_line), switch_name_(switch_name), - field_trial_name_(field_trial_name), + required_field_trials_(required_field_trials), default_value_(default_value == DEFAULT_ENABLED), override_value_(OVERRIDE_NONE) {} +FeatureSwitch::~FeatureSwitch(){}; + bool FeatureSwitch::IsEnabled() const { if (override_value_ != OVERRIDE_NONE) return override_value_ == OVERRIDE_ENABLED; @@ -187,19 +220,33 @@ bool FeatureSwitch::IsEnabled() const { if (switch_value == "0") return false; + // TODO(imcheng): Don't check |default_value_|. Otherwise, we could improperly + // ignore an enable/disable switch if there is a field trial active. + // crbug.com/585569 if (!default_value_ && command_line_->HasSwitch(GetLegacyEnableFlag())) return true; if (default_value_ && command_line_->HasSwitch(GetLegacyDisableFlag())) return false; - if (field_trial_name_) { - std::string group_name = - base::FieldTrialList::FindFullName(field_trial_name_); - if (group_name == "Enabled") - return true; - if (group_name == "Disabled") + if (!required_field_trials_.empty()) { + bool enabled_by_field_trial = true; + bool disabled_by_field_trial = false; + for (const std::string& field_trial_name : required_field_trials_) { + std::string group_name = + base::FieldTrialList::FindFullName(field_trial_name); + if (group_name != "Enabled") { + enabled_by_field_trial = false; + if (group_name == "Disabled") { + disabled_by_field_trial = true; + break; + } + } + } + if (disabled_by_field_trial) return false; + if (enabled_by_field_trial) + return true; } return default_value_; diff --git a/extensions/common/feature_switch.h b/extensions/common/feature_switch.h index c170f9c..b39cc8c 100644 --- a/extensions/common/feature_switch.h +++ b/extensions/common/feature_switch.h @@ -6,6 +6,7 @@ #define EXTENSIONS_COMMON_FEATURE_SWITCH_H_ #include <string> +#include <vector> #include "base/macros.h" @@ -26,8 +27,10 @@ namespace extensions { // the finch config). // 3. If there is a switch name, and the switch is present in the command line, // the command line value will be used. -// 4. If there is a finch experiment associated and applicable to the machine, -// the finch value will be used. +// 4. If there are field trials associated with the feature, and the machine +// is in the "Enabled" group for all field trials, then the feature is +// enabled. If the machine is in the "Disabled" group for any field trials, +// the feature is disabled. // 5. Otherwise, the default value is used. class FeatureSwitch { public: @@ -72,13 +75,17 @@ class FeatureSwitch { FeatureSwitch(const char* switch_name, const char* field_trial_name, DefaultValue default_value); + FeatureSwitch(const char* switch_name, + const std::vector<std::string>& required_field_trials, + DefaultValue default_value); FeatureSwitch(const base::CommandLine* command_line, const char* switch_name, DefaultValue default_value); FeatureSwitch(const base::CommandLine* command_line, const char* switch_name, - const char* field_trial_name, + const std::vector<std::string>& required_field_trials, DefaultValue default_value); + ~FeatureSwitch(); // Consider using ScopedOverride instead. void SetOverrideValue(OverrideValue value); @@ -92,7 +99,7 @@ class FeatureSwitch { const base::CommandLine* command_line_; const char* switch_name_; - const char* field_trial_name_; + std::vector<std::string> required_field_trials_; bool default_value_; OverrideValue override_value_; |