Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: chrome/service/service_process.cc

Issue 2501033002: Redirect SequencedWorkerPool to TaskScheduler in the service process. (Closed)
Patch Set: CR robliao #15 (initialize before SWP, use 30 second reclaim time) Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
164
165 // Initialize TaskScheduler and redirect SequencedWorkerPool tasks to it.
166 constexpr int kMaxTaskSchedulerThreads = 3;
167 constexpr base::TimeDelta kTaskSchedulerReclaimTime =
168 base::TimeDelta::FromSeconds(30);
169 std::vector<base::SchedulerWorkerPoolParams> worker_pool_params_vector;
170 worker_pool_params_vector.emplace_back(
171 "Service", base::ThreadPriority::NORMAL,
172 base::SchedulerWorkerPoolParams::IORestriction::ALLOWED,
173 kMaxTaskSchedulerThreads, kTaskSchedulerReclaimTime);
174 base::TaskScheduler::CreateAndSetDefaultTaskScheduler(
175 worker_pool_params_vector, base::Bind([](const base::TaskTraits&) {
gab 2016/11/15 20:46:02 [](const base::TaskTraits&) -> size_t {} (will av
fdoray 2016/11/15 21:37:13 Done.
176 // All TaskTraits are mapped to the single TaskScheduler pool in this
177 // process.
178 return static_cast<size_t>(0);
179 }));
180 base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess();
181
160 blocking_pool_ = new base::SequencedWorkerPool( 182 blocking_pool_ = new base::SequencedWorkerPool(
161 3, "ServiceBlocking", base::TaskPriority::USER_VISIBLE); 183 3, "ServiceBlocking", base::TaskPriority::USER_VISIBLE);
162 184
163 // Initialize Mojo early so things can use it. 185 // Initialize Mojo early so things can use it.
164 mojo::edk::Init(); 186 mojo::edk::Init();
165 mojo_ipc_support_.reset( 187 mojo_ipc_support_.reset(
166 new mojo::edk::ScopedIPCSupport(io_thread_->task_runner())); 188 new mojo::edk::ScopedIPCSupport(io_thread_->task_runner()));
167 189
168 request_context_getter_ = new ServiceURLRequestContextGetter(); 190 request_context_getter_ = new ServiceURLRequestContextGetter();
169 191
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (blocking_pool_.get()) { 273 if (blocking_pool_.get()) {
252 // The goal is to make it impossible for chrome to 'infinite loop' during 274 // The goal is to make it impossible for chrome to 'infinite loop' during
253 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks 275 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks
254 // queued during shutdown get run. There's nothing particularly scientific 276 // queued during shutdown get run. There's nothing particularly scientific
255 // about the number chosen. 277 // about the number chosen.
256 const int kMaxNewShutdownBlockingTasks = 1000; 278 const int kMaxNewShutdownBlockingTasks = 1000;
257 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks); 279 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks);
258 blocking_pool_ = NULL; 280 blocking_pool_ = NULL;
259 } 281 }
260 282
283 base::TaskScheduler::GetInstance()->Shutdown();
284
261 // The NetworkChangeNotifier must be destroyed after all other threads that 285 // The NetworkChangeNotifier must be destroyed after all other threads that
262 // might use it have been shut down. 286 // might use it have been shut down.
263 network_change_notifier_.reset(); 287 network_change_notifier_.reset();
264 288
265 return true; 289 return true;
266 } 290 }
267 291
268 // This method is called when a shutdown command is received from IPC channel 292 // This method is called when a shutdown command is received from IPC channel
269 // or there was an error in the IPC channel. 293 // or there was an error in the IPC channel.
270 void ServiceProcess::Shutdown() { 294 void ServiceProcess::Shutdown() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 } else { 436 } else {
413 Shutdown(); 437 Shutdown();
414 } 438 }
415 } 439 }
416 } 440 }
417 441
418 ServiceProcess::~ServiceProcess() { 442 ServiceProcess::~ServiceProcess() {
419 Teardown(); 443 Teardown();
420 g_service_process = NULL; 444 g_service_process = NULL;
421 } 445 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698