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 "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 | 9 |
| 10 #include "base/base_switches.h" | 10 #include "base/base_switches.h" |
| 11 #include "base/bind.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" | |
| 26 #include "base/task_scheduler/task_scheduler.h" | |
| 24 #include "base/threading/sequenced_worker_pool.h" | 27 #include "base/threading/sequenced_worker_pool.h" |
| 25 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 29 #include "base/time/time.h" | |
| 26 #include "base/values.h" | 30 #include "base/values.h" |
| 27 #include "build/build_config.h" | 31 #include "build/build_config.h" |
| 28 #include "chrome/common/chrome_constants.h" | 32 #include "chrome/common/chrome_constants.h" |
| 29 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
| 30 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
| 31 #include "chrome/common/env_vars.h" | 35 #include "chrome/common/env_vars.h" |
| 32 #include "chrome/common/pref_names.h" | 36 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/common/service_process_util.h" | 37 #include "chrome/common/service_process_util.h" |
| 34 #include "chrome/grit/chromium_strings.h" | 38 #include "chrome/grit/chromium_strings.h" |
| 35 #include "chrome/grit/generated_resources.h" | 39 #include "chrome/grit/generated_resources.h" |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 base::Thread::Options options; | 154 base::Thread::Options options; |
| 151 options.message_loop_type = base::MessageLoop::TYPE_IO; | 155 options.message_loop_type = base::MessageLoop::TYPE_IO; |
| 152 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); | 156 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); |
| 153 file_thread_.reset(new base::Thread("ServiceProcess_File")); | 157 file_thread_.reset(new base::Thread("ServiceProcess_File")); |
| 154 if (!io_thread_->StartWithOptions(options) || | 158 if (!io_thread_->StartWithOptions(options) || |
| 155 !file_thread_->StartWithOptions(options)) { | 159 !file_thread_->StartWithOptions(options)) { |
| 156 NOTREACHED(); | 160 NOTREACHED(); |
| 157 Teardown(); | 161 Teardown(); |
| 158 return false; | 162 return false; |
| 159 } | 163 } |
| 160 blocking_pool_ = new base::SequencedWorkerPool( | 164 blocking_pool_ = new base::SequencedWorkerPool( |
|
robliao
2016/11/15 18:43:57
Should this happen after TaskScheduler Initializat
fdoray
2016/11/15 21:37:13
Done.
| |
| 161 3, "ServiceBlocking", base::TaskPriority::USER_VISIBLE); | 165 3, "ServiceBlocking", base::TaskPriority::USER_VISIBLE); |
| 162 | 166 |
| 167 // Initialize TaskScheduler and redirect SequencedWorkerPool tasks to it. | |
| 168 constexpr int kMaxTaskSchedulerThreads = 3; | |
| 169 constexpr base::TimeDelta kTaskSchedulerReclaimTime = | |
| 170 base::TimeDelta::FromSeconds(15); | |
|
robliao
2016/11/15 18:43:57
Any harm in not using the standard 30 we currently
fdoray
2016/11/15 21:37:13
Done. I thought that since the service process doe
| |
| 171 std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector; | |
| 172 worker_pool_params_vector.emplace_back( | |
| 173 "Service", base::ThreadPriority::NORMAL, | |
| 174 base::SchedulerWorkerPoolParams::IORestriction::ALLOWED, | |
| 175 kMaxTaskSchedulerThreads, kTaskSchedulerReclaimTime); | |
| 176 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | |
| 177 worker_pool_params_vector, base::Bind([](const base::TaskTraits&) { | |
| 178 // All TaskTraits are mapped to the single TaskScheduler pool in this | |
| 179 // process. | |
| 180 return static_cast<size_t>(0); | |
| 181 })); | |
| 182 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); | |
| 183 | |
| 163 // Initialize Mojo early so things can use it. | 184 // Initialize Mojo early so things can use it. |
| 164 mojo::edk::Init(); | 185 mojo::edk::Init(); |
| 165 mojo_ipc_support_.reset( | 186 mojo_ipc_support_.reset( |
| 166 new mojo::edk::ScopedIPCSupport(io_thread_->task_runner())); | 187 new mojo::edk::ScopedIPCSupport(io_thread_->task_runner())); |
| 167 | 188 |
| 168 request_context_getter_ = new ServiceURLRequestContextGetter(); | 189 request_context_getter_ = new ServiceURLRequestContextGetter(); |
| 169 | 190 |
| 170 base::FilePath user_data_dir; | 191 base::FilePath user_data_dir; |
| 171 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); | 192 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 172 base::FilePath pref_path = | 193 base::FilePath pref_path = |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 246 if (blocking_pool_.get()) { | 267 if (blocking_pool_.get()) { |
| 247 // The goal is to make it impossible for chrome to 'infinite loop' during | 268 // The goal is to make it impossible for chrome to 'infinite loop' during |
| 248 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks | 269 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks |
| 249 // queued during shutdown get run. There's nothing particularly scientific | 270 // queued during shutdown get run. There's nothing particularly scientific |
| 250 // about the number chosen. | 271 // about the number chosen. |
| 251 const int kMaxNewShutdownBlockingTasks = 1000; | 272 const int kMaxNewShutdownBlockingTasks = 1000; |
| 252 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks); | 273 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks); |
| 253 blocking_pool_ = NULL; | 274 blocking_pool_ = NULL; |
| 254 } | 275 } |
| 255 | 276 |
| 277 base::TaskScheduler::GetInstance()->Shutdown(); | |
| 278 | |
| 256 // The NetworkChangeNotifier must be destroyed after all other threads that | 279 // The NetworkChangeNotifier must be destroyed after all other threads that |
| 257 // might use it have been shut down. | 280 // might use it have been shut down. |
| 258 network_change_notifier_.reset(); | 281 network_change_notifier_.reset(); |
| 259 | 282 |
| 260 service_process_state_->SignalStopped(); | 283 service_process_state_->SignalStopped(); |
| 261 return true; | 284 return true; |
| 262 } | 285 } |
| 263 | 286 |
| 264 // This method is called when a shutdown command is received from IPC channel | 287 // This method is called when a shutdown command is received from IPC channel |
| 265 // or there was an error in the IPC channel. | 288 // or there was an error in the IPC channel. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 } else { | 431 } else { |
| 409 Shutdown(); | 432 Shutdown(); |
| 410 } | 433 } |
| 411 } | 434 } |
| 412 } | 435 } |
| 413 | 436 |
| 414 ServiceProcess::~ServiceProcess() { | 437 ServiceProcess::~ServiceProcess() { |
| 415 Teardown(); | 438 Teardown(); |
| 416 g_service_process = NULL; | 439 g_service_process = NULL; |
| 417 } | 440 } |
| OLD | NEW |