Chromium Code Reviews| Index: extensions/common/feature_switch.cc |
| diff --git a/extensions/common/feature_switch.cc b/extensions/common/feature_switch.cc |
| index 6567ba9b4220a28ce58cac63592d53bc54e3c3dc..f9a7e490fdeee7a9924f1b26ac5484223a80c6ed 100644 |
| --- a/extensions/common/feature_switch.cc |
| +++ b/extensions/common/feature_switch.cc |
| @@ -20,6 +20,8 @@ namespace { |
| const char kLoadMediaRouterComponentExtensionFlag[] = |
| "load-media-router-component-extension"; |
| +const char kYieldBetweenContentScriptRuns[] = "YieldBetweenContentScriptRuns"; |
| + |
| class CommonSwitches { |
| public: |
| CommonSwitches() |
| @@ -54,7 +56,11 @@ class CommonSwitches { |
| FeatureSwitch::DEFAULT_DISABLED), |
| #endif // defined(GOOGLE_CHROME_BUILD) |
| native_crx_bindings(switches::kNativeCrxBindings, |
| - FeatureSwitch::DEFAULT_DISABLED) { |
| + FeatureSwitch::DEFAULT_DISABLED), |
| + yield_between_content_script_runs( |
| + switches::kYieldBetweenContentScriptRuns, |
| + kYieldBetweenContentScriptRuns, |
|
Devlin
2017/03/10 03:18:45
We should rename this to be kYieldBetweenContentSc
Kunihiko Sakamoto
2017/03/10 07:07:28
Done.
|
| + FeatureSwitch::DEFAULT_DISABLED) { |
| } |
| FeatureSwitch force_dev_mode_highlighting; |
| @@ -71,6 +77,7 @@ class CommonSwitches { |
| FeatureSwitch trace_app_source; |
| FeatureSwitch load_media_router_component_extension; |
| FeatureSwitch native_crx_bindings; |
| + FeatureSwitch yield_between_content_script_runs; |
| }; |
| base::LazyInstance<CommonSwitches> g_common_switches = |
| @@ -108,6 +115,9 @@ FeatureSwitch* FeatureSwitch::load_media_router_component_extension() { |
| FeatureSwitch* FeatureSwitch::native_crx_bindings() { |
| return &g_common_switches.Get().native_crx_bindings; |
| } |
| +FeatureSwitch* FeatureSwitch::yield_between_content_script_runs() { |
| + return &g_common_switches.Get().yield_between_content_script_runs; |
| +} |
| FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature, |
| bool override_value) |
| @@ -148,12 +158,18 @@ FeatureSwitch::FeatureSwitch(const base::CommandLine* command_line, |
| switch_name_(switch_name), |
| field_trial_name_(field_trial_name), |
| default_value_(default_value == DEFAULT_ENABLED), |
| - override_value_(OVERRIDE_NONE) {} |
| + override_value_(OVERRIDE_NONE), |
| + cached_value_(NOT_CACHED) {} |
| bool FeatureSwitch::IsEnabled() const { |
| if (override_value_ != OVERRIDE_NONE) |
| return override_value_ == OVERRIDE_ENABLED; |
| + if (cached_value_ == NOT_CACHED) |
| + cached_value_ = ComputeValue() ? CACHED_ENABLED : CACHED_DISABLED; |
| + return cached_value_ == CACHED_ENABLED; |
| +} |
| +bool FeatureSwitch::ComputeValue() const { |
| if (!switch_name_) |
| return default_value_; |