Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(913)

Side by Side Diff: extensions/common/feature_switch.cc

Issue 2633253002: Split content script injections into multiple tasks (Closed)
Patch Set: rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 kYieldBetweenContentScriptRuns[] = "YieldBetweenContentScriptRuns";
24
23 class CommonSwitches { 25 class CommonSwitches {
24 public: 26 public:
25 CommonSwitches() 27 CommonSwitches()
26 : force_dev_mode_highlighting(switches::kForceDevModeHighlighting, 28 : force_dev_mode_highlighting(switches::kForceDevModeHighlighting,
27 FeatureSwitch::DEFAULT_DISABLED), 29 FeatureSwitch::DEFAULT_DISABLED),
28 prompt_for_external_extensions( 30 prompt_for_external_extensions(
29 #if defined(CHROMIUM_BUILD) 31 #if defined(CHROMIUM_BUILD)
30 switches::kPromptForExternalExtensions, 32 switches::kPromptForExternalExtensions,
31 #else 33 #else
32 nullptr, 34 nullptr,
(...skipping 14 matching lines...) Expand all
47 trace_app_source(switches::kTraceAppSource, 49 trace_app_source(switches::kTraceAppSource,
48 FeatureSwitch::DEFAULT_ENABLED), 50 FeatureSwitch::DEFAULT_ENABLED),
49 load_media_router_component_extension( 51 load_media_router_component_extension(
50 kLoadMediaRouterComponentExtensionFlag, 52 kLoadMediaRouterComponentExtensionFlag,
51 #if defined(GOOGLE_CHROME_BUILD) 53 #if defined(GOOGLE_CHROME_BUILD)
52 FeatureSwitch::DEFAULT_ENABLED), 54 FeatureSwitch::DEFAULT_ENABLED),
53 #else 55 #else
54 FeatureSwitch::DEFAULT_DISABLED), 56 FeatureSwitch::DEFAULT_DISABLED),
55 #endif // defined(GOOGLE_CHROME_BUILD) 57 #endif // defined(GOOGLE_CHROME_BUILD)
56 native_crx_bindings(switches::kNativeCrxBindings, 58 native_crx_bindings(switches::kNativeCrxBindings,
57 FeatureSwitch::DEFAULT_DISABLED) { 59 FeatureSwitch::DEFAULT_DISABLED),
60 yield_between_content_script_runs(
61 switches::kYieldBetweenContentScriptRuns,
62 kYieldBetweenContentScriptRuns,
Devlin 2017/03/10 03:18:45 We should rename this to be kYieldBetweenContentSc
Kunihiko Sakamoto 2017/03/10 07:07:28 Done.
63 FeatureSwitch::DEFAULT_DISABLED) {
58 } 64 }
59 65
60 FeatureSwitch force_dev_mode_highlighting; 66 FeatureSwitch force_dev_mode_highlighting;
61 67
62 // Should we prompt the user before allowing external extensions to install? 68 // Should we prompt the user before allowing external extensions to install?
63 // Default is yes. 69 // Default is yes.
64 FeatureSwitch prompt_for_external_extensions; 70 FeatureSwitch prompt_for_external_extensions;
65 71
66 FeatureSwitch error_console; 72 FeatureSwitch error_console;
67 FeatureSwitch enable_override_bookmarks_ui; 73 FeatureSwitch enable_override_bookmarks_ui;
68 FeatureSwitch extension_action_redesign; 74 FeatureSwitch extension_action_redesign;
69 FeatureSwitch scripts_require_action; 75 FeatureSwitch scripts_require_action;
70 FeatureSwitch embedded_extension_options; 76 FeatureSwitch embedded_extension_options;
71 FeatureSwitch trace_app_source; 77 FeatureSwitch trace_app_source;
72 FeatureSwitch load_media_router_component_extension; 78 FeatureSwitch load_media_router_component_extension;
73 FeatureSwitch native_crx_bindings; 79 FeatureSwitch native_crx_bindings;
80 FeatureSwitch yield_between_content_script_runs;
74 }; 81 };
75 82
76 base::LazyInstance<CommonSwitches> g_common_switches = 83 base::LazyInstance<CommonSwitches> g_common_switches =
77 LAZY_INSTANCE_INITIALIZER; 84 LAZY_INSTANCE_INITIALIZER;
78 85
79 } // namespace 86 } // namespace
80 87
81 FeatureSwitch* FeatureSwitch::force_dev_mode_highlighting() { 88 FeatureSwitch* FeatureSwitch::force_dev_mode_highlighting() {
82 return &g_common_switches.Get().force_dev_mode_highlighting; 89 return &g_common_switches.Get().force_dev_mode_highlighting;
83 } 90 }
(...skipping 17 matching lines...) Expand all
101 } 108 }
102 FeatureSwitch* FeatureSwitch::trace_app_source() { 109 FeatureSwitch* FeatureSwitch::trace_app_source() {
103 return &g_common_switches.Get().trace_app_source; 110 return &g_common_switches.Get().trace_app_source;
104 } 111 }
105 FeatureSwitch* FeatureSwitch::load_media_router_component_extension() { 112 FeatureSwitch* FeatureSwitch::load_media_router_component_extension() {
106 return &g_common_switches.Get().load_media_router_component_extension; 113 return &g_common_switches.Get().load_media_router_component_extension;
107 } 114 }
108 FeatureSwitch* FeatureSwitch::native_crx_bindings() { 115 FeatureSwitch* FeatureSwitch::native_crx_bindings() {
109 return &g_common_switches.Get().native_crx_bindings; 116 return &g_common_switches.Get().native_crx_bindings;
110 } 117 }
118 FeatureSwitch* FeatureSwitch::yield_between_content_script_runs() {
119 return &g_common_switches.Get().yield_between_content_script_runs;
120 }
111 121
112 FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature, 122 FeatureSwitch::ScopedOverride::ScopedOverride(FeatureSwitch* feature,
113 bool override_value) 123 bool override_value)
114 : feature_(feature), 124 : feature_(feature),
115 previous_value_(feature->GetOverrideValue()) { 125 previous_value_(feature->GetOverrideValue()) {
116 feature_->SetOverrideValue( 126 feature_->SetOverrideValue(
117 override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED); 127 override_value ? OVERRIDE_ENABLED : OVERRIDE_DISABLED);
118 } 128 }
119 129
120 FeatureSwitch::ScopedOverride::~ScopedOverride() { 130 FeatureSwitch::ScopedOverride::~ScopedOverride() {
(...skipping 20 matching lines...) Expand all
141 : FeatureSwitch(command_line, switch_name, nullptr, default_value) {} 151 : FeatureSwitch(command_line, switch_name, nullptr, default_value) {}
142 152
143 FeatureSwitch::FeatureSwitch(const base::CommandLine* command_line, 153 FeatureSwitch::FeatureSwitch(const base::CommandLine* command_line,
144 const char* switch_name, 154 const char* switch_name,
145 const char* field_trial_name, 155 const char* field_trial_name,
146 DefaultValue default_value) 156 DefaultValue default_value)
147 : command_line_(command_line), 157 : command_line_(command_line),
148 switch_name_(switch_name), 158 switch_name_(switch_name),
149 field_trial_name_(field_trial_name), 159 field_trial_name_(field_trial_name),
150 default_value_(default_value == DEFAULT_ENABLED), 160 default_value_(default_value == DEFAULT_ENABLED),
151 override_value_(OVERRIDE_NONE) {} 161 override_value_(OVERRIDE_NONE),
162 cached_value_(NOT_CACHED) {}
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_ == NOT_CACHED)
168 cached_value_ = ComputeValue() ? CACHED_ENABLED : CACHED_DISABLED;
169 return cached_value_ == CACHED_ENABLED;
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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698