Chromium Code Reviews| Index: components/task_scheduler_util/initialization_util.cc |
| diff --git a/components/task_scheduler_util/initialization_util.cc b/components/task_scheduler_util/initialization_util.cc |
| index ca94f42171117f036be7702fe7e8116de4395bcf..926d0fa88a8818b98556cb2a0846ddd8b9cd7583 100644 |
| --- a/components/task_scheduler_util/initialization_util.cc |
| +++ b/components/task_scheduler_util/initialization_util.cc |
| @@ -5,6 +5,8 @@ |
| #include "components/task_scheduler_util/initialization_util.h" |
| #include <algorithm> |
| +#include <map> |
| +#include <string> |
| #include <vector> |
| #include "base/bind.h" |
| @@ -14,9 +16,11 @@ |
| #include "base/strings/string_split.h" |
| #include "base/sys_info.h" |
| #include "base/task_scheduler/scheduler_worker_pool_params.h" |
| +#include "base/task_scheduler/switches.h" |
| #include "base/task_scheduler/task_scheduler.h" |
| #include "base/task_scheduler/task_traits.h" |
| #include "base/time/time.h" |
|
fdoray
2016/11/16 19:23:59
#include "build/build_config.h"
robliao
2016/11/16 19:42:55
Done.
|
| +#include "components/variations/variations_associated_data.h" |
| namespace task_scheduler_util { |
| @@ -89,10 +93,28 @@ size_t WorkerPoolIndexForTraits(const base::TaskTraits& traits) { |
| return is_background ? BACKGROUND_WORKER_POOL : FOREGROUND_WORKER_POOL; |
| } |
| -} // namespace |
| +std::map<std::string, std::string> GetDefaultBrowserVariationParams() { |
| + std::map<std::string, std::string> variation_params; |
| +#if defined(OS_ANDROID) || defined(OS_IOS) |
| + variation_params["Background"] = "2;8;0.1;0;30000"; |
| + variation_params["BackgroundFileIO"] = "2;8;0.1;0;30000"; |
| + variation_params["Foreground"] = "3;8;0.3;0;30000"; |
| + variation_params["ForegroundFileIO"] = "3;8;0.3;0;30000"; |
| +#else |
| + variation_params["Background"] = "3;8;0.1;0;30000"; |
| + variation_params["BackgroundFileIO"] = "3;8;0.1;0;30000"; |
| + variation_params["Foreground"] = "8;32;0.3;0;30000"; |
| + variation_params["ForegroundFileIO"] = "8;32;0.3;0;30000"; |
| +#endif // defined(OS_ANDROID) || defined(OS_IOS) |
| + return variation_params; |
| +} |
| -bool InitializeDefaultTaskScheduler( |
| - const std::map<std::string, std::string>& variation_params) { |
| +// Converts a browser-based |variation_params| to |
| +// std::vector<base::SchedulerWOrkerPoolParams>. Returns an empty vector on |
|
fdoray
2016/11/16 19:23:59
WO -> Wo
robliao
2016/11/16 19:42:55
Done.
|
| +// failure. |
| +std::vector<base::SchedulerWorkerPoolParams> |
| +VariationsParamsToBrowserSchedulerWorkerPoolParams( |
| + std::map<std::string, std::string> variation_params) { |
|
fdoray
2016/11/16 19:23:59
const std::map<>&
robliao
2016/11/16 19:42:55
Done.
|
| using ThreadPriority = base::ThreadPriority; |
| using IORestriction = base::SchedulerWorkerPoolParams::IORestriction; |
| struct SchedulerWorkerPoolPredefinedParams { |
| @@ -108,14 +130,13 @@ bool InitializeDefaultTaskScheduler( |
| }; |
| static_assert(arraysize(kAllPredefinedParams) == WORKER_POOL_COUNT, |
| "Mismatched Worker Pool Types and Predefined Parameters"); |
| - |
| std::vector<base::SchedulerWorkerPoolParams> params_vector; |
| for (const auto& predefined_params : kAllPredefinedParams) { |
| const auto pair = variation_params.find(predefined_params.name); |
| if (pair == variation_params.end()) { |
| DLOG(ERROR) << "Missing Worker Pool Configuration: " |
| << predefined_params.name; |
| - return false; |
| + return std::vector<base::SchedulerWorkerPoolParams>(); |
| } |
| const WorkerPoolVariationValues variation_values = |
| @@ -125,7 +146,7 @@ bool InitializeDefaultTaskScheduler( |
| variation_values.detach_period.is_zero()) { |
| DLOG(ERROR) << "Invalid Worker Pool Configuration: " << |
| predefined_params.name << " [" << pair->second << "]"; |
| - return false; |
| + return std::vector<base::SchedulerWorkerPoolParams>(); |
| } |
| params_vector.emplace_back(predefined_params.name, |
| @@ -134,13 +155,42 @@ bool InitializeDefaultTaskScheduler( |
| variation_values.threads, |
| variation_values.detach_period); |
| } |
| - |
| DCHECK_EQ(WORKER_POOL_COUNT, params_vector.size()); |
| + return params_vector; |
| +} |
| + |
| +} // namespace |
| +void InitializeDefaultBrowserTaskScheduler() { |
| + static constexpr char kFieldTrialName[] = "BrowserScheduler"; |
|
gab
2016/11/16 19:32:17
No static required for constexpr I think?
robliao
2016/11/16 19:42:56
See http://stackoverflow.com/questions/13865842/do
|
| + std::map<std::string, std::string> variation_params; |
| + if (!variations::GetVariationParams(kFieldTrialName, &variation_params)) { |
| + variation_params = GetDefaultBrowserVariationParams(); |
|
fdoray
2016/11/16 19:23:59
no braces
robliao
2016/11/16 19:42:56
Done.
|
| + } |
|
gab
2016/11/16 19:32:17
nit: no {}
robliao
2016/11/16 19:42:56
Done.
|
| + |
| + auto params_vector = |
| + VariationsParamsToBrowserSchedulerWorkerPoolParams(variation_params); |
| + if (params_vector.empty()) { |
| + variation_params = GetDefaultBrowserVariationParams(); |
| + params_vector = |
| + VariationsParamsToBrowserSchedulerWorkerPoolParams(variation_params); |
| + DCHECK(!params_vector.empty()); |
| + } |
| base::TaskScheduler::CreateAndSetDefaultTaskScheduler( |
| params_vector, base::Bind(WorkerPoolIndexForTraits)); |
| - return true; |
| + if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| + switches::kDisableBrowserTaskScheduler)) { |
| + return; |
| + } |
| + |
| + // TODO(gab): Remove this when http://crbug.com/622400 concludes. |
| + const auto sequenced_worker_pool_param = |
| + variation_params.find("RedirectSequencedWorkerPools"); |
| + if (sequenced_worker_pool_param != variation_params.end() && |
| + sequenced_worker_pool_param->second == "true") { |
| + base::SequencedWorkerPool::RedirectToTaskSchedulerForProcess(); |
| + } |
| } |
| } // namespace task_scheduler_util |