| 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 #include <vector> |
| 10 | 10 |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); | 156 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); |
| 157 file_thread_.reset(new base::Thread("ServiceProcess_File")); | 157 file_thread_.reset(new base::Thread("ServiceProcess_File")); |
| 158 if (!io_thread_->StartWithOptions(options) || | 158 if (!io_thread_->StartWithOptions(options) || |
| 159 !file_thread_->StartWithOptions(options)) { | 159 !file_thread_->StartWithOptions(options)) { |
| 160 NOTREACHED(); | 160 NOTREACHED(); |
| 161 Teardown(); | 161 Teardown(); |
| 162 return false; | 162 return false; |
| 163 } | 163 } |
| 164 | 164 |
| 165 // Initialize TaskScheduler and redirect SequencedWorkerPool tasks to it. | 165 // Initialize TaskScheduler and redirect SequencedWorkerPool tasks to it. |
| 166 constexpr int kMaxTaskSchedulerThreads = 3; | 166 using StandbyThreadPolicy = |
| 167 std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector; | 167 base::SchedulerWorkerPoolParams::StandbyThreadPolicy; |
| 168 worker_pool_params_vector.emplace_back( | 168 constexpr int kMaxBackgroundThreads = 1; |
| 169 "CloudPrintServiceProcess", base::ThreadPriority::NORMAL, | 169 constexpr int kMaxBackgroundBlockingThreads = 1; |
| 170 base::SchedulerWorkerPoolParams::StandbyThreadPolicy::LAZY, | 170 constexpr int kMaxForegroundThreads = 3; |
| 171 kMaxTaskSchedulerThreads, base::TimeDelta::FromSeconds(30), | 171 constexpr int kMaxForegroundBlockingThreads = 3; |
| 172 base::SchedulerBackwardCompatibility::INIT_COM_STA); | 172 constexpr base::TimeDelta kSuggestedReclaimTime = |
| 173 base::TimeDelta::FromSeconds(30); |
| 174 |
| 173 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( | 175 base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
| 174 worker_pool_params_vector, | 176 "CloudPrintServiceProcess", |
| 175 base::Bind([](const base::TaskTraits&) -> size_t { return 0; })); | 177 {{StandbyThreadPolicy::LAZY, kMaxBackgroundThreads, |
| 178 kSuggestedReclaimTime}, |
| 179 {StandbyThreadPolicy::LAZY, kMaxBackgroundBlockingThreads, |
| 180 kSuggestedReclaimTime}, |
| 181 {StandbyThreadPolicy::LAZY, kMaxForegroundThreads, |
| 182 kSuggestedReclaimTime}, |
| 183 {StandbyThreadPolicy::LAZY, kMaxForegroundBlockingThreads, |
| 184 kSuggestedReclaimTime, |
| 185 base::SchedulerBackwardCompatibility::INIT_COM_STA}}); |
| 186 |
| 176 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | 187 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
| 177 | 188 |
| 189 // Since SequencedWorkerPool is redirected to TaskScheduler, the value of |
| 190 // |kMaxBlockingPoolThreads| is ignored. |
| 191 constexpr int kMaxBlockingPoolThreads = 3; |
| 178 blocking_pool_ = | 192 blocking_pool_ = |
| 179 new base::SequencedWorkerPool(kMaxTaskSchedulerThreads, "ServiceBlocking", | 193 new base::SequencedWorkerPool(kMaxBlockingPoolThreads, "ServiceBlocking", |
| 180 base::TaskPriority::USER_VISIBLE); | 194 base::TaskPriority::USER_VISIBLE); |
| 181 | 195 |
| 182 // Initialize Mojo early so things can use it. | 196 // Initialize Mojo early so things can use it. |
| 183 mojo::edk::Init(); | 197 mojo::edk::Init(); |
| 184 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( | 198 mojo_ipc_support_.reset(new mojo::edk::ScopedIPCSupport( |
| 185 io_thread_->task_runner(), | 199 io_thread_->task_runner(), |
| 186 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST)); | 200 mojo::edk::ScopedIPCSupport::ShutdownPolicy::FAST)); |
| 187 | 201 |
| 188 request_context_getter_ = new ServiceURLRequestContextGetter(); | 202 request_context_getter_ = new ServiceURLRequestContextGetter(); |
| 189 | 203 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } else { | 449 } else { |
| 436 Shutdown(); | 450 Shutdown(); |
| 437 } | 451 } |
| 438 } | 452 } |
| 439 } | 453 } |
| 440 | 454 |
| 441 ServiceProcess::~ServiceProcess() { | 455 ServiceProcess::~ServiceProcess() { |
| 442 Teardown(); | 456 Teardown(); |
| 443 g_service_process = NULL; | 457 g_service_process = NULL; |
| 444 } | 458 } |
| OLD | NEW |