| 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>(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 switches::kDisableBrowserTaskScheduler) && | 192 switches::kDisableBrowserTaskScheduler) && |
| 195 sequenced_worker_pool_param != variation_params.end() && | 193 sequenced_worker_pool_param != variation_params.end() && |
| 196 sequenced_worker_pool_param->second == "true") { | 194 sequenced_worker_pool_param->second == "true") { |
| 197 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); | 195 base::SequencedWorkerPool::EnableWithRedirectionToTaskSchedulerForProcess(); |
| 198 } else { | 196 } else { |
| 199 base::SequencedWorkerPool::EnableForProcess(); | 197 base::SequencedWorkerPool::EnableForProcess(); |
| 200 } | 198 } |
| 201 } | 199 } |
| 202 | 200 |
| 203 } // namespace task_scheduler_util | 201 } // namespace task_scheduler_util |
| OLD | NEW |