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

Side by Side Diff: components/task_scheduler_util/renderer/initialization.cc

Issue 2788223002: Generate TaskScheduler::InitParams from components/task_scheduler_util/. (Closed)
Patch Set: fix-build-error Created 3 years, 8 months 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 | « components/task_scheduler_util/renderer/initialization.h ('k') | 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/task_scheduler_util/renderer/initialization.h" 5 #include "components/task_scheduler_util/renderer/initialization.h"
6 6
7 #include <map>
8 #include <string>
9
10 #include "base/command_line.h" 7 #include "base/command_line.h"
11 #include "base/logging.h"
12 #include "base/task_scheduler/task_traits.h" 8 #include "base/task_scheduler/task_traits.h"
13 #include "base/threading/platform_thread.h"
14 #include "components/task_scheduler_util/common/variations_util.h" 9 #include "components/task_scheduler_util/common/variations_util.h"
15 10
16 namespace task_scheduler_util { 11 namespace task_scheduler_util {
17 12
18 namespace { 13 namespace {
19 14
20 enum WorkerPoolType : size_t { 15 enum WorkerPoolType : size_t {
21 BACKGROUND = 0, 16 BACKGROUND = 0,
22 BACKGROUND_BLOCKING, 17 BACKGROUND_BLOCKING,
23 FOREGROUND, 18 FOREGROUND,
24 FOREGROUND_BLOCKING, 19 FOREGROUND_BLOCKING,
25 WORKER_POOL_COUNT // Always last. 20 WORKER_POOL_COUNT // Always last.
26 }; 21 };
27 22
28 } // namespace 23 } // namespace
29 24
25 std::unique_ptr<base::TaskScheduler::InitParams>
26 GetRendererTaskSchedulerInitParamsFromCommandLine() {
27 return GetTaskSchedulerInitParams(
28 "Renderer", GetVariationParamsFromCommandLine(
29 *base::CommandLine::ForCurrentProcess()));
30 }
31
30 std::vector<base::SchedulerWorkerPoolParams> GetRendererWorkerPoolParams() { 32 std::vector<base::SchedulerWorkerPoolParams> GetRendererWorkerPoolParams() {
31 using ThreadPriority = base::ThreadPriority; 33 const auto init_params = GetRendererTaskSchedulerInitParamsFromCommandLine();
32 std::vector<SchedulerImmutableWorkerPoolParams> immutable_worker_pool_params; 34 if (!init_params)
33 DCHECK_EQ(BACKGROUND, immutable_worker_pool_params.size()); 35 return std::vector<base::SchedulerWorkerPoolParams>();
34 immutable_worker_pool_params.emplace_back("RendererBackground", 36
35 ThreadPriority::BACKGROUND); 37 return std::vector<base::SchedulerWorkerPoolParams>{
36 DCHECK_EQ(BACKGROUND_BLOCKING, immutable_worker_pool_params.size()); 38 init_params->background_worker_pool_params,
37 immutable_worker_pool_params.emplace_back("RendererBackgroundBlocking", 39 init_params->background_blocking_worker_pool_params,
38 ThreadPriority::BACKGROUND); 40 init_params->foreground_worker_pool_params,
39 DCHECK_EQ(FOREGROUND, immutable_worker_pool_params.size()); 41 init_params->foreground_blocking_worker_pool_params};
40 immutable_worker_pool_params.emplace_back("RendererForeground",
41 ThreadPriority::NORMAL);
42 DCHECK_EQ(FOREGROUND_BLOCKING, immutable_worker_pool_params.size());
43 immutable_worker_pool_params.emplace_back("RendererForegroundBlocking",
44 ThreadPriority::NORMAL);
45 return GetWorkerPoolParams(immutable_worker_pool_params,
46 GetVariationParamsFromCommandLine(
47 *base::CommandLine::ForCurrentProcess()));
48 } 42 }
49 43
50 size_t RendererWorkerPoolIndexForTraits(const base::TaskTraits& traits) { 44 size_t RendererWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
51 const bool is_background = 45 const bool is_background =
52 traits.priority() == base::TaskPriority::BACKGROUND; 46 traits.priority() == base::TaskPriority::BACKGROUND;
53 if (traits.may_block() || traits.with_base_sync_primitives()) 47 if (traits.may_block() || traits.with_base_sync_primitives())
54 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING; 48 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING;
55 return is_background ? BACKGROUND : FOREGROUND; 49 return is_background ? BACKGROUND : FOREGROUND;
56 } 50 }
57 51
58 } // namespace task_scheduler_util 52 } // namespace task_scheduler_util
OLDNEW
« no previous file with comments | « components/task_scheduler_util/renderer/initialization.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698