Index: base/task_scheduler/delayed_task_manager.h |
diff --git a/base/task_scheduler/delayed_task_manager.h b/base/task_scheduler/delayed_task_manager.h |
index 55cf8e521d0568eb30dff66fc9ca170f434eca8f..1249f2ac82d9ba22e73f4fc211a089cd20c0b8b3 100644 |
--- a/base/task_scheduler/delayed_task_manager.h |
+++ b/base/task_scheduler/delayed_task_manager.h |
@@ -6,11 +6,14 @@ |
#define BASE_TASK_SCHEDULER_DELAYED_TASK_MANAGER_H_ |
#include <memory> |
+#include <utility> |
+#include <vector> |
#include "base/base_export.h" |
-#include "base/callback_forward.h" |
+#include "base/callback.h" |
#include "base/macros.h" |
#include "base/memory/ref_counted.h" |
+#include "base/task_scheduler/scheduler_lock.h" |
namespace base { |
@@ -20,26 +23,35 @@ namespace internal { |
struct Task; |
-// The DelayedTaskManager forwards tasks to various scheduler components when |
-// they become ripe for execution. This class is thread-safe. |
+// The DelayedTaskManager forwards tasks to post task callbacks when they become |
+// ripe for execution. Tasks are not forwarded before Start() is called. This |
+// class is thread-safe. |
class BASE_EXPORT DelayedTaskManager { |
public: |
// Posts |task| for execution immediately. |
- using PostTaskNowCallback = Callback<void(std::unique_ptr<Task> task)>; |
+ using PostTaskNowCallback = OnceCallback<void(std::unique_ptr<Task> task)>; |
+ DelayedTaskManager(); |
+ ~DelayedTaskManager(); |
+ |
+ // Starts the delayed task manager, allowing past and future tasks to be |
+ // forwarded to their callbacks as they become ripe for execution. |
// |service_thread_task_runner| posts tasks to the TaskScheduler service |
// thread. |
- explicit DelayedTaskManager( |
- scoped_refptr<TaskRunner> service_thread_task_runner); |
- ~DelayedTaskManager(); |
+ void Start(scoped_refptr<TaskRunner> service_thread_task_runner); |
// Calls |post_task_now_callback| with |task| when |task| is ripe for |
// execution. |
void AddDelayedTask(std::unique_ptr<Task> task, |
- const PostTaskNowCallback& post_task_now_callback); |
+ PostTaskNowCallback post_task_now_callback); |
private: |
- const scoped_refptr<TaskRunner> service_thread_task_runner_; |
+ // Synchronizes access to all members. |
+ SchedulerLock lock_; |
gab
2017/04/12 19:15:51
The lock is irrelevant after threads have all "see
fdoray
2017/04/19 15:37:55
Done.
|
+ |
+ scoped_refptr<TaskRunner> service_thread_task_runner_; |
+ std::vector<std::pair<std::unique_ptr<Task>, PostTaskNowCallback>> |
+ tasks_added_before_start_; |
DISALLOW_COPY_AND_ASSIGN(DelayedTaskManager); |
}; |