OLD | NEW |
---|---|
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/callback.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/scheduler_worker_pool_params.h" | |
25 #include "base/task_scheduler/task_scheduler.h" | |
26 #include "base/threading/sequenced_worker_pool.h" | |
19 #include "content/child/site_isolation_stats_gatherer.h" | 27 #include "content/child/site_isolation_stats_gatherer.h" |
20 #include "content/public/common/content_features.h" | 28 #include "content/public/common/content_features.h" |
21 #include "content/public/common/content_switches.h" | 29 #include "content/public/common/content_switches.h" |
22 #include "content/public/renderer/content_renderer_client.h" | 30 #include "content/public/renderer/content_renderer_client.h" |
23 #include "third_party/WebKit/public/web/WebFrame.h" | 31 #include "third_party/WebKit/public/web/WebFrame.h" |
24 #include "v8/include/v8.h" | 32 #include "v8/include/v8.h" |
25 | 33 |
34 namespace base { | |
35 class TaskTraits; | |
36 } // namespace | |
37 | |
26 namespace { | 38 namespace { |
27 | 39 |
28 const base::Feature kV8_ES2015_TailCalls_Feature { | 40 const base::Feature kV8_ES2015_TailCalls_Feature { |
29 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT | 41 "V8_ES2015_TailCalls", base::FEATURE_DISABLED_BY_DEFAULT |
30 }; | 42 }; |
31 | 43 |
32 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ | 44 const base::Feature kV8_ES2016_ExplicitTailCalls_Feature{ |
33 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; | 45 "V8_ES2016_ExplicitTailCalls", base::FEATURE_DISABLED_BY_DEFAULT}; |
34 | 46 |
35 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", | 47 const base::Feature kV8SerializeEagerFeature{"V8_Serialize_Eager", |
36 base::FEATURE_DISABLED_BY_DEFAULT}; | 48 base::FEATURE_DISABLED_BY_DEFAULT}; |
37 | 49 |
38 const base::Feature kV8SerializeAgeCodeFeature{ | 50 const base::Feature kV8SerializeAgeCodeFeature{ |
39 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT}; | 51 "V8_Serialize_Age_Code", base::FEATURE_DISABLED_BY_DEFAULT}; |
40 | 52 |
41 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) { | 53 void SetV8FlagIfFeature(const base::Feature& feature, const char* v8_flag) { |
42 if (base::FeatureList::IsEnabled(feature)) { | 54 if (base::FeatureList::IsEnabled(feature)) { |
43 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); | 55 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); |
44 } | 56 } |
45 } | 57 } |
46 | 58 |
47 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { | 59 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { |
48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { | 60 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { |
49 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); | 61 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); |
50 } | 62 } |
51 } | 63 } |
52 | 64 |
65 bool IsSingleProcess() { | |
66 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
67 switches::kSingleProcess); | |
68 } | |
69 | |
70 void InitializeTaskScheduler() { | |
71 if (IsSingleProcess()) { | |
72 // If this renderer runs in the browser process, there should already be a | |
73 // TaskScheduler and redirection settings shouldn't be changed. | |
74 DCHECK(base::TaskScheduler::GetInstance()); | |
75 return; | |
76 } | |
77 DCHECK(!base::TaskScheduler::GetInstance()); | |
78 | |
79 std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector; | |
80 base::Callback<size_t(const base::TaskTraits& traits)> | |
gab
2016/11/18 18:32:00
Feels like this type should be defined somewhere.
| |
81 worker_pool_index_for_traits_callback; | |
82 bool redirect_sequenced_worker_pool = false; | |
83 | |
84 content::GetContentClient() | |
85 ->renderer() | |
86 ->GetTaskSchedulerInitializationArguments( | |
87 &worker_pool_params_vector, &worker_pool_index_for_traits_callback, | |
88 &redirect_sequenced_worker_pool); | |
89 DCHECK(!worker_pool_params_vector.empty()); | |
90 DCHECK(worker_pool_index_for_traits_callback); | |
91 | |
92 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | |
93 worker_pool_params_vector, worker_pool_index_for_traits_callback); | |
94 | |
95 if (redirect_sequenced_worker_pool) | |
96 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); | |
gab
2016/11/18 18:32:00
else EnableForProcess?
(won't there be a clash wi
| |
97 } | |
98 | |
53 } // namespace | 99 } // namespace |
54 | 100 |
55 namespace content { | 101 namespace content { |
56 | 102 |
57 RenderProcessImpl::RenderProcessImpl() | 103 RenderProcessImpl::RenderProcessImpl() |
58 : enabled_bindings_(0) { | 104 : enabled_bindings_(0) { |
59 #if defined(OS_WIN) | 105 #if defined(OS_WIN) |
60 // HACK: See http://b/issue?id=1024307 for rationale. | 106 // HACK: See http://b/issue?id=1024307 for rationale. |
61 if (GetModuleHandle(L"LPK.DLL") == NULL) { | 107 if (GetModuleHandle(L"LPK.DLL") == NULL) { |
62 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works | 108 // 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 Loading... | |
96 *base::CommandLine::ForCurrentProcess(); | 142 *base::CommandLine::ForCurrentProcess(); |
97 | 143 |
98 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { | 144 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { |
99 std::string flags( | 145 std::string flags( |
100 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); | 146 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); |
101 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); | 147 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); |
102 } | 148 } |
103 | 149 |
104 SiteIsolationStatsGatherer::SetEnabled( | 150 SiteIsolationStatsGatherer::SetEnabled( |
105 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); | 151 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); |
152 | |
153 InitializeTaskScheduler(); | |
106 } | 154 } |
107 | 155 |
108 RenderProcessImpl::~RenderProcessImpl() { | 156 RenderProcessImpl::~RenderProcessImpl() { |
109 #ifndef NDEBUG | 157 #ifndef NDEBUG |
110 int count = blink::WebFrame::instanceCount(); | 158 int count = blink::WebFrame::instanceCount(); |
111 if (count) | 159 if (count) |
112 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; | 160 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; |
113 #endif | 161 #endif |
114 | 162 |
163 if (!IsSingleProcess()) { | |
164 DCHECK(base::TaskScheduler::GetInstance()); | |
165 base::TaskScheduler::GetInstance()->Shutdown(); | |
166 } | |
167 | |
115 GetShutDownEvent()->Signal(); | 168 GetShutDownEvent()->Signal(); |
116 } | 169 } |
117 | 170 |
118 void RenderProcessImpl::AddBindings(int bindings) { | 171 void RenderProcessImpl::AddBindings(int bindings) { |
119 enabled_bindings_ |= bindings; | 172 enabled_bindings_ |= bindings; |
120 } | 173 } |
121 | 174 |
122 int RenderProcessImpl::GetEnabledBindings() const { | 175 int RenderProcessImpl::GetEnabledBindings() const { |
123 return enabled_bindings_; | 176 return enabled_bindings_; |
124 } | 177 } |
125 | 178 |
126 } // namespace content | 179 } // namespace content |
OLD | NEW |