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

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

Issue 2491823005: Initialize TaskScheduler in renderers. (Closed)
Patch Set: do not enable in this CL Created 4 years, 1 month 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/renderer/render_process_impl.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
15 #include "base/command_line.h" 19 #include "base/command_line.h"
16 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
17 #include "base/feature_list.h" 21 #include "base/feature_list.h"
18 #include "base/sys_info.h" 22 #include "base/sys_info.h"
23 #include "base/task_scheduler/scheduler_worker_pool_params.h"
24 #include "base/task_scheduler/task_scheduler.h"
25 #include "base/threading/sequenced_worker_pool.h"
19 #include "content/child/site_isolation_stats_gatherer.h" 26 #include "content/child/site_isolation_stats_gatherer.h"
20 #include "content/public/common/content_features.h" 27 #include "content/public/common/content_features.h"
21 #include "content/public/common/content_switches.h" 28 #include "content/public/common/content_switches.h"
22 #include "content/public/renderer/content_renderer_client.h" 29 #include "content/public/renderer/content_renderer_client.h"
23 #include "third_party/WebKit/public/web/WebFrame.h" 30 #include "third_party/WebKit/public/web/WebFrame.h"
24 #include "v8/include/v8.h" 31 #include "v8/include/v8.h"
25 32
33 namespace base {
34 class TaskTraits;
35 }
36
26 namespace { 37 namespace {
27 38
28 const base::Feature kV8_ES2015_TailCalls_Feature { 39 const base::Feature kV8_ES2015_TailCalls_Feature {
29 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT 40 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT
30 }; 41 };
31 42
32 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ 43 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{
33 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; 44 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT};
34 45
35 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", 46 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager",
36 base::FEATURE_DISABLED_BY_DEFAULT}; 47 base::FEATURE_DISABLED_BY_DEFAULT};
37 48
38 const base::Feature kV8SerializeAgeCodeFeature{ 49 const base::Feature kV8SerializeAgeCodeFeature{
39 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT}; 50 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT};
40 51
41 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) { 52 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) {
42 if (base::FeatureList::IsEnabled(feature)) { 53 if (base::FeatureList::IsEnabled(feature)) {
43 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); 54 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
44 } 55 }
45 } 56 }
46 57
47 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { 58 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) {
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { 59 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) {
49 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); 60 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag));
50 } 61 }
51 } 62 }
52 63
64 bool MaybeInitializeTaskScheduler() {
robliao 2016/11/14 16:05:26 What's the behavior when base linked to chrome.dll
gab 2016/11/14 16:16:43 Hmm? base is linked to both but any process instan
fdoray 2016/11/15 16:30:34 --single-process only works in component builds ht
65 // TaskScheduler already exists when the renderer runs inside the browser
66 // process.
67 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
gab 2016/11/14 16:16:43 Use base::TaskScheduler::GetInstance() instead? (p
fdoray 2016/11/15 16:30:34 Done. With some changes because I don't want a Ren
68 switches::kSingleProcess)) {
69 return false;
70 }
71
72 std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector;
73 base::Callback<size_t(const base::TaskTraits& traits)>
74 worker_pool_index_for_traits_callback;
75 bool should_redirect_sequenced_worker_pool = false;
76
77 if (!content::GetContentClient()->renderer()->ShouldInitializeTaskScheduler(
78 &worker_pool_params_vector, &worker_pool_index_for_traits_callback,
79 &should_redirect_sequenced_worker_pool)) {
80 return false;
81 }
82
83 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
84 worker_pool_params_vector, worker_pool_index_for_traits_callback);
85
86 if (should_redirect_sequenced_worker_pool)
87 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess();
88
89 return true;
90 }
91
53 } // namespace 92 } // namespace
54 93
55 namespace content { 94 namespace content {
56 95
57 RenderProcessImpl::RenderProcessImpl() 96 RenderProcessImpl::RenderProcessImpl() {
58 : enabled_bindings_(0) {
59 #if defined(OS_WIN) 97 #if defined(OS_WIN)
60 // HACK: See http://b/issue?id=1024307 for rationale. 98 // HACK: See http://b/issue?id=1024307 for rationale.
61 if (GetModuleHandle(L"LPK.DLL") == NULL) { 99 if (GetModuleHandle(L"LPK.DLL") == NULL) {
62 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works 100 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works
63 // when buffering into a EMF buffer for printing. 101 // when buffering into a EMF buffer for printing.
64 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs); 102 typedef BOOL (__stdcall *GdiInitializeLanguagePack)(int LoadedShapingDLLs);
65 GdiInitializeLanguagePack gdi_init_lpk = 103 GdiInitializeLanguagePack gdi_init_lpk =
66 reinterpret_cast<GdiInitializeLanguagePack>(GetProcAddress( 104 reinterpret_cast<GdiInitializeLanguagePack>(GetProcAddress(
67 GetModuleHandle(L"GDI32.DLL"), 105 GetModuleHandle(L"GDI32.DLL"),
68 "GdiInitializeLanguagePack")); 106 "GdiInitializeLanguagePack"));
(...skipping 27 matching lines...) Expand all
96 *base::CommandLine::ForCurrentProcess(); 134 *base::CommandLine::ForCurrentProcess();
97 135
98 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { 136 if (command_line.HasSwitch(switches::kJavaScriptFlags)) {
99 std::string flags( 137 std::string flags(
100 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); 138 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags));
101 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); 139 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size()));
102 } 140 }
103 141
104 SiteIsolationStatsGatherer::SetEnabled( 142 SiteIsolationStatsGatherer::SetEnabled(
105 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); 143 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats());
144
145 initialized_task_scheduler_ = MaybeInitializeTaskScheduler();
106 } 146 }
107 147
108 RenderProcessImpl::~RenderProcessImpl() { 148 RenderProcessImpl::~RenderProcessImpl() {
109 #ifndef NDEBUG 149 #ifndef NDEBUG
110 int count = blink::WebFrame::instanceCount(); 150 int count = blink::WebFrame::instanceCount();
111 if (count) 151 if (count)
112 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; 152 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES";
113 #endif 153 #endif
114 154
155 if (initialized_task_scheduler_) {
156 DCHECK(base::TaskScheduler::GetInstance());
157 base::TaskScheduler::GetInstance()->Shutdown();
158 }
159
115 GetShutDownEvent()->Signal(); 160 GetShutDownEvent()->Signal();
116 } 161 }
117 162
118 void RenderProcessImpl::AddBindings(int bindings) { 163 void RenderProcessImpl::AddBindings(int bindings) {
119 enabled_bindings_ |= bindings; 164 enabled_bindings_ |= bindings;
120 } 165 }
121 166
122 int RenderProcessImpl::GetEnabledBindings() const { 167 int RenderProcessImpl::GetEnabledBindings() const {
123 return enabled_bindings_; 168 return enabled_bindings_;
124 } 169 }
125 170
126 } // namespace content 171 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/render_process_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698