Add TaskScheduler::InitParams and accept it in TaskSchedulerImpl constructor.
TaskScheduler::InitParams is a struct of 4 SchedulerWorkerPoolParams.
Eventually, TaskSchedulerImpl will always be initialized with it
(it will no longer be possible to provide a vector with an
arbitrary number of SchedulerWorkerPoolParams).
Reference CL: https://codereview.chromium.org/2749303002/
BUG=690706
Review-Url: https://codereview.chromium.org/2764603002
Cr-Commit-Position: refs/heads/master@{#460167}
diff --git a/base/task_scheduler/task_scheduler.h b/base/task_scheduler/task_scheduler.h
index 4b07c88998..a869858 100644
--- a/base/task_scheduler/task_scheduler.h
+++ b/base/task_scheduler/task_scheduler.h
@@ -15,6 +15,7 @@
#include "base/sequenced_task_runner.h"
#include "base/single_thread_task_runner.h"
#include "base/task_runner.h"
+#include "base/task_scheduler/scheduler_worker_pool_params.h"
#include "base/task_scheduler/task_traits.h"
#include "base/time/time.h"
@@ -29,7 +30,6 @@
namespace base {
class HistogramBase;
-class SchedulerWorkerPoolParams;
// Interface for a task scheduler and static methods to manage the instance used
// by the post_task.h API. Note: all base/task_scheduler users should go through
@@ -37,6 +37,22 @@
// which manages the process' instance.
class BASE_EXPORT TaskScheduler {
public:
+ struct BASE_EXPORT InitParams {
+ InitParams(
+ const SchedulerWorkerPoolParams& background_worker_pool_params_in,
+ const SchedulerWorkerPoolParams&
+ background_blocking_worker_pool_params_in,
+ const SchedulerWorkerPoolParams& foreground_worker_pool_params_in,
+ const SchedulerWorkerPoolParams&
+ foreground_blocking_worker_pool_params_in);
+ ~InitParams();
+
+ const SchedulerWorkerPoolParams background_worker_pool_params;
+ const SchedulerWorkerPoolParams background_blocking_worker_pool_params;
+ const SchedulerWorkerPoolParams foreground_worker_pool_params;
+ const SchedulerWorkerPoolParams foreground_blocking_worker_pool_params;
+ };
+
// Returns the index of the worker pool in which a task with |traits| should
// run. This should be coded in a future-proof way: new traits should
// gracefully map to a default pool.
@@ -121,11 +137,24 @@
// |worker_pool_index_for_traits_callback| returns the index in |worker_pools|
// of the worker pool in which a task with given traits should run. For tests,
// prefer base::test::ScopedTaskScheduler (ensures isolation).
+ //
+ // Deprecated. Use the overload below instead. https://crbug.com/690706
static void CreateAndSetDefaultTaskScheduler(
const std::vector<SchedulerWorkerPoolParams>& worker_pool_params_vector,
const WorkerPoolIndexForTraitsCallback&
worker_pool_index_for_traits_callback);
+ // Creates and sets a task scheduler using custom params. |name| is used to
+ // label threads and histograms. It should identify the component that creates
+ // the TaskScheduler. |init_params| is used to initialize the worker pools.
+ // CHECKs on failure. For tests, prefer base::test::ScopedTaskScheduler
+ // (ensures isolation).
+ //
+ // Note: The names and priority hints in |init_params| are ignored (ref. TODO
+ // to remove them).
+ static void CreateAndSetDefaultTaskScheduler(const std::string& name,
+ const InitParams& init_params);
+
// Registers |task_scheduler| to handle tasks posted through the post_task.h
// API for this process. For tests, prefer base::test::ScopedTaskScheduler
// (ensures isolation).