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

Side by Side Diff: components/task_scheduler_util/common/variations_util.cc

Issue 2568793003: Control TaskScheduler initialization params in renderers via field trial. (Closed)
Patch Set: do not define command line functions on ios Created 3 years, 11 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/common/variations_util.h" 5 #include "components/task_scheduler_util/common/variations_util.h"
6 6
7 #include "base/command_line.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
9 #include "base/strings/string_piece.h" 10 #include "base/strings/string_piece.h"
10 #include "base/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "base/strings/string_util.h"
11 #include "base/task_scheduler/initialization_util.h" 13 #include "base/task_scheduler/initialization_util.h"
12 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "components/variations/variations_associated_data.h"
13 16
14 namespace task_scheduler_util { 17 namespace task_scheduler_util {
15 18
16 namespace { 19 namespace {
17 20
18 struct SchedulerCustomizableWorkerPoolParams { 21 struct SchedulerCustomizableWorkerPoolParams {
19 base::SchedulerWorkerPoolParams::StandbyThreadPolicy standby_thread_policy; 22 base::SchedulerWorkerPoolParams::StandbyThreadPolicy standby_thread_policy;
20 int max_threads = 0; 23 int max_threads = 0;
21 base::TimeDelta detach_period; 24 base::TimeDelta detach_period;
22 }; 25 };
23 26
27 #if !defined(OS_IOS)
28 constexpr char kTaskSchedulerVariationParamsSwitch[] =
29 "task-scheduler-variation-params";
30
31 constexpr char kSeparator[] = "|";
32
33 bool ContainsSeparator(const std::string& str) {
34 return str.find(kSeparator) != std::string::npos;
35 }
36 #endif // !defined(OS_IOS)
37
24 // Converts |pool_descriptor| to a SchedulerWorkerPoolVariableParams. Returns a 38 // Converts |pool_descriptor| to a SchedulerWorkerPoolVariableParams. Returns a
25 // default SchedulerWorkerPoolVariableParams on failure. 39 // default SchedulerWorkerPoolVariableParams on failure.
26 // 40 //
27 // |pool_descriptor| is a semi-colon separated value string with the following 41 // |pool_descriptor| is a semi-colon separated value string with the following
28 // items: 42 // items:
29 // 0. Minimum Thread Count (int) 43 // 0. Minimum Thread Count (int)
30 // 1. Maximum Thread Count (int) 44 // 1. Maximum Thread Count (int)
31 // 2. Thread Count Multiplier (double) 45 // 2. Thread Count Multiplier (double)
32 // 3. Thread Count Offset (int) 46 // 3. Thread Count Offset (int)
33 // 4. Detach Time in Milliseconds (int) 47 // 4. Detach Time in Milliseconds (int)
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 112 }
99 worker_pool_params_vector.emplace_back( 113 worker_pool_params_vector.emplace_back(
100 worker_pool_name, constant_worker_pool_params.priority_hint(), 114 worker_pool_name, constant_worker_pool_params.priority_hint(),
101 variable_worker_pool_params.standby_thread_policy, 115 variable_worker_pool_params.standby_thread_policy,
102 variable_worker_pool_params.max_threads, 116 variable_worker_pool_params.max_threads,
103 variable_worker_pool_params.detach_period); 117 variable_worker_pool_params.detach_period);
104 } 118 }
105 return worker_pool_params_vector; 119 return worker_pool_params_vector;
106 } 120 }
107 121
122 #if !defined(OS_IOS)
123 void AddVariationParamsToCommandLine(base::StringPiece key_prefix,
124 base::CommandLine* command_line) {
125 DCHECK(command_line);
126
127 std::map<std::string, std::string> variation_params;
128 if (!variations::GetVariationParams("BrowserScheduler", &variation_params))
129 return;
130
131 std::vector<std::string> parts;
132 for (const auto& key_value : variation_params) {
133 if (base::StartsWith(key_value.first, key_prefix,
134 base::CompareCase::SENSITIVE)) {
135 if (ContainsSeparator(key_value.first) ||
136 ContainsSeparator(key_value.second)) {
137 DLOG(ERROR)
138 << "Unexpected Character in Task Scheduler Variation Params: "
139 << key_value.first << " [" << key_value.second << "]";
140 return;
141 }
142 parts.push_back(key_value.first);
143 parts.push_back(key_value.second);
144 }
145 }
146
147 if (!parts.empty()) {
148 command_line->AppendSwitchASCII(kTaskSchedulerVariationParamsSwitch,
149 base::JoinString(parts, kSeparator));
150 }
151 }
152
153 std::map<std::string, std::string> GetVariationParamsFromCommandLine(
154 const base::CommandLine& command_line) {
155 const auto serialized_variation_params =
156 command_line.GetSwitchValueASCII(kTaskSchedulerVariationParamsSwitch);
157 const auto parts =
158 base::SplitStringPiece(serialized_variation_params, kSeparator,
159 base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
160 std::map<std::string, std::string> variation_params;
161 for (auto it = parts.begin(); it != parts.end(); ++it) {
162 base::StringPiece key = *it;
163 ++it;
164 if (it == parts.end()) {
165 NOTREACHED();
166 return std::map<std::string, std::string>();
167 }
168 base::StringPiece value = *it;
169 variation_params[key.as_string()] = value.as_string();
170 }
171 return variation_params;
172 }
173 #endif // !defined(OS_IOS)
gab 2017/01/06 18:48:39 style nit: two spaces before // (and elsewhere)
174
108 } // namespace task_scheduler_util 175 } // namespace task_scheduler_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698