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 BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ | 5 #ifndef BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ |
6 #define BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ | 6 #define BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| 11 #include "base/callback_forward.h" |
11 #include "base/macros.h" | 12 #include "base/macros.h" |
12 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 | 15 |
15 namespace base { | 16 namespace base { |
16 | 17 |
17 class TaskRunner; | 18 class TaskRunner; |
18 | 19 |
19 namespace internal { | 20 namespace internal { |
20 | 21 |
21 class SchedulerWorker; | |
22 class SchedulerWorkerPool; | |
23 class Sequence; | |
24 struct Task; | 22 struct Task; |
25 | 23 |
26 // A DelayedTaskManager forwards Tasks to a SchedulerWorkerPool when they become | 24 // The DelayedTaskManager forwards tasks to various scheduler components when |
27 // ripe for execution. This class is thread-safe. | 25 // they become ripe for execution. This class is thread-safe. |
28 class BASE_EXPORT DelayedTaskManager { | 26 class BASE_EXPORT DelayedTaskManager { |
29 public: | 27 public: |
| 28 // Posts |task| for execution immediately. |
| 29 using PostTaskNowCallback = Callback<void(std::unique_ptr<Task> task)>; |
| 30 |
30 // |service_thread_task_runner| posts tasks to the TaskScheduler service | 31 // |service_thread_task_runner| posts tasks to the TaskScheduler service |
31 // thread. | 32 // thread. |
32 explicit DelayedTaskManager( | 33 explicit DelayedTaskManager( |
33 scoped_refptr<TaskRunner> service_thread_task_runner); | 34 scoped_refptr<TaskRunner> service_thread_task_runner); |
34 ~DelayedTaskManager(); | 35 ~DelayedTaskManager(); |
35 | 36 |
36 // Posts |task|. The task will be forwarded to |worker_pool| with |sequence| | 37 // Calls |post_task_now_callback| with |task| when |task| is ripe for |
37 // and |worker| when it becomes ripe for execution. |worker| is a | 38 // execution. |
38 // SchedulerWorker owned by |worker_pool| or nullptr. | |
39 // | |
40 // TODO(robliao): Find a concrete way to manage the memory of |worker| and | |
41 // |worker_pool|. These objects are never deleted in production, but it is | |
42 // better not to spread this assumption throughout the scheduler. | |
43 void AddDelayedTask(std::unique_ptr<Task> task, | 39 void AddDelayedTask(std::unique_ptr<Task> task, |
44 scoped_refptr<Sequence> sequence, | 40 const PostTaskNowCallback& post_task_now_callback); |
45 SchedulerWorker* worker, | |
46 SchedulerWorkerPool* worker_pool); | |
47 | 41 |
48 private: | 42 private: |
49 const scoped_refptr<TaskRunner> service_thread_task_runner_; | 43 const scoped_refptr<TaskRunner> service_thread_task_runner_; |
50 | 44 |
51 DISALLOW_COPY_AND_ASSIGN(DelayedTaskManager); | 45 DISALLOW_COPY_AND_ASSIGN(DelayedTaskManager); |
52 }; | 46 }; |
53 | 47 |
54 } // namespace internal | 48 } // namespace internal |
55 } // namespace base | 49 } // namespace base |
56 | 50 |
57 #endif // BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ | 51 #endif // BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ |
OLD | NEW |