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

Side by Side Diff: content/renderer/render_process_impl.cc

Issue 2491823005: Initialize TaskScheduler in renderers. (Closed)
Patch Set: self-review Created 4 years 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
« no previous file with comments | « content/public/renderer/content_renderer_client.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/renderer/render_process_impl.h" 5 #include "content/renderer/render_process_impl.h"
6 6
7 #include "build/build_config.h" 7 #include "build/build_config.h"
8 8
9 #if defined(OS_WIN) 9 #if defined(OS_WIN)
10 #include <windows.h> 10 #include <windows.h>
11 #include <objidl.h> 11 #include <objidl.h>
12 #include <mlang.h> 12 #include <mlang.h>
13 #endif 13 #endif
14 14
15 #include <stddef.h>
16
17 #include <vector>
18
19 #include "base/bind.h"
15 #include "base/command_line.h" 20 #include "base/command_line.h"
16 #include "base/compiler_specific.h" 21 #include "base/compiler_specific.h"
17 #include "base/feature_list.h" 22 #include "base/feature_list.h"
18 #include "base/sys_info.h" 23 #include "base/sys_info.h"
24 #include "base/task_scheduler/initialization_util.h"
25 #include "base/task_scheduler/scheduler_worker_pool_params.h"
26 #include "base/task_scheduler/task_scheduler.h"
27 #include "base/task_scheduler/task_traits.h"
28 #include "base/threading/platform_thread.h"
29 #include "base/time/time.h"
19 #include "content/child/site_isolation_stats_gatherer.h" 30 #include "content/child/site_isolation_stats_gatherer.h"
31 #include "content/public/common/content_client.h"
20 #include "content/public/common/content_features.h" 32 #include "content/public/common/content_features.h"
21 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
22 #include "content/public/renderer/content_renderer_client.h" 34 #include "content/public/renderer/content_renderer_client.h"
23 #include "third_party/WebKit/public/web/WebFrame.h" 35 #include "third_party/WebKit/public/web/WebFrame.h"
24 #include "v8/include/v8.h" 36 #include "v8/include/v8.h"
25 37
26 namespace { 38 namespace {
27 39
40 enum WorkerPoolType : size_t {
41 BACKGROUND = 0,
42 BACKGROUND_FILE_IO,
43 FOREGROUND,
44 FOREGROUND_FILE_IO,
45 WORKER_POOL_COUNT // Always last.
46 };
47
28 const base::Feature kV8_ES2015_TailCalls_Feature { 48 const base::Feature kV8_ES2015_TailCalls_Feature {
29 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT 49 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT
30 }; 50 };
31 51
32 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ 52 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{
33 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; 53 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT};
34 54
35 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", 55 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager",
36 base::FEATURE_DISABLED_BY_DEFAULT}; 56 base::FEATURE_DISABLED_BY_DEFAULT};
37 57
38 const base::Feature kV8SerializeAgeCodeFeature{ 58 const base::Feature kV8SerializeAgeCodeFeature{
39 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT}; 59 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT};
40 60
41 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) { 61 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) {
42 if (base::FeatureList::IsEnabled(feature)) { 62 if (base::FeatureList::IsEnabled(feature)) {
43 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); 63 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
44 } 64 }
45 } 65 }
46 66
47 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { 67 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) {
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { 68 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
49 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); 69 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
50 } 70 }
51 } 71 }
52 72
73 std::vector<base::SchedulerWorkerPoolParams>
74 GetDefaultSchedulerWorkerPoolParams() {
75 using StandbyThreadPolicy =
76 base::SchedulerWorkerPoolParams::StandbyThreadPolicy;
77 using ThreadPriority = base::ThreadPriority;
78 std::vector<base::SchedulerWorkerPoolParams> params_vector;
79 params_vector.emplace_back("RendererBackground", ThreadPriority::BACKGROUND,
80 StandbyThreadPolicy::LAZY, 1,
81 base::TimeDelta::FromSeconds(30));
82 params_vector.emplace_back(
83 "RendererBackgroundFileIO", ThreadPriority::BACKGROUND,
84 StandbyThreadPolicy::LAZY, 1, base::TimeDelta::FromSeconds(30));
85 params_vector.emplace_back(
86 "RendererForeground", ThreadPriority::NORMAL, StandbyThreadPolicy::LAZY,
87 base::RecommendedMaxNumberOfThreadsInPool(1, 2, 1, 0),
gab 2016/12/09 23:19:42 Thought we'd said 2-4?
fdoray 2016/12/12 16:20:08 Done.
88 base::TimeDelta::FromSeconds(30));
89 params_vector.emplace_back("RendererForegroundFileIO", ThreadPriority::NORMAL,
90 StandbyThreadPolicy::LAZY, 1,
91 base::TimeDelta::FromSeconds(30));
92 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size());
93 return params_vector;
94 }
95
96 // Returns the worker pool index for |traits| defaulting to FOREGROUND or
97 // FOREGROUND_FILE_IO on any other priorities based off of worker pools defined
98 // in GetDefaultSchedulerWorkerPoolParams().
99 size_t DefaultRendererWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
100 const bool is_background =
101 traits.priority() == base::TaskPriority::BACKGROUND;
102 if (traits.with_file_io())
103 return is_background ? BACKGROUND_FILE_IO : FOREGROUND_FILE_IO;
104
105 return is_background ? BACKGROUND : FOREGROUND;
106 }
107
108 bool IsSingleProcess() {
109 return base::CommandLine::ForCurrentProcess()->HasSwitch(
110 switches::kSingleProcess);
111 }
112
113 void InitializeTaskScheduler() {
114 if (IsSingleProcess()) {
115 // There should already be a TaskScheduler when the renderer runs inside the
116 // browser process.
117 DCHECK(base::TaskScheduler::GetInstance());
118 return;
119 }
120 DCHECK(!base::TaskScheduler::GetInstance());
121
122 std::vector<base::SchedulerWorkerPoolParams> params_vector;
123 base::TaskScheduler::WorkerPoolIndexForTraitsCallback
124 index_to_traits_callback;
125 content::GetContentClient()->renderer()->GetTaskSchedulerInitializationParams(
126 &params_vector, &index_to_traits_callback);
127
128 if (params_vector.empty()) {
129 params_vector = GetDefaultSchedulerWorkerPoolParams();
130 index_to_traits_callback =
131 base::Bind(&DefaultRendererWorkerPoolIndexForTraits);
132 }
133 DCHECK(index_to_traits_callback);
134
135 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
136 params_vector, index_to_traits_callback);
137 }
138
53 } // namespace 139 } // namespace
54 140
55 namespace content { 141 namespace content {
56 142
57 RenderProcessImpl::RenderProcessImpl() 143 RenderProcessImpl::RenderProcessImpl()
58 : enabled_bindings_(0) { 144 : enabled_bindings_(0) {
59 #if defined(OS_WIN) 145 #if defined(OS_WIN)
60 // HACK: See http://b/issue?id=1024307 for rationale. 146 // HACK: See http://b/issue?id=1024307 for rationale.
61 if (GetModuleHandle(L"LPK.DLL") == NULL) { 147 if (GetModuleHandle(L"LPK.DLL") == NULL) {
62 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works 148 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 *base::CommandLine::ForCurrentProcess(); 182 *base::CommandLine::ForCurrentProcess();
97 183
98 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { 184 if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
99 std::string flags( 185 std::string flags(
100 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); 186 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags));
101 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); 187 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
102 } 188 }
103 189
104 SiteIsolationStatsGatherer::SetEnabled( 190 SiteIsolationStatsGatherer::SetEnabled(
105 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); 191 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats());
192
193 InitializeTaskScheduler();
106 } 194 }
107 195
108 RenderProcessImpl::~RenderProcessImpl() { 196 RenderProcessImpl::~RenderProcessImpl() {
109 #ifndef NDEBUG 197 #ifndef NDEBUG
110 int count = blink::WebFrame::instanceCount(); 198 int count = blink::WebFrame::instanceCount();
111 if (count) 199 if (count)
112 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; 200 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES";
113 #endif 201 #endif
114 202
203 if (!IsSingleProcess()) {
204 DCHECK(base::TaskScheduler::GetInstance());
205 base::TaskScheduler::GetInstance()->Shutdown();
206 }
207
115 GetShutDownEvent()->Signal(); 208 GetShutDownEvent()->Signal();
116 } 209 }
117 210
118 void RenderProcessImpl::AddBindings(int bindings) { 211 void RenderProcessImpl::AddBindings(int bindings) {
119 enabled_bindings_ |= bindings; 212 enabled_bindings_ |= bindings;
120 } 213 }
121 214
122 int RenderProcessImpl::GetEnabledBindings() const { 215 int RenderProcessImpl::GetEnabledBindings() const {
123 return enabled_bindings_; 216 return enabled_bindings_;
124 } 217 }
125 218
126 } // namespace content 219 } // namespace content
OLDNEW
« no previous file with comments | « content/public/renderer/content_renderer_client.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698