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

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

Issue 2501033002: Redirect SequencedWorkerPool to TaskScheduler in the service process. (Closed)
Patch Set: rebase Created 4 years 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/callback.h" 11 #include "base/callback.h"
12 #include "base/command_line.h" 12 #include "base/command_line.h"
13 #include "base/environment.h" 13 #include "base/environment.h"
14 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
15 #include "base/location.h" 15 #include "base/location.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/memory/singleton.h" 18 #include "base/memory/singleton.h"
19 #include "base/path_service.h" 19 #include "base/path_service.h"
20 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
21 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/synchronization/waitable_event.h" 23 #include "base/synchronization/waitable_event.h"
24 #include "base/task_scheduler/task_scheduler.h"
24 #include "base/threading/sequenced_worker_pool.h" 25 #include "base/threading/sequenced_worker_pool.h"
25 #include "base/threading/thread_task_runner_handle.h" 26 #include "base/threading/thread_task_runner_handle.h"
27 #include "base/time/time.h"
26 #include "base/values.h" 28 #include "base/values.h"
27 #include "build/build_config.h" 29 #include "build/build_config.h"
28 #include "chrome/common/chrome_constants.h" 30 #include "chrome/common/chrome_constants.h"
29 #include "chrome/common/chrome_paths.h" 31 #include "chrome/common/chrome_paths.h"
30 #include "chrome/common/chrome_switches.h" 32 #include "chrome/common/chrome_switches.h"
31 #include "chrome/common/env_vars.h" 33 #include "chrome/common/env_vars.h"
32 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
33 #include "chrome/common/service_process_util.h" 35 #include "chrome/common/service_process_util.h"
34 #include "chrome/grit/chromium_strings.h" 36 #include "chrome/grit/chromium_strings.h"
35 #include "chrome/grit/generated_resources.h" 37 #include "chrome/grit/generated_resources.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 options.message_loop_type = base::MessageLoop::TYPE_IO; 153 options.message_loop_type = base::MessageLoop::TYPE_IO;
152 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO")); 154 io_thread_.reset(new ServiceIOThread("ServiceProcess_IO"));
153 file_thread_.reset(new base::Thread("ServiceProcess_File")); 155 file_thread_.reset(new base::Thread("ServiceProcess_File"));
154 if (!io_thread_->StartWithOptions(options) || 156 if (!io_thread_->StartWithOptions(options) ||
155 !file_thread_->StartWithOptions(options)) { 157 !file_thread_->StartWithOptions(options)) {
156 NOTREACHED(); 158 NOTREACHED();
157 Teardown(); 159 Teardown();
158 return false; 160 return false;
159 } 161 }
160 162
161 // Enable SequencedWorkerPool in the service process. 163 // Initialize TaskScheduler and redirect SequencedWorkerPool tasks to it.
162 // TODO(fdoray): Remove this once the SequencedWorkerPool to TaskScheduler 164 constexpr int kMaxTaskSchedulerThreads = 3;
163 // redirection experiment concludes https://crbug.com/622400. 165 base::TaskScheduler::CreateAndSetSimpleTaskScheduler(
164 base::SequencedWorkerPool::EnableForProcess(); 166 kMaxTaskSchedulerThreads);
167 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess();
165 168
166 blocking_pool_ = new base::SequencedWorkerPool( 169 blocking_pool_ = new base::SequencedWorkerPool(
167 3, "ServiceBlocking", base::TaskPriority::USER_VISIBLE); 170 3, "ServiceBlocking", base::TaskPriority::USER_VISIBLE);
168 171
169 // Initialize Mojo early so things can use it. 172 // Initialize Mojo early so things can use it.
170 mojo::edk::Init(); 173 mojo::edk::Init();
171 mojo_ipc_support_.reset( 174 mojo_ipc_support_.reset(
172 new mojo::edk::ScopedIPCSupport(io_thread_->task_runner())); 175 new mojo::edk::ScopedIPCSupport(io_thread_->task_runner()));
173 176
174 request_context_getter_ = new ServiceURLRequestContextGetter(); 177 request_context_getter_ = new ServiceURLRequestContextGetter();
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (blocking_pool_.get()) { 260 if (blocking_pool_.get()) {
258 // The goal is to make it impossible for chrome to 'infinite loop' during 261 // The goal is to make it impossible for chrome to 'infinite loop' during
259 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks 262 // shutdown, but to reasonably expect that all BLOCKING_SHUTDOWN tasks
260 // queued during shutdown get run. There's nothing particularly scientific 263 // queued during shutdown get run. There's nothing particularly scientific
261 // about the number chosen. 264 // about the number chosen.
262 const int kMaxNewShutdownBlockingTasks = 1000; 265 const int kMaxNewShutdownBlockingTasks = 1000;
263 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks); 266 blocking_pool_->Shutdown(kMaxNewShutdownBlockingTasks);
264 blocking_pool_ = NULL; 267 blocking_pool_ = NULL;
265 } 268 }
266 269
270 if (base::TaskScheduler::GetInstance())
271 base::TaskScheduler::GetInstance()->Shutdown();
272
267 // The NetworkChangeNotifier must be destroyed after all other threads that 273 // The NetworkChangeNotifier must be destroyed after all other threads that
268 // might use it have been shut down. 274 // might use it have been shut down.
269 network_change_notifier_.reset(); 275 network_change_notifier_.reset();
270 276
271 return true; 277 return true;
272 } 278 }
273 279
274 // This method is called when a shutdown command is received from IPC channel 280 // This method is called when a shutdown command is received from IPC channel
275 // or there was an error in the IPC channel. 281 // or there was an error in the IPC channel.
276 void ServiceProcess::Shutdown() { 282 void ServiceProcess::Shutdown() {
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 } else { 424 } else {
419 Shutdown(); 425 Shutdown();
420 } 426 }
421 } 427 }
422 } 428 }
423 429
424 ServiceProcess::~ServiceProcess() { 430 ServiceProcess::~ServiceProcess() {
425 Teardown(); 431 Teardown();
426 g_service_process = NULL; 432 g_service_process = NULL;
427 } 433 }
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