| 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 load-media-router-component-extension is defined in | 18 // The switch load-media-router-component-extension is defined in |
| 19 // chrome/common/chrome_switches.cc, but we can't depend on chrome here. | 19 // chrome/common/chrome_switches.cc, but we can't depend on chrome here. |
| 20 const char kLoadMediaRouterComponentExtensionFlag[] = | 20 const char kLoadMediaRouterComponentExtensionFlag[] = |
| 21 "load-media-router-component-extension"; | 21 "load-media-router-component-extension"; |
| 22 | 22 |
| 23 const char kYieldBetweenContentScriptRunsFieldTrial[] = |
| 24 "YieldBetweenContentScriptRuns"; |
| 25 |
| 23 class CommonSwitches { | 26 class CommonSwitches { |
| 24 public: | 27 public: |
| 25 CommonSwitches() | 28 CommonSwitches() |
| 26 : force_dev_mode_highlighting(switches::kForceDevModeHighlighting, | 29 : force_dev_mode_highlighting(switches::kForceDevModeHighlighting, |
| 27 FeatureSwitch::DEFAULT_DISABLED), | 30 FeatureSwitch::DEFAULT_DISABLED), |
| 28 prompt_for_external_extensions( | 31 prompt_for_external_extensions( |
| 29 #if defined(CHROMIUM_BUILD) | 32 #if defined(CHROMIUM_BUILD) |
| 30 switches::kPromptForExternalExtensions, | 33 switches::kPromptForExternalExtensions, |
| 31 #else | 34 #else |
| 32 nullptr, | 35 nullptr, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 47 trace_app_source(switches::kTraceAppSource, | 50 trace_app_source(switches::kTraceAppSource, |
| 48 FeatureSwitch::DEFAULT_ENABLED), | 51 FeatureSwitch::DEFAULT_ENABLED), |
| 49 load_media_router_component_extension( | 52 load_media_router_component_extension( |
| 50 kLoadMediaRouterComponentExtensionFlag, | 53 kLoadMediaRouterComponentExtensionFlag, |
| 51 #if defined(GOOGLE_CHROME_BUILD) | 54 #if defined(GOOGLE_CHROME_BUILD) |
| 52 FeatureSwitch::DEFAULT_ENABLED), | 55 FeatureSwitch::DEFAULT_ENABLED), |
| 53 #else | 56 #else |
| 54 FeatureSwitch::DEFAULT_DISABLED), | 57 FeatureSwitch::DEFAULT_DISABLED), |
| 55 #endif // defined(GOOGLE_CHROME_BUILD) | 58 #endif // defined(GOOGLE_CHROME_BUILD) |
| 56 native_crx_bindings(switches::kNativeCrxBindings, | 59 native_crx_bindings(switches::kNativeCrxBindings, |
| 57 FeatureSwitch::DEFAULT_DISABLED) { | 60 FeatureSwitch::DEFAULT_DISABLED), |
| 61 yield_between_content_script_runs( |
| 62 switches::kYieldBetweenContentScriptRuns, |
| 63 kYieldBetweenContentScriptRunsFieldTrial, |
| 64 FeatureSwitch::DEFAULT_DISABLED) { |
| 58 } | 65 } |
| 59 | 66 |
| 60 FeatureSwitch force_dev_mode_highlighting; | 67 FeatureSwitch force_dev_mode_highlighting; |
| 61 | 68 |
| 62 // Should we prompt the user before allowing external extensions to install? | 69 // Should we prompt the user before allowing external extensions to install? |
| 63 // Default is yes. | 70 // Default is yes. |
| 64 FeatureSwitch prompt_for_external_extensions; | 71 FeatureSwitch prompt_for_external_extensions; |
| 65 | 72 |
| 66 FeatureSwitch error_console; | 73 FeatureSwitch error_console; |
| 67 FeatureSwitch enable_override_bookmarks_ui; | 74 FeatureSwitch enable_override_bookmarks_ui; |
| 68 FeatureSwitch extension_action_redesign; | 75 FeatureSwitch extension_action_redesign; |
| 69 FeatureSwitch scripts_require_action; | 76 FeatureSwitch scripts_require_action; |
| 70 FeatureSwitch embedded_extension_options; | 77 FeatureSwitch embedded_extension_options; |
| 71 FeatureSwitch trace_app_source; | 78 FeatureSwitch trace_app_source; |
| 72 FeatureSwitch load_media_router_component_extension; | 79 FeatureSwitch load_media_router_component_extension; |
| 73 FeatureSwitch native_crx_bindings; | 80 FeatureSwitch native_crx_bindings; |
| 81 FeatureSwitch yield_between_content_script_runs; |
| 74 }; | 82 }; |
| 75 | 83 |
| 76 base::LazyInstance<CommonSwitches>::DestructorAtExit g_common_switches = | 84 base::LazyInstance<CommonSwitches>::DestructorAtExit g_common_switches = |
| 77 LAZY_INSTANCE_INITIALIZER; | 85 LAZY_INSTANCE_INITIALIZER; |
| 78 | 86 |
| 79 } // namespace | 87 } // namespace |
| 80 | 88 |
| 81 FeatureSwitch* FeatureSwitch::force_dev_mode_highlighting() { | 89 FeatureSwitch* FeatureSwitch::force_dev_mode_highlighting() { |
| 82 return &g_common_switches.Get().force_dev_mode_highlighting; | 90 return &g_common_switches.Get().force_dev_mode_highlighting; |
| 83 } | 91 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 101 } | 109 } |
| 102 FeatureSwitch* FeatureSwitch::trace_app_source() { | 110 FeatureSwitch* FeatureSwitch::trace_app_source() { |
| 103 return &g_common_switches.Get().trace_app_source; | 111 return &g_common_switches.Get().trace_app_source; |
| 104 } | 112 } |
| 105 FeatureSwitch* FeatureSwitch::load_media_router_component_extension() { | 113 FeatureSwitch* FeatureSwitch::load_media_router_component_extension() { |
| 106 return &g_common_switches.Get().load_media_router_component_extension; | 114 return &g_common_switches.Get().load_media_router_component_extension; |
| 107 } | 115 } |
| 108 FeatureSwitch* FeatureSwitch::native_crx_bindings() { | 116 FeatureSwitch* FeatureSwitch::native_crx_bindings() { |
| 109 return &g_common_switches.Get().native_crx_bindings; | 117 return &g_common_switches.Get().native_crx_bindings; |
| 110 } | 118 } |
| 119 FeatureSwitch* FeatureSwitch::yield_between_content_script_runs() { |
| 120 return &g_common_switches.Get().yield_between_content_script_runs; |
| 121 } |
| 111 | 122 |
| 112 FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature, | 123 FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature, |
| 113 bool override_value) | 124 bool override_value) |
| 114 : feature_(feature), | 125 : feature_(feature), |
| 115 previous_value_(feature->GetOverrideValue()) { | 126 previous_value_(feature->GetOverrideValue()) { |
| 116 feature_->SetOverrideValue( | 127 feature_->SetOverrideValue( |
| 117 override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED); | 128 override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED); |
| 118 } | 129 } |
| 119 | 130 |
| 120 FeatureSwitch::ScopedOverride::~ScopedOverride() { | 131 FeatureSwitch::ScopedOverride::~ScopedOverride() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 146 DefaultValue default_value) | 157 DefaultValue default_value) |
| 147 : command_line_(command_line), | 158 : command_line_(command_line), |
| 148 switch_name_(switch_name), | 159 switch_name_(switch_name), |
| 149 field_trial_name_(field_trial_name), | 160 field_trial_name_(field_trial_name), |
| 150 default_value_(default_value == DEFAULT_ENABLED), | 161 default_value_(default_value == DEFAULT_ENABLED), |
| 151 override_value_(OVERRIDE_NONE) {} | 162 override_value_(OVERRIDE_NONE) {} |
| 152 | 163 |
| 153 bool FeatureSwitch::IsEnabled() const { | 164 bool FeatureSwitch::IsEnabled() const { |
| 154 if (override_value_ != OVERRIDE_NONE) | 165 if (override_value_ != OVERRIDE_NONE) |
| 155 return override_value_ == OVERRIDE_ENABLED; | 166 return override_value_ == OVERRIDE_ENABLED; |
| 167 if (!cached_value_.has_value()) |
| 168 cached_value_ = ComputeValue(); |
| 169 return cached_value_.value(); |
| 170 } |
| 156 | 171 |
| 172 bool FeatureSwitch::ComputeValue() const { |
| 157 if (!switch_name_) | 173 if (!switch_name_) |
| 158 return default_value_; | 174 return default_value_; |
| 159 | 175 |
| 160 std::string temp = command_line_->GetSwitchValueASCII(switch_name_); | 176 std::string temp = command_line_->GetSwitchValueASCII(switch_name_); |
| 161 std::string switch_value; | 177 std::string switch_value; |
| 162 base::TrimWhitespaceASCII(temp, base::TRIM_ALL, &switch_value); | 178 base::TrimWhitespaceASCII(temp, base::TRIM_ALL, &switch_value); |
| 163 | 179 |
| 164 if (switch_value == "1") | 180 if (switch_value == "1") |
| 165 return true; | 181 return true; |
| 166 | 182 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 | 216 |
| 201 void FeatureSwitch::SetOverrideValue(OverrideValue override_value) { | 217 void FeatureSwitch::SetOverrideValue(OverrideValue override_value) { |
| 202 override_value_ = override_value; | 218 override_value_ = override_value; |
| 203 } | 219 } |
| 204 | 220 |
| 205 FeatureSwitch::OverrideValue FeatureSwitch::GetOverrideValue() const { | 221 FeatureSwitch::OverrideValue FeatureSwitch::GetOverrideValue() const { |
| 206 return override_value_; | 222 return override_value_; |
| 207 } | 223 } |
| 208 | 224 |
| 209 } // namespace extensions | 225 } // namespace extensions |
| OLD | NEW |