Chromium Code Reviews| 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 | |
| 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/task_scheduler/task_traits.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 |
| 26 namespace { | 34 namespace { |
| 27 | 35 |
| 28 const base::Feature kV8_ES2015_TailCalls_Feature { | 36 const base::Feature kV8_ES2015_TailCalls_Feature { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 43 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); | 51 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); |
| 44 } | 52 } |
| 45 } | 53 } |
| 46 | 54 |
| 47 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { | 55 void SetV8FlagIfHasSwitch(const char* switch_name, const char* v8_flag) { |
| 48 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { | 56 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switch_name)) { |
| 49 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); | 57 v8::V8::SetFlagsFromString(v8_flag, strlen(v8_flag)); |
| 50 } | 58 } |
| 51 } | 59 } |
| 52 | 60 |
| 61 bool IsSingleProcess() { | |
| 62 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 63 switches::kSingleProcess); | |
| 64 } | |
| 65 | |
| 66 enum WorkerPoolType : size_t { | |
| 67 BACKGROUND_WORKER_POOL = 0, | |
| 68 FOREGROUND_WORKER_POOL, | |
| 69 WORKER_POOL_COUNT // Always last. | |
| 70 }; | |
| 71 | |
| 72 size_t GetTaskSchedulerWorkerPoolIndexForTraits( | |
| 73 const base::TaskTraits& traits) { | |
| 74 return traits.priority() == base::TaskPriority::BACKGROUND | |
|
gab
2016/11/15 20:25:05
DCHECK(!traits.with_file_io());
fdoray
2016/11/16 16:40:52
Done.
| |
| 75 ? BACKGROUND_WORKER_POOL | |
| 76 : FOREGROUND_WORKER_POOL; | |
| 77 } | |
| 78 | |
| 79 void InitializeTaskScheduler() { | |
| 80 if (IsSingleProcess()) { | |
| 81 // If this renderer runs in the browser process, there should already be a | |
| 82 // TaskScheduler and redirection settings shouldn't be changed. | |
| 83 DCHECK(base::TaskScheduler::GetInstance()); | |
| 84 return; | |
| 85 } | |
| 86 DCHECK(!base::TaskScheduler::GetInstance()); | |
| 87 | |
| 88 int max_background_threads = 0; | |
| 89 base::TimeDelta background_reclaim_time; | |
| 90 int max_foreground_threads = 0; | |
| 91 base::TimeDelta foreground_reclaim_time; | |
| 92 bool redirect_sequenced_worker_pool = false; | |
| 93 | |
| 94 content::GetContentClient() | |
| 95 ->renderer() | |
| 96 ->GetTaskSchedulerInitializationArguments( | |
| 97 &max_background_threads, &background_reclaim_time, | |
| 98 &max_foreground_threads, &foreground_reclaim_time, | |
| 99 &redirect_sequenced_worker_pool); | |
| 100 | |
| 101 DCHECK_GT(max_background_threads, 0); | |
|
robliao
2016/11/15 20:31:51
Hitting this DCHECK and the one below seems like i
robliao
2016/11/15 20:32:36
create tasks -> run tasks
gab
2016/11/15 20:42:47
No need to CHECK IMO, DCHECK documents runtime inv
robliao
2016/11/15 20:49:08
This would be pretty fatal to the process. We alre
gab
2016/11/15 22:04:30
But the CHECK in SchedulerWorkerPoolImpl::Initiali
fdoray
2016/11/16 16:40:52
These DCHECKs will only fail if GetTaskSchedulerIn
gab
2016/11/16 16:58:06
Agreed.
| |
| 102 DCHECK(!background_reclaim_time.is_zero()); | |
| 103 DCHECK_GT(max_foreground_threads, 0); | |
| 104 DCHECK(!foreground_reclaim_time.is_zero()); | |
| 105 | |
| 106 std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector; | |
| 107 DCHECK_EQ(BACKGROUND_WORKER_POOL, worker_pool_params_vector.size()); | |
| 108 worker_pool_params_vector.emplace_back( | |
| 109 "RendererBackground", base::ThreadPriority::BACKGROUND, | |
| 110 base::SchedulerWorkerPoolParams::IORestriction::DISALLOWED, | |
| 111 max_background_threads, background_reclaim_time); | |
| 112 DCHECK_EQ(FOREGROUND_WORKER_POOL, worker_pool_params_vector.size()); | |
| 113 worker_pool_params_vector.emplace_back( | |
| 114 "RendererForeground", base::ThreadPriority::NORMAL, | |
| 115 base::SchedulerWorkerPoolParams::IORestriction::DISALLOWED, | |
| 116 max_foreground_threads, foreground_reclaim_time); | |
| 117 DCHECK_EQ(WORKER_POOL_COUNT, worker_pool_params_vector.size()); | |
| 118 | |
| 119 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | |
| 120 worker_pool_params_vector, | |
| 121 base::Bind(&GetTaskSchedulerWorkerPoolIndexForTraits)); | |
| 122 | |
| 123 if (redirect_sequenced_worker_pool) | |
| 124 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); | |
| 125 } | |
| 126 | |
| 53 } // namespace | 127 } // namespace |
| 54 | 128 |
| 55 namespace content { | 129 namespace content { |
| 56 | 130 |
| 57 RenderProcessImpl::RenderProcessImpl() | 131 RenderProcessImpl::RenderProcessImpl() |
| 58 : enabled_bindings_(0) { | 132 : enabled_bindings_(0) { |
| 59 #if defined(OS_WIN) | 133 #if defined(OS_WIN) |
| 60 // HACK: See http://b/issue?id=1024307 for rationale. | 134 // HACK: See http://b/issue?id=1024307 for rationale. |
| 61 if (GetModuleHandle(L"LPK.DLL") == NULL) { | 135 if (GetModuleHandle(L"LPK.DLL") == NULL) { |
| 62 // Makes sure lpk.dll is loaded by gdi32 to make sure ExtTextOut() works | 136 // 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(); | 170 *base::CommandLine::ForCurrentProcess(); |
| 97 | 171 |
| 98 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { | 172 if (command_line.HasSwitch(switches::kJavaScriptFlags)) { |
| 99 std::string flags( | 173 std::string flags( |
| 100 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); | 174 command_line.GetSwitchValueASCII(switches::kJavaScriptFlags)); |
| 101 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); | 175 v8::V8::SetFlagsFromString(flags.c_str(), static_cast<int>(flags.size())); |
| 102 } | 176 } |
| 103 | 177 |
| 104 SiteIsolationStatsGatherer::SetEnabled( | 178 SiteIsolationStatsGatherer::SetEnabled( |
| 105 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); | 179 GetContentClient()->renderer()->ShouldGatherSiteIsolationStats()); |
| 180 | |
| 181 InitializeTaskScheduler(); | |
| 106 } | 182 } |
| 107 | 183 |
| 108 RenderProcessImpl::~RenderProcessImpl() { | 184 RenderProcessImpl::~RenderProcessImpl() { |
| 109 #ifndef NDEBUG | 185 #ifndef NDEBUG |
| 110 int count = blink::WebFrame::instanceCount(); | 186 int count = blink::WebFrame::instanceCount(); |
| 111 if (count) | 187 if (count) |
| 112 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; | 188 DLOG(ERROR) << "WebFrame LEAKED " << count << " TIMES"; |
| 113 #endif | 189 #endif |
| 114 | 190 |
| 191 if (!IsSingleProcess()) { | |
| 192 DCHECK(base::TaskScheduler::GetInstance()); | |
| 193 base::TaskScheduler::GetInstance()->Shutdown(); | |
| 194 } | |
| 195 | |
| 115 GetShutDownEvent()->Signal(); | 196 GetShutDownEvent()->Signal(); |
| 116 } | 197 } |
| 117 | 198 |
| 118 void RenderProcessImpl::AddBindings(int bindings) { | 199 void RenderProcessImpl::AddBindings(int bindings) { |
| 119 enabled_bindings_ |= bindings; | 200 enabled_bindings_ |= bindings; |
| 120 } | 201 } |
| 121 | 202 |
| 122 int RenderProcessImpl::GetEnabledBindings() const { | 203 int RenderProcessImpl::GetEnabledBindings() const { |
| 123 return enabled_bindings_; | 204 return enabled_bindings_; |
| 124 } | 205 } |
| 125 | 206 |
| 126 } // namespace content | 207 } // namespace content |
| OLD | NEW |