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/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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/metrics/statistics_recorder.h" | 11 #include "base/metrics/statistics_recorder.h" |
12 #include "base/process/process_handle.h" | 12 #include "base/process/process_handle.h" |
13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/task_scheduler/task_scheduler.h" |
16 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
17 #include "base/threading/thread_local.h" | 18 #include "base/threading/thread_local.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "content/child/child_thread_impl.h" | 20 #include "content/child/child_thread_impl.h" |
20 | 21 |
21 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
22 #include "base/debug/debugger.h" | 23 #include "base/debug/debugger.h" |
23 #endif | 24 #endif |
24 | 25 |
25 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 26 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
(...skipping 14 matching lines...) Expand all Loading... |
40 ChildProcess::ChildProcess(base::ThreadPriority io_thread_priority) | 41 ChildProcess::ChildProcess(base::ThreadPriority io_thread_priority) |
41 : ref_count_(0), | 42 : ref_count_(0), |
42 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 43 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
43 base::WaitableEvent::InitialState::NOT_SIGNALED), | 44 base::WaitableEvent::InitialState::NOT_SIGNALED), |
44 io_thread_("Chrome_ChildIOThread") { | 45 io_thread_("Chrome_ChildIOThread") { |
45 DCHECK(!g_lazy_tls.Pointer()->Get()); | 46 DCHECK(!g_lazy_tls.Pointer()->Get()); |
46 g_lazy_tls.Pointer()->Set(this); | 47 g_lazy_tls.Pointer()->Set(this); |
47 | 48 |
48 base::StatisticsRecorder::Initialize(); | 49 base::StatisticsRecorder::Initialize(); |
49 | 50 |
| 51 // Initialize TaskScheduler if not already done. A TaskScheduler may already |
| 52 // exist when ChildProcess is instantiated in the browser process or in a |
| 53 // test process. |
| 54 if (!base::TaskScheduler::GetInstance()) { |
| 55 InitializeTaskScheduler(); |
| 56 DCHECK(base::TaskScheduler::GetInstance()); |
| 57 initialized_task_scheduler_ = true; |
| 58 } |
| 59 |
50 // We can't recover from failing to start the IO thread. | 60 // We can't recover from failing to start the IO thread. |
51 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 61 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
52 thread_options.priority = io_thread_priority; | 62 thread_options.priority = io_thread_priority; |
53 #if defined(OS_ANDROID) | 63 #if defined(OS_ANDROID) |
54 // TODO(reveman): Remove this in favor of setting it explicitly for each type | 64 // TODO(reveman): Remove this in favor of setting it explicitly for each type |
55 // of process. | 65 // of process. |
56 thread_options.priority = base::ThreadPriority::DISPLAY; | 66 thread_options.priority = base::ThreadPriority::DISPLAY; |
57 #endif | 67 #endif |
58 CHECK(io_thread_.StartWithOptions(thread_options)); | 68 CHECK(io_thread_.StartWithOptions(thread_options)); |
59 } | 69 } |
(...skipping 13 matching lines...) Expand all Loading... |
73 main_thread_.reset(); | 83 main_thread_.reset(); |
74 } else { | 84 } else { |
75 // Leak the main_thread_. See a comment in | 85 // Leak the main_thread_. See a comment in |
76 // RenderThreadImpl::ShouldBeDestroyed. | 86 // RenderThreadImpl::ShouldBeDestroyed. |
77 main_thread_.release(); | 87 main_thread_.release(); |
78 } | 88 } |
79 } | 89 } |
80 | 90 |
81 g_lazy_tls.Pointer()->Set(NULL); | 91 g_lazy_tls.Pointer()->Set(NULL); |
82 io_thread_.Stop(); | 92 io_thread_.Stop(); |
| 93 |
| 94 if (initialized_task_scheduler_) { |
| 95 DCHECK(base::TaskScheduler::GetInstance()); |
| 96 base::TaskScheduler::GetInstance()->Shutdown(); |
| 97 } |
83 } | 98 } |
84 | 99 |
85 ChildThreadImpl* ChildProcess::main_thread() { | 100 ChildThreadImpl* ChildProcess::main_thread() { |
86 return main_thread_.get(); | 101 return main_thread_.get(); |
87 } | 102 } |
88 | 103 |
89 void ChildProcess::set_main_thread(ChildThreadImpl* thread) { | 104 void ChildProcess::set_main_thread(ChildThreadImpl* thread) { |
90 main_thread_.reset(thread); | 105 main_thread_.reset(thread); |
91 } | 106 } |
92 | 107 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 struct sigaction sa; | 170 struct sigaction sa; |
156 memset(&sa, 0, sizeof(sa)); | 171 memset(&sa, 0, sizeof(sa)); |
157 sa.sa_handler = SigUSR1Handler; | 172 sa.sa_handler = SigUSR1Handler; |
158 sigaction(SIGUSR1, &sa, NULL); | 173 sigaction(SIGUSR1, &sa, NULL); |
159 | 174 |
160 pause(); | 175 pause(); |
161 #endif // defined(OS_ANDROID) | 176 #endif // defined(OS_ANDROID) |
162 #endif // defined(OS_POSIX) | 177 #endif // defined(OS_POSIX) |
163 } | 178 } |
164 | 179 |
| 180 void ChildProcess::InitializeTaskScheduler() { |
| 181 constexpr int kMaxThreads = 2; |
| 182 base::TaskScheduler::CreateAndSetSimpleTaskScheduler(kMaxThreads); |
| 183 } |
| 184 |
165 } // namespace content | 185 } // namespace content |
OLD | NEW |