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

Side by Side Diff: content/child/child_process.cc

Issue 2798623002: Use TaskScheduler::InitParams to initialize TaskScheduler in child processes. (Closed)
Patch Set: Created 3 years, 8 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
« no previous file with comments | « content/child/child_process.h ('k') | content/public/renderer/content_renderer_client.h » ('j') | 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/child/child_process.h" 5 #include "content/child/child_process.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/metrics/statistics_recorder.h" 12 #include "base/metrics/statistics_recorder.h"
13 #include "base/process/process_handle.h" 13 #include "base/process/process_handle.h"
14 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
15 #include "base/strings/string_number_conversions.h" 15 #include "base/strings/string_number_conversions.h"
16 #include "base/strings/utf_string_conversions.h" 16 #include "base/strings/utf_string_conversions.h"
17 #include "base/task_scheduler/task_scheduler.h"
17 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
18 #include "base/threading/thread_local.h" 19 #include "base/threading/thread_local.h"
19 #include "build/build_config.h" 20 #include "build/build_config.h"
20 #include "content/child/child_thread_impl.h" 21 #include "content/child/child_thread_impl.h"
21 22
22 #if defined(OS_ANDROID) 23 #if defined(OS_ANDROID)
23 #include "base/debug/debugger.h" 24 #include "base/debug/debugger.h"
24 #endif 25 #endif
25 26
26 #if defined(OS_POSIX) && !defined(OS_ANDROID) 27 #if defined(OS_POSIX) && !defined(OS_ANDROID)
27 #include <signal.h> 28 #include <signal.h>
28 static void SigUSR1Handler(int signal) { } 29 static void SigUSR1Handler(int signal) { }
29 #endif 30 #endif
30 31
31 namespace content { 32 namespace content {
32 33
33 namespace { 34 namespace {
34 base::LazyInstance<base::ThreadLocalPointer<ChildProcess>>::DestructorAtExit 35 base::LazyInstance<base::ThreadLocalPointer<ChildProcess>>::DestructorAtExit
35 g_lazy_tls = LAZY_INSTANCE_INITIALIZER; 36 g_lazy_tls = LAZY_INSTANCE_INITIALIZER;
36 } 37 }
37 38
38 ChildProcess::ChildProcess( 39 ChildProcess::ChildProcess(
39 base::ThreadPriority io_thread_priority, 40 base::ThreadPriority io_thread_priority,
40 const std::vector<base::SchedulerWorkerPoolParams>& worker_pool_params, 41 const std::string& task_scheduler_name,
41 base::TaskScheduler::WorkerPoolIndexForTraitsCallback 42 std::unique_ptr<base::TaskScheduler::InitParams> task_scheduler_init_params)
42 worker_pool_index_for_traits_callback)
43 : ref_count_(0), 43 : ref_count_(0),
44 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 44 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
45 base::WaitableEvent::InitialState::NOT_SIGNALED), 45 base::WaitableEvent::InitialState::NOT_SIGNALED),
46 io_thread_("Chrome_ChildIOThread") { 46 io_thread_("Chrome_ChildIOThread") {
47 DCHECK(!g_lazy_tls.Pointer()->Get()); 47 DCHECK(!g_lazy_tls.Pointer()->Get());
48 g_lazy_tls.Pointer()->Set(this); 48 g_lazy_tls.Pointer()->Set(this);
49 49
50 base::StatisticsRecorder::Initialize(); 50 base::StatisticsRecorder::Initialize();
51 51
52 // Initialize TaskScheduler if not already done. A TaskScheduler may already 52 // Initialize TaskScheduler if not already done. A TaskScheduler may already
53 // exist when ChildProcess is instantiated in the browser process or in a 53 // exist when ChildProcess is instantiated in the browser process or in a
54 // test process. 54 // test process.
55 if (!base::TaskScheduler::GetInstance()) { 55 if (!base::TaskScheduler::GetInstance()) {
56 if (worker_pool_params.empty()) { 56 if (task_scheduler_init_params) {
57 DCHECK(!worker_pool_index_for_traits_callback); 57 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
58 base::TaskScheduler::CreateAndSetSimpleTaskScheduler("ContentChild"); 58 task_scheduler_name, *task_scheduler_init_params.get());
59 } else { 59 } else {
60 DCHECK(worker_pool_index_for_traits_callback); 60 base::TaskScheduler::CreateAndSetSimpleTaskScheduler(task_scheduler_name);
61 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
62 worker_pool_params, std::move(worker_pool_index_for_traits_callback));
63 } 61 }
64 62
65 DCHECK(base::TaskScheduler::GetInstance()); 63 DCHECK(base::TaskScheduler::GetInstance());
66 initialized_task_scheduler_ = true; 64 initialized_task_scheduler_ = true;
67 } 65 }
68 66
69 // We can't recover from failing to start the IO thread. 67 // We can't recover from failing to start the IO thread.
70 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); 68 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0);
71 thread_options.priority = io_thread_priority; 69 thread_options.priority = io_thread_priority;
72 #if defined(OS_ANDROID) 70 #if defined(OS_ANDROID)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 memset(&sa, 0, sizeof(sa)); 178 memset(&sa, 0, sizeof(sa));
181 sa.sa_handler = SigUSR1Handler; 179 sa.sa_handler = SigUSR1Handler;
182 sigaction(SIGUSR1, &sa, NULL); 180 sigaction(SIGUSR1, &sa, NULL);
183 181
184 pause(); 182 pause();
185 #endif // defined(OS_ANDROID) 183 #endif // defined(OS_ANDROID)
186 #endif // defined(OS_POSIX) 184 #endif // defined(OS_POSIX)
187 } 185 }
188 186
189 } // namespace content 187 } // namespace content
OLDNEW
« no previous file with comments | « content/child/child_process.h ('k') | content/public/renderer/content_renderer_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698