Chromium Code Reviews| Index: extensions/common/feature_switch.cc |
| diff --git a/extensions/common/feature_switch.cc b/extensions/common/feature_switch.cc |
| index d8c6b98e5ddecbc56ca176c8cb6e657c82964a46..d66458578d70bcf958d774470abd698943586a0c 100644 |
| --- a/extensions/common/feature_switch.cc |
| +++ b/extensions/common/feature_switch.cc |
| @@ -15,11 +15,18 @@ 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* kEnableMediaRouterExperimentDependencies[] = { |
| + kExtensionActionRedesignExperiment}; |
| + |
| class CommonSwitches { |
| public: |
| CommonSwitches() |
| @@ -51,14 +58,21 @@ 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, |
| - FeatureSwitch::DEFAULT_DISABLED), |
| + media_router( |
| + kMediaRouterFlag, |
| + kEnableMediaRouterExperiment, |
| + std::vector<const char*>( |
| + kEnableMediaRouterExperimentDependencies, |
| + kEnableMediaRouterExperimentDependencies + |
| + arraysize(kEnableMediaRouterExperimentDependencies)), |
| + FeatureSwitch::DEFAULT_DISABLED), |
| media_router_with_cast_extension( |
| - "media-router", |
| + kMediaRouterFlag, |
| kEnableMediaRouterWithCastExtensionExperiment, |
| + std::vector<const char*>( |
| + kEnableMediaRouterExperimentDependencies, |
| + kEnableMediaRouterExperimentDependencies + |
| + arraysize(kEnableMediaRouterExperimentDependencies)), |
| FeatureSwitch::DEFAULT_DISABLED) { |
| } |
| @@ -86,6 +100,14 @@ class CommonSwitches { |
| base::LazyInstance<CommonSwitches> g_common_switches = |
| LAZY_INSTANCE_INITIALIZER; |
| +std::string GetSwitchValue(const base::CommandLine* command_line, |
| + const std::string& switch_name) { |
| + std::string temp = command_line->GetSwitchValueASCII(switch_name); |
| + std::string switch_value; |
| + base::TrimWhitespaceASCII(temp, base::TRIM_ALL, &switch_value); |
| + return switch_value; |
| +} |
| + |
| } // namespace |
| FeatureSwitch* FeatureSwitch::force_dev_mode_highlighting() { |
| @@ -108,7 +130,8 @@ FeatureSwitch* FeatureSwitch::extension_action_redesign() { |
| // is enabled. Should be removed when the toolbar redesign is used by default. |
| // See crbug.com/514694 |
| // TODO(kmarshall): Remove this override. |
| - if (media_router()->IsEnabled()) |
| + if (GetSwitchValue(base::CommandLine::ForCurrentProcess(), |
| + kMediaRouterFlag) == "1") |
|
Devlin
2016/02/09 18:45:14
This doesn't account for the case of, e.g., --enab
imcheng
2016/02/09 21:35:39
Checking media_router() isn't correct for users wi
Devlin
2016/02/10 18:08:33
So we need to check media_router() for most users
|
| return &g_common_switches.Get().extension_action_redesign_override; |
| return &g_common_switches.Get().extension_action_redesign; |
| @@ -153,23 +176,44 @@ FeatureSwitch::FeatureSwitch(const char* switch_name, |
| : FeatureSwitch(base::CommandLine::ForCurrentProcess(), |
| switch_name, |
| field_trial_name, |
| + std::vector<const char*>(), |
| 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 char* field_trial_name, |
|
Devlin
2016/02/09 18:45:14
Could we instead just always take a vector of requ
imcheng
2016/02/09 21:35:39
I think it depends on how you interpret the requir
|
| + const std::vector<const char*>& dependent_field_trials, |
| + DefaultValue default_value) |
| + : FeatureSwitch(base::CommandLine::ForCurrentProcess(), |
| + switch_name, |
| + field_trial_name, |
| + dependent_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, |
| + nullptr, |
| + std::vector<const char*>(), |
| + default_value) {} |
| + |
| +FeatureSwitch::FeatureSwitch( |
| + const base::CommandLine* command_line, |
| + const char* switch_name, |
| + const char* field_trial_name, |
| + const std::vector<const char*>& dependent_field_trials, |
| + DefaultValue default_value) |
| : command_line_(command_line), |
| switch_name_(switch_name), |
| field_trial_name_(field_trial_name), |
| + dependent_field_trials_(dependent_field_trials), |
| default_value_(default_value == DEFAULT_ENABLED), |
| override_value_(OVERRIDE_NONE) {} |
| +FeatureSwitch::~FeatureSwitch() = default; |
|
Devlin
2016/02/09 18:45:14
we don't really use this style anywhere else that
imcheng
2016/02/09 21:35:39
Done.
|
| + |
| bool FeatureSwitch::IsEnabled() const { |
| if (override_value_ != OVERRIDE_NONE) |
| return override_value_ == OVERRIDE_ENABLED; |
| @@ -177,10 +221,7 @@ bool FeatureSwitch::IsEnabled() const { |
| if (!switch_name_) |
| return default_value_; |
| - std::string temp = command_line_->GetSwitchValueASCII(switch_name_); |
| - std::string switch_value; |
| - base::TrimWhitespaceASCII(temp, base::TRIM_ALL, &switch_value); |
| - |
| + std::string switch_value = GetSwitchValue(command_line_, switch_name_); |
| if (switch_value == "1") |
| return true; |
| @@ -196,7 +237,7 @@ bool FeatureSwitch::IsEnabled() const { |
| if (field_trial_name_) { |
| std::string group_name = |
| base::FieldTrialList::FindFullName(field_trial_name_); |
| - if (group_name == "Enabled") |
| + if (group_name == "Enabled" && DependentFieldTrialsEnabled()) |
| return true; |
| if (group_name == "Disabled") |
| return false; |
| @@ -215,6 +256,16 @@ std::string FeatureSwitch::GetLegacyDisableFlag() const { |
| return std::string("disable-") + switch_name_; |
| } |
| +bool FeatureSwitch::DependentFieldTrialsEnabled() const { |
| + for (const std::string& dependent_field_trial : dependent_field_trials_) { |
| + std::string group_name = |
| + base::FieldTrialList::FindFullName(dependent_field_trial); |
| + if (group_name != "Enabled") |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| void FeatureSwitch::SetOverrideValue(OverrideValue override_value) { |
| override_value_ = override_value; |
| } |