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

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

Issue 2799453002: Remove deprecated functions from components/task_scheduler_util/. (Closed)
Patch Set: 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/browser/initialization.h" 5 #include "components/task_scheduler_util/browser/initialization.h"
6 6
7 #include <map> 7 #include <map>
8 #include <string> 8 #include <string>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/task_scheduler/scheduler_worker_params.h" 11 #include "base/task_scheduler/scheduler_worker_params.h"
12 #include "base/task_scheduler/switches.h" 12 #include "base/task_scheduler/switches.h"
13 #include "base/threading/sequenced_worker_pool.h" 13 #include "base/threading/sequenced_worker_pool.h"
14 #include "components/task_scheduler_util/common/variations_util.h" 14 #include "components/task_scheduler_util/common/variations_util.h"
15 #include "components/variations/variations_associated_data.h" 15 #include "components/variations/variations_associated_data.h"
16 16
17 namespace task_scheduler_util { 17 namespace task_scheduler_util {
18 18
19 namespace { 19 namespace {
20 20
21 constexpr char kFieldTrialName[] = "BrowserScheduler"; 21 constexpr char kFieldTrialName[] = "BrowserScheduler";
22 22
23 enum WorkerPoolType : size_t {
24 BACKGROUND = 0,
25 BACKGROUND_BLOCKING,
26 FOREGROUND,
27 FOREGROUND_BLOCKING,
28 WORKER_POOL_COUNT // Always last.
29 };
30
31 } // namespace 23 } // namespace
32 24
33 std::unique_ptr<base::TaskScheduler::InitParams> 25 std::unique_ptr<base::TaskScheduler::InitParams>
34 GetBrowserTaskSchedulerInitParamsFromVariations() { 26 GetBrowserTaskSchedulerInitParamsFromVariations() {
35 std::map<std::string, std::string> variation_params; 27 std::map<std::string, std::string> variation_params;
36 if (!::variations::GetVariationParams(kFieldTrialName, &variation_params)) 28 if (!::variations::GetVariationParams(kFieldTrialName, &variation_params))
37 return nullptr; 29 return nullptr;
38 30
39 return GetTaskSchedulerInitParams( 31 return GetTaskSchedulerInitParams(
40 "", variation_params, base::SchedulerBackwardCompatibility::INIT_COM_STA); 32 "", variation_params, base::SchedulerBackwardCompatibility::INIT_COM_STA);
41 } 33 }
42 34
43 std::vector<base::SchedulerWorkerPoolParams>
44 GetBrowserWorkerPoolParamsFromVariations() {
45 const auto init_params = GetBrowserTaskSchedulerInitParamsFromVariations();
46 if (!init_params)
47 return std::vector<base::SchedulerWorkerPoolParams>();
48
49 return std::vector<base::SchedulerWorkerPoolParams>{
50 init_params->background_worker_pool_params,
51 init_params->background_blocking_worker_pool_params,
52 init_params->foreground_worker_pool_params,
53 init_params->foreground_blocking_worker_pool_params};
54 }
55
56 size_t BrowserWorkerPoolIndexForTraits(const base::TaskTraits& traits) {
57 const bool is_background =
58 traits.priority() == base::TaskPriority::BACKGROUND;
59 if (traits.may_block() || traits.with_base_sync_primitives())
60 return is_background ? BACKGROUND_BLOCKING : FOREGROUND_BLOCKING;
61 return is_background ? BACKGROUND : FOREGROUND;
62 }
63
64 void MaybePerformBrowserTaskSchedulerRedirection() { 35 void MaybePerformBrowserTaskSchedulerRedirection() {
65 // TODO(gab): Remove this when http://crbug.com/622400 concludes. 36 // TODO(gab): Remove this when http://crbug.com/622400 concludes.
66 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( 37 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
67 switches::kDisableBrowserTaskScheduler) && 38 switches::kDisableBrowserTaskScheduler) &&
68 variations::GetVariationParamValue( 39 variations::GetVariationParamValue(
69 kFieldTrialName, "RedirectSequencedWorkerPools") == "true") { 40 kFieldTrialName, "RedirectSequencedWorkerPools") == "true") {
70 const base::TaskPriority max_task_priority = 41 const base::TaskPriority max_task_priority =
71 variations::GetVariationParamValue( 42 variations::GetVariationParamValue(
72 kFieldTrialName, "CapSequencedWorkerPoolsAtUserVisible") == "true" 43 kFieldTrialName, "CapSequencedWorkerPoolsAtUserVisible") == "true"
73 ? base::TaskPriority::USER_VISIBLE 44 ? base::TaskPriority::USER_VISIBLE
74 : base::TaskPriority::HIGHEST; 45 : base::TaskPriority::HIGHEST;
75 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess( 46 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(
76 max_task_priority); 47 max_task_priority);
77 } 48 }
78 } 49 }
79 50
80 } // namespace task_scheduler_util 51 } // namespace task_scheduler_util
OLDNEW
« no previous file with comments | « components/task_scheduler_util/browser/initialization.h ('k') | components/task_scheduler_util/renderer/initialization.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698