| 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 #ifndef COMPONENTS_TASK_SCHEDULER_UTIL_COMMON_VARIATIONS_UTIL_H_ | 5 #ifndef COMPONENTS_TASK_SCHEDULER_UTIL_COMMON_VARIATIONS_UTIL_H_ |
| 6 #define COMPONENTS_TASK_SCHEDULER_UTIL_COMMON_VARIATIONS_UTIL_H_ | 6 #define COMPONENTS_TASK_SCHEDULER_UTIL_COMMON_VARIATIONS_UTIL_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> |
| 9 #include <string> | 10 #include <string> |
| 10 #include <vector> | |
| 11 | 11 |
| 12 #include "build/build_config.h" | |
| 13 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
| 14 #include "base/task_scheduler/scheduler_worker_params.h" | 13 #include "base/task_scheduler/scheduler_worker_params.h" |
| 15 #include "base/task_scheduler/scheduler_worker_pool_params.h" | 14 #include "base/task_scheduler/task_scheduler.h" |
| 16 #include "base/threading/platform_thread.h" | 15 #include "build/build_config.h" |
| 17 | 16 |
| 18 namespace base { | 17 namespace base { |
| 19 class CommandLine; | 18 class CommandLine; |
| 20 } | 19 } |
| 21 | 20 |
| 22 namespace task_scheduler_util { | 21 namespace task_scheduler_util { |
| 23 | 22 |
| 24 class SchedulerImmutableWorkerPoolParams { | 23 // Builds a TaskScheduler::InitParams from pool descriptors in |
| 25 public: | 24 // |variations_params| that are prefixed with |variation_param_prefix|. |
| 26 SchedulerImmutableWorkerPoolParams( | 25 // |foreground_blocking_backward_compatibility| controls backward compatibility |
| 27 const char* name, | 26 // in the foreground blocking pool. Returns nullptr on failure. |
| 28 base::ThreadPriority priority_hint, | 27 std::unique_ptr<base::TaskScheduler::InitParams> GetTaskSchedulerInitParams( |
| 29 base::SchedulerBackwardCompatibility backward_compatibility = | 28 base::StringPiece variation_param_prefix, |
| 30 base::SchedulerBackwardCompatibility::DISABLED); | 29 const std::map<std::string, std::string>& variation_params, |
| 31 | 30 base::SchedulerBackwardCompatibility |
| 32 const char* name() const { return name_; } | 31 foreground_blocking_backward_compatibility = |
| 33 base::ThreadPriority priority_hint() const { return priority_hint_; } | 32 base::SchedulerBackwardCompatibility::DISABLED); |
| 34 base::SchedulerBackwardCompatibility backward_compatibility() const { | |
| 35 return backward_compatibility_; | |
| 36 } | |
| 37 | |
| 38 private: | |
| 39 const char* name_; | |
| 40 base::ThreadPriority priority_hint_; | |
| 41 base::SchedulerBackwardCompatibility backward_compatibility_; | |
| 42 }; | |
| 43 | |
| 44 // Returns a SchedulerWorkerPoolParams vector to initialize pools specified in | |
| 45 // |constant_worker_pool_params_vector|. SchedulerWorkerPoolParams members | |
| 46 // without a counterpart in SchedulerImmutableWorkerPoolParams are initialized | |
| 47 // based of |variation_params|. Returns an empty vector on failure. | |
| 48 std::vector<base::SchedulerWorkerPoolParams> GetWorkerPoolParams( | |
| 49 const std::vector<SchedulerImmutableWorkerPoolParams>& | |
| 50 constant_worker_pool_params_vector, | |
| 51 const std::map<std::string, std::string>& variation_params); | |
| 52 | 33 |
| 53 #if !defined(OS_IOS) | 34 #if !defined(OS_IOS) |
| 54 // Serializes variation params from the BrowserScheduler field trial whose key | 35 // Serializes variation params from the BrowserScheduler field trial whose key |
| 55 // start with |prefix| to the --task-scheduler-variation-params switch of | 36 // start with |prefix| to the --task-scheduler-variation-params switch of |
| 56 // |command_line|. | 37 // |command_line|. |
| 57 void AddVariationParamsToCommandLine(base::StringPiece key_prefix, | 38 void AddVariationParamsToCommandLine(base::StringPiece key_prefix, |
| 58 base::CommandLine* command_line); | 39 base::CommandLine* command_line); |
| 59 | 40 |
| 60 // Returns a map of key-value pairs deserialized from the | 41 // Returns a map of key-value pairs deserialized from the |
| 61 // --task-scheduler-variation-params switch of |command_line|. | 42 // --task-scheduler-variation-params switch of |command_line|. |
| 62 std::map<std::string, std::string> GetVariationParamsFromCommandLine( | 43 std::map<std::string, std::string> GetVariationParamsFromCommandLine( |
| 63 const base::CommandLine& command_line); | 44 const base::CommandLine& command_line); |
| 64 #endif // !defined(OS_IOS) | 45 #endif // !defined(OS_IOS) |
| 65 | 46 |
| 66 } // namespace task_scheduler_util | 47 } // namespace task_scheduler_util |
| 67 | 48 |
| 68 #endif // COMPONENTS_TASK_SCHEDULER_UTIL_COMMON_VARIATIONS_UTIL_H_ | 49 #endif // COMPONENTS_TASK_SCHEDULER_UTIL_COMMON_VARIATIONS_UTIL_H_ |
| OLD | NEW |