| 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/bind.h" |
| 9 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 10 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 11 #include "base/metrics/statistics_recorder.h" | 12 #include "base/metrics/statistics_recorder.h" |
| 12 #include "base/process/process_handle.h" | 13 #include "base/process/process_handle.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/task_scheduler/task_scheduler.h" | |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/threading/thread_local.h" | 18 #include "base/threading/thread_local.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 #include "content/child/child_thread_impl.h" | 20 #include "content/child/child_thread_impl.h" |
| 21 | 21 |
| 22 #if defined(OS_ANDROID) | 22 #if defined(OS_ANDROID) |
| 23 #include "base/debug/debugger.h" | 23 #include "base/debug/debugger.h" |
| 24 #endif | 24 #endif |
| 25 | 25 |
| 26 #if defined(OS_POSIX) && !defined(OS_ANDROID) | 26 #if defined(OS_POSIX) && !defined(OS_ANDROID) |
| 27 #include <signal.h> | 27 #include <signal.h> |
| 28 static void SigUSR1Handler(int signal) { } | 28 static void SigUSR1Handler(int signal) { } |
| 29 #endif | 29 #endif |
| 30 | 30 |
| 31 namespace content { | 31 namespace content { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 base::LazyInstance<base::ThreadLocalPointer<ChildProcess> > g_lazy_tls = | 35 base::LazyInstance<base::ThreadLocalPointer<ChildProcess> > g_lazy_tls = |
| 36 LAZY_INSTANCE_INITIALIZER; | 36 LAZY_INSTANCE_INITIALIZER; |
| 37 } | 37 } |
| 38 | 38 |
| 39 ChildProcess::ChildProcess() : ChildProcess(base::ThreadPriority::NORMAL) {} | 39 ChildProcess::ChildProcess( |
| 40 | 40 base::ThreadPriority io_thread_priority, |
| 41 ChildProcess::ChildProcess(base::ThreadPriority io_thread_priority) | 41 const std::vector<base::SchedulerWorkerPoolParams>& worker_pool_params, |
| 42 base::TaskScheduler::WorkerPoolIndexForTraitsCallback |
| 43 worker_pool_index_for_traits_callback) |
| 42 : ref_count_(0), | 44 : ref_count_(0), |
| 43 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, | 45 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, |
| 44 base::WaitableEvent::InitialState::NOT_SIGNALED), | 46 base::WaitableEvent::InitialState::NOT_SIGNALED), |
| 45 io_thread_("Chrome_ChildIOThread") { | 47 io_thread_("Chrome_ChildIOThread") { |
| 46 DCHECK(!g_lazy_tls.Pointer()->Get()); | 48 DCHECK(!g_lazy_tls.Pointer()->Get()); |
| 47 g_lazy_tls.Pointer()->Set(this); | 49 g_lazy_tls.Pointer()->Set(this); |
| 48 | 50 |
| 49 base::StatisticsRecorder::Initialize(); | 51 base::StatisticsRecorder::Initialize(); |
| 50 | 52 |
| 51 // Initialize TaskScheduler if not already done. A TaskScheduler may already | 53 // Initialize TaskScheduler if not already done. A TaskScheduler may already |
| 52 // exist when ChildProcess is instantiated in the browser process or in a | 54 // exist when ChildProcess is instantiated in the browser process or in a |
| 53 // test process. | 55 // test process. |
| 54 if (!base::TaskScheduler::GetInstance()) { | 56 if (!base::TaskScheduler::GetInstance()) { |
| 55 InitializeTaskScheduler(); | 57 if (worker_pool_params.empty()) { |
| 58 DCHECK(!worker_pool_index_for_traits_callback); |
| 59 constexpr int kMaxThreads = 2; |
| 60 base::TaskScheduler::CreateAndSetSimpleTaskScheduler(kMaxThreads); |
| 61 } else { |
| 62 DCHECK(worker_pool_index_for_traits_callback); |
| 63 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
| 64 worker_pool_params, std::move(worker_pool_index_for_traits_callback)); |
| 65 } |
| 66 |
| 56 DCHECK(base::TaskScheduler::GetInstance()); | 67 DCHECK(base::TaskScheduler::GetInstance()); |
| 57 initialized_task_scheduler_ = true; | 68 initialized_task_scheduler_ = true; |
| 58 } | 69 } |
| 59 | 70 |
| 60 // We can't recover from failing to start the IO thread. | 71 // We can't recover from failing to start the IO thread. |
| 61 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); | 72 base::Thread::Options thread_options(base::MessageLoop::TYPE_IO, 0); |
| 62 thread_options.priority = io_thread_priority; | 73 thread_options.priority = io_thread_priority; |
| 63 #if defined(OS_ANDROID) | 74 #if defined(OS_ANDROID) |
| 64 // TODO(reveman): Remove this in favor of setting it explicitly for each type | 75 // TODO(reveman): Remove this in favor of setting it explicitly for each type |
| 65 // of process. | 76 // of process. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 struct sigaction sa; | 181 struct sigaction sa; |
| 171 memset(&sa, 0, sizeof(sa)); | 182 memset(&sa, 0, sizeof(sa)); |
| 172 sa.sa_handler = SigUSR1Handler; | 183 sa.sa_handler = SigUSR1Handler; |
| 173 sigaction(SIGUSR1, &sa, NULL); | 184 sigaction(SIGUSR1, &sa, NULL); |
| 174 | 185 |
| 175 pause(); | 186 pause(); |
| 176 #endif // defined(OS_ANDROID) | 187 #endif // defined(OS_ANDROID) |
| 177 #endif // defined(OS_POSIX) | 188 #endif // defined(OS_POSIX) |
| 178 } | 189 } |
| 179 | 190 |
| 180 void ChildProcess::InitializeTaskScheduler() { | |
| 181 constexpr int kMaxThreads = 2; | |
| 182 base::TaskScheduler::CreateAndSetSimpleTaskScheduler(kMaxThreads); | |
| 183 } | |
| 184 | |
| 185 } // namespace content | 191 } // namespace content |
| OLD | NEW |