| Index: base/task_scheduler/task_scheduler_impl.h
|
| diff --git a/base/task_scheduler/task_scheduler_impl.h b/base/task_scheduler/task_scheduler_impl.h
|
| index f9d789ea4c550daec7c001f591ce2068f672e936..6a5797fdd510c8bf25c01efadc1a69f70ee9821a 100644
|
| --- a/base/task_scheduler/task_scheduler_impl.h
|
| +++ b/base/task_scheduler/task_scheduler_impl.h
|
| @@ -5,7 +5,11 @@
|
| #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
|
| #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_
|
|
|
| +#include <stddef.h>
|
| +
|
| #include <memory>
|
| +#include <string>
|
| +#include <vector>
|
|
|
| #include "base/base_export.h"
|
| #include "base/logging.h"
|
| @@ -14,10 +18,12 @@
|
| #include "base/synchronization/waitable_event.h"
|
| #include "base/task_runner.h"
|
| #include "base/task_scheduler/delayed_task_manager.h"
|
| +#include "base/task_scheduler/scheduler_thread_pool_impl.h"
|
| #include "base/task_scheduler/sequence.h"
|
| #include "base/task_scheduler/task_scheduler.h"
|
| #include "base/task_scheduler/task_tracker.h"
|
| #include "base/task_scheduler/task_traits.h"
|
| +#include "base/threading/platform_thread.h"
|
|
|
| namespace base {
|
| namespace internal {
|
| @@ -28,9 +34,40 @@ class SchedulerThreadPoolImpl;
|
| // Default TaskScheduler implementation. This class is thread-safe.
|
| class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
|
| public:
|
| - // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure to
|
| - // do so (never returns null).
|
| - static std::unique_ptr<TaskSchedulerImpl> Create();
|
| + // Delegate interface for TaskSchedulerImpl.
|
| + class BASE_EXPORT Delegate {
|
| + public:
|
| + struct ThreadPoolCreationArgs {
|
| + // Name of the pool. Use to label the pool's threads.
|
| + std::string name;
|
| +
|
| + // Priority of the pool's threads.
|
| + ThreadPriority thread_priority;
|
| +
|
| + // Whether IO is allowed in the pool.
|
| + SchedulerThreadPoolImpl::IORestriction io_restriction;
|
| +
|
| + // Maximum number of threads in the pool.
|
| + size_t max_threads;
|
| + };
|
| +
|
| + virtual ~Delegate() = default;
|
| +
|
| + // Returns the number of pools to create.
|
| + virtual size_t GetNumThreadPools() = 0;
|
| +
|
| + // Returns creation arguments for the pool at index |pool_index|.
|
| + virtual ThreadPoolCreationArgs GetCreationArgsForThreadPool(
|
| + size_t pool_index) = 0;
|
| +
|
| + // Returns the index of the pool in which a task with |traits| should run.
|
| + virtual size_t GetThreadPoolIndexForTraits(const TaskTraits& traits) = 0;
|
| + };
|
| +
|
| + // Creates and returns an initialized TaskSchedulerImpl. CHECKs on failure
|
| + // (never returns null).
|
| + static std::unique_ptr<TaskSchedulerImpl> Create(
|
| + std::unique_ptr<Delegate> delegate);
|
|
|
| // Destroying a TaskSchedulerImpl is not allowed in production; it is always
|
| // leaked. In tests, it can only be destroyed after JoinForTesting() has
|
| @@ -51,7 +88,7 @@ class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
|
| void JoinForTesting();
|
|
|
| private:
|
| - TaskSchedulerImpl();
|
| + TaskSchedulerImpl(std::unique_ptr<Delegate> delegate);
|
|
|
| void Initialize();
|
|
|
| @@ -66,21 +103,10 @@ class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler {
|
| // DelayedTaskManager.
|
| void OnDelayedRunTimeUpdated();
|
|
|
| + std::unique_ptr<Delegate> delegate_;
|
| TaskTracker task_tracker_;
|
| DelayedTaskManager delayed_task_manager_;
|
| -
|
| - // Thread pool for BACKGROUND Tasks without file I/O.
|
| - std::unique_ptr<SchedulerThreadPoolImpl> background_thread_pool_;
|
| -
|
| - // Thread pool for BACKGROUND Tasks with file I/O.
|
| - std::unique_ptr<SchedulerThreadPoolImpl> background_file_io_thread_pool_;
|
| -
|
| - // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks without file I/O.
|
| - std::unique_ptr<SchedulerThreadPoolImpl> normal_thread_pool_;
|
| -
|
| - // Thread pool for USER_VISIBLE and USER_BLOCKING Tasks with file I/O.
|
| - std::unique_ptr<SchedulerThreadPoolImpl> normal_file_io_thread_pool_;
|
| -
|
| + std::vector<std::unique_ptr<SchedulerThreadPoolImpl>> thread_pools_;
|
| std::unique_ptr<SchedulerServiceThread> service_thread_;
|
|
|
| #if DCHECK_IS_ON()
|
|
|