| OLD | NEW |
| 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/initialization_util.h" | 5 #include "components/task_scheduler_util/initialization_util.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 return variation_params; | 117 return variation_params; |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Converts a browser-based |variation_params| to | 120 // Converts a browser-based |variation_params| to |
| 121 // std::vector<base::SchedulerWorkerPoolParams>. Returns an empty vector on | 121 // std::vector<base::SchedulerWorkerPoolParams>. Returns an empty vector on |
| 122 // failure. | 122 // failure. |
| 123 std::vector<base::SchedulerWorkerPoolParams> | 123 std::vector<base::SchedulerWorkerPoolParams> |
| 124 VariationsParamsToBrowserSchedulerWorkerPoolParams( | 124 VariationsParamsToBrowserSchedulerWorkerPoolParams( |
| 125 const std::map<std::string, std::string>& variation_params) { | 125 const std::map<std::string, std::string>& variation_params) { |
| 126 using ThreadPriority = base::ThreadPriority; | 126 using ThreadPriority = base::ThreadPriority; |
| 127 using IORestriction = base::SchedulerWorkerPoolParams::IORestriction; | |
| 128 struct SchedulerWorkerPoolPredefinedParams { | 127 struct SchedulerWorkerPoolPredefinedParams { |
| 129 const char* name; | 128 const char* name; |
| 130 ThreadPriority priority_hint; | 129 ThreadPriority priority_hint; |
| 131 IORestriction io_restriction; | |
| 132 }; | 130 }; |
| 133 static const SchedulerWorkerPoolPredefinedParams kAllPredefinedParams[] = { | 131 static const SchedulerWorkerPoolPredefinedParams kAllPredefinedParams[] = { |
| 134 {"Background", ThreadPriority::BACKGROUND, IORestriction::DISALLOWED}, | 132 {"Background", ThreadPriority::BACKGROUND}, |
| 135 {"BackgroundFileIO", ThreadPriority::BACKGROUND, IORestriction::ALLOWED}, | 133 {"BackgroundFileIO", ThreadPriority::BACKGROUND}, |
| 136 {"Foreground", ThreadPriority::NORMAL, IORestriction::DISALLOWED}, | 134 {"Foreground", ThreadPriority::NORMAL}, |
| 137 {"ForegroundFileIO", ThreadPriority::NORMAL, IORestriction::ALLOWED}, | 135 {"ForegroundFileIO", ThreadPriority::NORMAL}, |
| 138 }; | 136 }; |
| 139 static_assert(arraysize(kAllPredefinedParams) == WORKER_POOL_COUNT, | 137 static_assert(arraysize(kAllPredefinedParams) == WORKER_POOL_COUNT, |
| 140 "Mismatched Worker Pool Types and Predefined Parameters"); | 138 "Mismatched Worker Pool Types and Predefined Parameters"); |
| 141 std::vector<base::SchedulerWorkerPoolParams> params_vector; | 139 std::vector<base::SchedulerWorkerPoolParams> params_vector; |
| 142 for (const auto& predefined_params : kAllPredefinedParams) { | 140 for (const auto& predefined_params : kAllPredefinedParams) { |
| 143 const auto pair = variation_params.find(predefined_params.name); | 141 const auto pair = variation_params.find(predefined_params.name); |
| 144 if (pair == variation_params.end()) { | 142 if (pair == variation_params.end()) { |
| 145 DLOG(ERROR) << "Missing Worker Pool Configuration: " | 143 DLOG(ERROR) << "Missing Worker Pool Configuration: " |
| 146 << predefined_params.name; | 144 << predefined_params.name; |
| 147 return std::vector<base::SchedulerWorkerPoolParams>(); | 145 return std::vector<base::SchedulerWorkerPoolParams>(); |
| 148 } | 146 } |
| 149 | 147 |
| 150 const WorkerPoolVariationValues variation_values = | 148 const WorkerPoolVariationValues variation_values = |
| 151 StringToWorkerPoolVariationValues(pair->second); | 149 StringToWorkerPoolVariationValues(pair->second); |
| 152 | 150 |
| 153 if (variation_values.threads <= 0 || | 151 if (variation_values.threads <= 0 || |
| 154 variation_values.detach_period.is_zero()) { | 152 variation_values.detach_period.is_zero()) { |
| 155 DLOG(ERROR) << "Invalid Worker Pool Configuration: " << | 153 DLOG(ERROR) << "Invalid Worker Pool Configuration: " << |
| 156 predefined_params.name << " [" << pair->second << "]"; | 154 predefined_params.name << " [" << pair->second << "]"; |
| 157 return std::vector<base::SchedulerWorkerPoolParams>(); | 155 return std::vector<base::SchedulerWorkerPoolParams>(); |
| 158 } | 156 } |
| 159 | 157 |
| 160 params_vector.emplace_back(predefined_params.name, | 158 params_vector.emplace_back(predefined_params.name, |
| 161 predefined_params.priority_hint, | 159 predefined_params.priority_hint, |
| 162 predefined_params.io_restriction, | |
| 163 variation_values.standby_thread_policy, | 160 variation_values.standby_thread_policy, |
| 164 variation_values.threads, | 161 variation_values.threads, |
| 165 variation_values.detach_period); | 162 variation_values.detach_period); |
| 166 } | 163 } |
| 167 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); | 164 DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); |
| 168 return params_vector; | 165 return params_vector; |
| 169 } | 166 } |
| 170 | 167 |
| 171 } // namespace | 168 } // namespace |
| 172 | 169 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 194 switches::kDisableBrowserTaskScheduler) && | 191 switches::kDisableBrowserTaskScheduler) && |
| 195 sequenced_worker_pool_param != variation_params.end() && | 192 sequenced_worker_pool_param != variation_params.end() && |
| 196 sequenced_worker_pool_param->second == "true") { | 193 sequenced_worker_pool_param->second == "true") { |
| 197 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | 194 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
| 198 } else { | 195 } else { |
| 199 base::SequencedWorkerPool::EnableForProcess(); | 196 base::SequencedWorkerPool::EnableForProcess(); |
| 200 } | 197 } |
| 201 } | 198 } |
| 202 | 199 |
| 203 } // namespace task_scheduler_util | 200 } // namespace task_scheduler_util |
| OLD | NEW |