OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| 6 #define BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
| 7 |
| 8 #include "base/base_export.h" |
| 9 #include "base/macros.h" |
| 10 #include "base/memory/ref_counted.h" |
| 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/task_scheduler/sequence.h" |
| 13 #include "base/task_scheduler/shutdown_manager.h" |
| 14 #include "base/task_scheduler/task_scheduler.h" |
| 15 #include "base/task_scheduler/thread_pool.h" |
| 16 |
| 17 namespace base { |
| 18 namespace internal { |
| 19 |
| 20 class WorkerThread; |
| 21 |
| 22 class BASE_EXPORT TaskSchedulerImpl : public TaskScheduler { |
| 23 public: |
| 24 TaskSchedulerImpl(); |
| 25 ~TaskSchedulerImpl() override; |
| 26 |
| 27 // TaskScheduler: |
| 28 void PostTaskWithTraits(const tracked_objects::Location& from_here, |
| 29 TaskTraits traits, |
| 30 const Closure& task) override; |
| 31 scoped_refptr<TaskRunner> CreateTaskRunnerWithTraits( |
| 32 TaskTraits traits, |
| 33 ExecutionMode execution_mode) override; |
| 34 void Shutdown() override; |
| 35 |
| 36 // Initiates shutdown and waits until all threads have exited. This method |
| 37 // must not be called more than once in the lifetime of the TaskSchedulerImpl. |
| 38 void ShutdownAndJoinAllThreadsForTesting(); |
| 39 |
| 40 private: |
| 41 // Returns the thread pool that should run tasks with |traits|. |
| 42 ThreadPool* GetThreadPoolForTraits(const TaskTraits& traits); |
| 43 |
| 44 // Callback invoked by |worker_thread| to reinsert |sequence| in the |
| 45 // appropriate priority queue after it has executed one of its tasks. |
| 46 void ReinsertSequenceCallback(scoped_refptr<Sequence> sequence, |
| 47 const WorkerThread* worker_thread); |
| 48 |
| 49 ShutdownManager shutdown_manager_; |
| 50 |
| 51 scoped_ptr<ThreadPool> background_thread_pool_; |
| 52 scoped_ptr<ThreadPool> background_file_io_thread_pool_; |
| 53 scoped_ptr<ThreadPool> normal_thread_pool_; |
| 54 scoped_ptr<ThreadPool> normal_file_io_thread_pool_; |
| 55 |
| 56 DISALLOW_COPY_AND_ASSIGN(TaskSchedulerImpl); |
| 57 }; |
| 58 |
| 59 } // namespace internal |
| 60 } // namespace base |
| 61 |
| 62 #endif // BASE_TASK_SCHEDULER_TASK_SCHEDULER_IMPL_H_ |
OLD | NEW |