Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "extensions/common/feature_switch.h" | 5 #include "extensions/common/feature_switch.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/metrics/field_trial.h" | 9 #include "base/metrics/field_trial.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "extensions/common/switches.h" | 12 #include "extensions/common/switches.h" |
| 13 | 13 |
| 14 namespace extensions { | 14 namespace extensions { |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 // The switch media-router is defined in chrome/common/chrome_switches.cc, but | |
| 19 // we can't depend on chrome here. | |
| 20 const char kMediaRouterFlag[] = "media-router"; | |
| 21 | |
| 18 const char kEnableMediaRouterExperiment[] = "EnableMediaRouter"; | 22 const char kEnableMediaRouterExperiment[] = "EnableMediaRouter"; |
| 19 const char kEnableMediaRouterWithCastExtensionExperiment[] = | 23 const char kEnableMediaRouterWithCastExtensionExperiment[] = |
| 20 "EnableMediaRouterWithCastExtension"; | 24 "EnableMediaRouterWithCastExtension"; |
| 21 const char kExtensionActionRedesignExperiment[] = "ExtensionActionRedesign"; | 25 const char kExtensionActionRedesignExperiment[] = "ExtensionActionRedesign"; |
| 22 | 26 |
| 27 const char* kEnableMediaRouterExperimentDependencies[] = { | |
| 28 kExtensionActionRedesignExperiment}; | |
| 29 | |
| 23 class CommonSwitches { | 30 class CommonSwitches { |
| 24 public: | 31 public: |
| 25 CommonSwitches() | 32 CommonSwitches() |
| 26 : easy_off_store_install(nullptr, FeatureSwitch::DEFAULT_DISABLED), | 33 : easy_off_store_install(nullptr, FeatureSwitch::DEFAULT_DISABLED), |
| 27 force_dev_mode_highlighting(switches::kForceDevModeHighlighting, | 34 force_dev_mode_highlighting(switches::kForceDevModeHighlighting, |
| 28 FeatureSwitch::DEFAULT_DISABLED), | 35 FeatureSwitch::DEFAULT_DISABLED), |
| 29 prompt_for_external_extensions( | 36 prompt_for_external_extensions( |
| 30 #if defined(CHROMIUM_BUILD) | 37 #if defined(CHROMIUM_BUILD) |
| 31 switches::kPromptForExternalExtensions, | 38 switches::kPromptForExternalExtensions, |
| 32 #else | 39 #else |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 44 kExtensionActionRedesignExperiment, | 51 kExtensionActionRedesignExperiment, |
| 45 FeatureSwitch::DEFAULT_DISABLED), | 52 FeatureSwitch::DEFAULT_DISABLED), |
| 46 extension_action_redesign_override(switches::kExtensionActionRedesign, | 53 extension_action_redesign_override(switches::kExtensionActionRedesign, |
| 47 FeatureSwitch::DEFAULT_ENABLED), | 54 FeatureSwitch::DEFAULT_ENABLED), |
| 48 scripts_require_action(switches::kScriptsRequireAction, | 55 scripts_require_action(switches::kScriptsRequireAction, |
| 49 FeatureSwitch::DEFAULT_DISABLED), | 56 FeatureSwitch::DEFAULT_DISABLED), |
| 50 embedded_extension_options(switches::kEmbeddedExtensionOptions, | 57 embedded_extension_options(switches::kEmbeddedExtensionOptions, |
| 51 FeatureSwitch::DEFAULT_DISABLED), | 58 FeatureSwitch::DEFAULT_DISABLED), |
| 52 trace_app_source(switches::kTraceAppSource, | 59 trace_app_source(switches::kTraceAppSource, |
| 53 FeatureSwitch::DEFAULT_ENABLED), | 60 FeatureSwitch::DEFAULT_ENABLED), |
| 54 // The switch media-router is defined in | 61 media_router( |
| 55 // chrome/common/chrome_switches.cc, but we can't depend on chrome here. | 62 kMediaRouterFlag, |
| 56 media_router("media-router", | 63 kEnableMediaRouterExperiment, |
| 57 kEnableMediaRouterExperiment, | 64 std::vector<const char*>( |
| 58 FeatureSwitch::DEFAULT_DISABLED), | 65 kEnableMediaRouterExperimentDependencies, |
| 66 kEnableMediaRouterExperimentDependencies + | |
| 67 arraysize(kEnableMediaRouterExperimentDependencies)), | |
| 68 FeatureSwitch::DEFAULT_DISABLED), | |
| 59 media_router_with_cast_extension( | 69 media_router_with_cast_extension( |
| 60 "media-router", | 70 kMediaRouterFlag, |
| 61 kEnableMediaRouterWithCastExtensionExperiment, | 71 kEnableMediaRouterWithCastExtensionExperiment, |
| 72 std::vector<const char*>( | |
| 73 kEnableMediaRouterExperimentDependencies, | |
| 74 kEnableMediaRouterExperimentDependencies + | |
| 75 arraysize(kEnableMediaRouterExperimentDependencies)), | |
| 62 FeatureSwitch::DEFAULT_DISABLED) { | 76 FeatureSwitch::DEFAULT_DISABLED) { |
| 63 } | 77 } |
| 64 | 78 |
| 65 // Enables extensions to be easily installed from sites other than the web | 79 // Enables extensions to be easily installed from sites other than the web |
| 66 // store. | 80 // store. |
| 67 FeatureSwitch easy_off_store_install; | 81 FeatureSwitch easy_off_store_install; |
| 68 | 82 |
| 69 FeatureSwitch force_dev_mode_highlighting; | 83 FeatureSwitch force_dev_mode_highlighting; |
| 70 | 84 |
| 71 // Should we prompt the user before allowing external extensions to install? | 85 // Should we prompt the user before allowing external extensions to install? |
| 72 // Default is yes. | 86 // Default is yes. |
| 73 FeatureSwitch prompt_for_external_extensions; | 87 FeatureSwitch prompt_for_external_extensions; |
| 74 | 88 |
| 75 FeatureSwitch error_console; | 89 FeatureSwitch error_console; |
| 76 FeatureSwitch enable_override_bookmarks_ui; | 90 FeatureSwitch enable_override_bookmarks_ui; |
| 77 FeatureSwitch extension_action_redesign; | 91 FeatureSwitch extension_action_redesign; |
| 78 FeatureSwitch extension_action_redesign_override; | 92 FeatureSwitch extension_action_redesign_override; |
| 79 FeatureSwitch scripts_require_action; | 93 FeatureSwitch scripts_require_action; |
| 80 FeatureSwitch embedded_extension_options; | 94 FeatureSwitch embedded_extension_options; |
| 81 FeatureSwitch trace_app_source; | 95 FeatureSwitch trace_app_source; |
| 82 FeatureSwitch media_router; | 96 FeatureSwitch media_router; |
| 83 FeatureSwitch media_router_with_cast_extension; | 97 FeatureSwitch media_router_with_cast_extension; |
| 84 }; | 98 }; |
| 85 | 99 |
| 86 base::LazyInstance<CommonSwitches> g_common_switches = | 100 base::LazyInstance<CommonSwitches> g_common_switches = |
| 87 LAZY_INSTANCE_INITIALIZER; | 101 LAZY_INSTANCE_INITIALIZER; |
| 88 | 102 |
| 103 std::string GetSwitchValue(const base::CommandLine* command_line, | |
| 104 const std::string& switch_name) { | |
| 105 std::string temp = command_line->GetSwitchValueASCII(switch_name); | |
| 106 std::string switch_value; | |
| 107 base::TrimWhitespaceASCII(temp, base::TRIM_ALL, &switch_value); | |
| 108 return switch_value; | |
| 109 } | |
| 110 | |
| 89 } // namespace | 111 } // namespace |
| 90 | 112 |
| 91 FeatureSwitch* FeatureSwitch::force_dev_mode_highlighting() { | 113 FeatureSwitch* FeatureSwitch::force_dev_mode_highlighting() { |
| 92 return &g_common_switches.Get().force_dev_mode_highlighting; | 114 return &g_common_switches.Get().force_dev_mode_highlighting; |
| 93 } | 115 } |
| 94 FeatureSwitch* FeatureSwitch::easy_off_store_install() { | 116 FeatureSwitch* FeatureSwitch::easy_off_store_install() { |
| 95 return &g_common_switches.Get().easy_off_store_install; | 117 return &g_common_switches.Get().easy_off_store_install; |
| 96 } | 118 } |
| 97 FeatureSwitch* FeatureSwitch::prompt_for_external_extensions() { | 119 FeatureSwitch* FeatureSwitch::prompt_for_external_extensions() { |
| 98 return &g_common_switches.Get().prompt_for_external_extensions; | 120 return &g_common_switches.Get().prompt_for_external_extensions; |
| 99 } | 121 } |
| 100 FeatureSwitch* FeatureSwitch::error_console() { | 122 FeatureSwitch* FeatureSwitch::error_console() { |
| 101 return &g_common_switches.Get().error_console; | 123 return &g_common_switches.Get().error_console; |
| 102 } | 124 } |
| 103 FeatureSwitch* FeatureSwitch::enable_override_bookmarks_ui() { | 125 FeatureSwitch* FeatureSwitch::enable_override_bookmarks_ui() { |
| 104 return &g_common_switches.Get().enable_override_bookmarks_ui; | 126 return &g_common_switches.Get().enable_override_bookmarks_ui; |
| 105 } | 127 } |
| 106 FeatureSwitch* FeatureSwitch::extension_action_redesign() { | 128 FeatureSwitch* FeatureSwitch::extension_action_redesign() { |
| 107 // Force-enable the redesigned extension action toolbar when the Media Router | 129 // Force-enable the redesigned extension action toolbar when the Media Router |
| 108 // is enabled. Should be removed when the toolbar redesign is used by default. | 130 // is enabled. Should be removed when the toolbar redesign is used by default. |
| 109 // See crbug.com/514694 | 131 // See crbug.com/514694 |
| 110 // TODO(kmarshall): Remove this override. | 132 // TODO(kmarshall): Remove this override. |
| 111 if (media_router()->IsEnabled()) | 133 if (GetSwitchValue(base::CommandLine::ForCurrentProcess(), |
| 134 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
| |
| 112 return &g_common_switches.Get().extension_action_redesign_override; | 135 return &g_common_switches.Get().extension_action_redesign_override; |
| 113 | 136 |
| 114 return &g_common_switches.Get().extension_action_redesign; | 137 return &g_common_switches.Get().extension_action_redesign; |
| 115 } | 138 } |
| 116 FeatureSwitch* FeatureSwitch::scripts_require_action() { | 139 FeatureSwitch* FeatureSwitch::scripts_require_action() { |
| 117 return &g_common_switches.Get().scripts_require_action; | 140 return &g_common_switches.Get().scripts_require_action; |
| 118 } | 141 } |
| 119 FeatureSwitch* FeatureSwitch::embedded_extension_options() { | 142 FeatureSwitch* FeatureSwitch::embedded_extension_options() { |
| 120 return &g_common_switches.Get().embedded_extension_options; | 143 return &g_common_switches.Get().embedded_extension_options; |
| 121 } | 144 } |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 146 : FeatureSwitch(base::CommandLine::ForCurrentProcess(), | 169 : FeatureSwitch(base::CommandLine::ForCurrentProcess(), |
| 147 switch_name, | 170 switch_name, |
| 148 default_value) {} | 171 default_value) {} |
| 149 | 172 |
| 150 FeatureSwitch::FeatureSwitch(const char* switch_name, | 173 FeatureSwitch::FeatureSwitch(const char* switch_name, |
| 151 const char* field_trial_name, | 174 const char* field_trial_name, |
| 152 DefaultValue default_value) | 175 DefaultValue default_value) |
| 153 : FeatureSwitch(base::CommandLine::ForCurrentProcess(), | 176 : FeatureSwitch(base::CommandLine::ForCurrentProcess(), |
| 154 switch_name, | 177 switch_name, |
| 155 field_trial_name, | 178 field_trial_name, |
| 179 std::vector<const char*>(), | |
| 180 default_value) {} | |
| 181 | |
| 182 FeatureSwitch::FeatureSwitch( | |
| 183 const char* switch_name, | |
| 184 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
| |
| 185 const std::vector<const char*>& dependent_field_trials, | |
| 186 DefaultValue default_value) | |
| 187 : FeatureSwitch(base::CommandLine::ForCurrentProcess(), | |
| 188 switch_name, | |
| 189 field_trial_name, | |
| 190 dependent_field_trials, | |
| 156 default_value) {} | 191 default_value) {} |
| 157 | 192 |
| 158 FeatureSwitch::FeatureSwitch(const base::CommandLine* command_line, | 193 FeatureSwitch::FeatureSwitch(const base::CommandLine* command_line, |
| 159 const char* switch_name, | 194 const char* switch_name, |
| 160 DefaultValue default_value) | 195 DefaultValue default_value) |
| 161 : FeatureSwitch(command_line, switch_name, nullptr, default_value) {} | 196 : FeatureSwitch(command_line, |
| 197 switch_name, | |
| 198 nullptr, | |
| 199 std::vector<const char*>(), | |
| 200 default_value) {} | |
| 162 | 201 |
| 163 FeatureSwitch::FeatureSwitch(const base::CommandLine* command_line, | 202 FeatureSwitch::FeatureSwitch( |
| 164 const char* switch_name, | 203 const base::CommandLine* command_line, |
| 165 const char* field_trial_name, | 204 const char* switch_name, |
| 166 DefaultValue default_value) | 205 const char* field_trial_name, |
| 206 const std::vector<const char*>& dependent_field_trials, | |
| 207 DefaultValue default_value) | |
| 167 : command_line_(command_line), | 208 : command_line_(command_line), |
| 168 switch_name_(switch_name), | 209 switch_name_(switch_name), |
| 169 field_trial_name_(field_trial_name), | 210 field_trial_name_(field_trial_name), |
| 211 dependent_field_trials_(dependent_field_trials), | |
| 170 default_value_(default_value == DEFAULT_ENABLED), | 212 default_value_(default_value == DEFAULT_ENABLED), |
| 171 override_value_(OVERRIDE_NONE) {} | 213 override_value_(OVERRIDE_NONE) {} |
| 172 | 214 |
| 215 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.
| |
| 216 | |
| 173 bool FeatureSwitch::IsEnabled() const { | 217 bool FeatureSwitch::IsEnabled() const { |
| 174 if (override_value_ != OVERRIDE_NONE) | 218 if (override_value_ != OVERRIDE_NONE) |
| 175 return override_value_ == OVERRIDE_ENABLED; | 219 return override_value_ == OVERRIDE_ENABLED; |
| 176 | 220 |
| 177 if (!switch_name_) | 221 if (!switch_name_) |
| 178 return default_value_; | 222 return default_value_; |
| 179 | 223 |
| 180 std::string temp = command_line_->GetSwitchValueASCII(switch_name_); | 224 std::string switch_value = GetSwitchValue(command_line_, switch_name_); |
| 181 std::string switch_value; | |
| 182 base::TrimWhitespaceASCII(temp, base::TRIM_ALL, &switch_value); | |
| 183 | |
| 184 if (switch_value == "1") | 225 if (switch_value == "1") |
| 185 return true; | 226 return true; |
| 186 | 227 |
| 187 if (switch_value == "0") | 228 if (switch_value == "0") |
| 188 return false; | 229 return false; |
| 189 | 230 |
| 190 if (!default_value_ && command_line_->HasSwitch(GetLegacyEnableFlag())) | 231 if (!default_value_ && command_line_->HasSwitch(GetLegacyEnableFlag())) |
|
Devlin
2016/02/09 18:45:14
unrelated to this change, but these should really
imcheng
2016/02/09 21:35:39
Ok, I will file a bug for it.
| |
| 191 return true; | 232 return true; |
| 192 | 233 |
| 193 if (default_value_ && command_line_->HasSwitch(GetLegacyDisableFlag())) | 234 if (default_value_ && command_line_->HasSwitch(GetLegacyDisableFlag())) |
| 194 return false; | 235 return false; |
| 195 | 236 |
| 196 if (field_trial_name_) { | 237 if (field_trial_name_) { |
| 197 std::string group_name = | 238 std::string group_name = |
| 198 base::FieldTrialList::FindFullName(field_trial_name_); | 239 base::FieldTrialList::FindFullName(field_trial_name_); |
| 199 if (group_name == "Enabled") | 240 if (group_name == "Enabled" && DependentFieldTrialsEnabled()) |
| 200 return true; | 241 return true; |
| 201 if (group_name == "Disabled") | 242 if (group_name == "Disabled") |
| 202 return false; | 243 return false; |
| 203 } | 244 } |
| 204 | 245 |
| 205 return default_value_; | 246 return default_value_; |
| 206 } | 247 } |
| 207 | 248 |
| 208 std::string FeatureSwitch::GetLegacyEnableFlag() const { | 249 std::string FeatureSwitch::GetLegacyEnableFlag() const { |
| 209 DCHECK(switch_name_); | 250 DCHECK(switch_name_); |
| 210 return std::string("enable-") + switch_name_; | 251 return std::string("enable-") + switch_name_; |
| 211 } | 252 } |
| 212 | 253 |
| 213 std::string FeatureSwitch::GetLegacyDisableFlag() const { | 254 std::string FeatureSwitch::GetLegacyDisableFlag() const { |
| 214 DCHECK(switch_name_); | 255 DCHECK(switch_name_); |
| 215 return std::string("disable-") + switch_name_; | 256 return std::string("disable-") + switch_name_; |
| 216 } | 257 } |
| 217 | 258 |
| 259 bool FeatureSwitch::DependentFieldTrialsEnabled() const { | |
| 260 for (const std::string& dependent_field_trial : dependent_field_trials_) { | |
| 261 std::string group_name = | |
| 262 base::FieldTrialList::FindFullName(dependent_field_trial); | |
| 263 if (group_name != "Enabled") | |
| 264 return false; | |
| 265 } | |
| 266 return true; | |
| 267 } | |
| 268 | |
| 218 void FeatureSwitch::SetOverrideValue(OverrideValue override_value) { | 269 void FeatureSwitch::SetOverrideValue(OverrideValue override_value) { |
| 219 override_value_ = override_value; | 270 override_value_ = override_value; |
| 220 } | 271 } |
| 221 | 272 |
| 222 FeatureSwitch::OverrideValue FeatureSwitch::GetOverrideValue() const { | 273 FeatureSwitch::OverrideValue FeatureSwitch::GetOverrideValue() const { |
| 223 return override_value_; | 274 return override_value_; |
| 224 } | 275 } |
| 225 | 276 |
| 226 } // namespace extensions | 277 } // namespace extensions |
| OLD | NEW |