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 "chrome/service/service_process.h" | 5 #include "chrome/service/service_process.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | |
9 | 10 |
10 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/environment.h" | 14 #include "base/environment.h" |
14 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
15 #include "base/location.h" | 16 #include "base/location.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
18 #include "base/memory/singleton.h" | 19 #include "base/memory/singleton.h" |
19 #include "base/path_service.h" | 20 #include "base/path_service.h" |
20 #include "base/single_thread_task_runner.h" | 21 #include "base/single_thread_task_runner.h" |
21 #include "base/strings/string16.h" | 22 #include "base/strings/string16.h" |
22 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
23 #include "base/synchronization/waitable_event.h" | 24 #include "base/synchronization/waitable_event.h" |
25 #include "base/task_scheduler/scheduler_worker_pool_params.h" | |
24 #include "base/task_scheduler/task_scheduler.h" | 26 #include "base/task_scheduler/task_scheduler.h" |
25 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
26 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
27 #include "base/time/time.h" | 29 #include "base/time/time.h" |
28 #include "base/values.h" | 30 #include "base/values.h" |
29 #include "build/build_config.h" | 31 #include "build/build_config.h" |
30 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
31 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/common/env_vars.h" | 35 #include "chrome/common/env_vars.h" |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 | 140 |
139 bool ServiceProcess::Initialize(base::MessageLoopForUI* message_loop, | 141 bool ServiceProcess::Initialize(base::MessageLoopForUI* message_loop, |
140 const base::CommandLine& command_line, | 142 const base::CommandLine& command_line, |
141 ServiceProcessState* state) { | 143 ServiceProcessState* state) { |
142 #if defined(USE_GLIB) | 144 #if defined(USE_GLIB) |
143 // g_type_init has been deprecated since version 2.35. | 145 // g_type_init has been deprecated since version 2.35. |
144 #if !GLIB_CHECK_VERSION(2, 35, 0) | 146 #if !GLIB_CHECK_VERSION(2, 35, 0) |
145 // GLib type system initialization is needed for gconf. | 147 // GLib type system initialization is needed for gconf. |
146 g_type_init(); | 148 g_type_init(); |
147 #endif | 149 #endif |
148 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) | 150 #endif // defined(OS_LINUX) || defined(OS_OPENBSD) |
149 main_message_loop_ = message_loop; | 151 main_message_loop_ = message_loop; |
150 service_process_state_.reset(state); | 152 service_process_state_.reset(state); |
151 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); | 153 network_change_notifier_.reset(net::NetworkChangeNotifier::Create()); |
152 base::Thread::Options options; | 154 base::Thread::Options options; |
153 options.message_loop_type = base::MessageLoop::TYPE_IO; | 155 options.message_loop_type = base::MessageLoop::TYPE_IO; |
154 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); | 156 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); |
155 file_thread_.reset(new base::Thread("ServiceProcess_File")); | 157 file_thread_.reset(new base::Thread("ServiceProcess_File")); |
156 if (!io_thread_->StartWithOptions(options) || | 158 if (!io_thread_->StartWithOptions(options) || |
157 !file_thread_->StartWithOptions(options)) { | 159 !file_thread_->StartWithOptions(options)) { |
158 NOTREACHED(); | 160 NOTREACHED(); |
159 Teardown(); | 161 Teardown(); |
160 return false; | 162 return false; |
161 } | 163 } |
162 | 164 |
163 // Initialize TaskScheduler and redirect SequencedWorkerPool tasks to it. | 165 // Initialize TaskScheduler and redirect SequencedWorkerPool tasks to it. |
164 base::TaskScheduler::CreateAndSetSimpleTaskScheduler( | 166 constexpr int kMaxTaskSchedulerThreads = 3; |
165 "CloudPrintServiceProcess"); | 167 std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector; |
168 worker_pool_params_vector.emplace_back( | |
169 "CloudPrintServiceProcess", base::ThreadPriority::NORMAL, | |
170 base::SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY, | |
171 kMaxTaskSchedulerThreads, base::TimeDelta::FromSeconds(30)); | |
robliao
2017/03/24 00:40:17
Given that you need COM to be initialized, you'll
Lei Zhang
2017/03/24 01:15:34
Doh. That's rather embarassing.
robliao
2017/03/24 01:22:20
Happens to all of us :-)
| |
172 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | |
173 worker_pool_params_vector, | |
174 base::Bind([](const base::TaskTraits&) -> size_t { return 0; })); | |
166 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | 175 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
167 | 176 |
168 blocking_pool_ = new base::SequencedWorkerPool( | 177 blocking_pool_ = |
169 3, "ServiceBlocking", base::TaskPriority::USER_VISIBLE); | 178 new base::SequencedWorkerPool(kMaxTaskSchedulerThreads, "ServiceBlocking", |
179 base::TaskPriority::USER_VISIBLE); | |
170 | 180 |
171 // Initialize Mojo early so things can use it. | 181 // Initialize Mojo early so things can use it. |
172 mojo::edk::Init(); | 182 mojo::edk::Init(); |
173 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( | 183 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( |
174 io_thread_->task_runner(), | 184 io_thread_->task_runner(), |
175 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST)); | 185 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST)); |
176 | 186 |
177 request_context_getter_ = new ServiceURLRequestContextGetter(); | 187 request_context_getter_ = new ServiceURLRequestContextGetter(); |
178 | 188 |
179 base::FilePath user_data_dir; | 189 base::FilePath user_data_dir; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 } else { | 434 } else { |
425 Shutdown(); | 435 Shutdown(); |
426 } | 436 } |
427 } | 437 } |
428 } | 438 } |
429 | 439 |
430 ServiceProcess::~ServiceProcess() { | 440 ServiceProcess::~ServiceProcess() { |
431 Teardown(); | 441 Teardown(); |
432 g_service_process = NULL; | 442 g_service_process = NULL; |
433 } | 443 } |
OLD | NEW |