1 | // Copyright 2013 The Flutter 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 FLUTTER_FML_TASK_RUNNER_H_ |
6 | #define FLUTTER_FML_TASK_RUNNER_H_ |
7 | |
8 | #include "flutter/fml/closure.h" |
9 | #include "flutter/fml/macros.h" |
10 | #include "flutter/fml/memory/ref_counted.h" |
11 | #include "flutter/fml/memory/ref_ptr.h" |
12 | #include "flutter/fml/message_loop_task_queues.h" |
13 | #include "flutter/fml/time/time_point.h" |
14 | |
15 | namespace fml { |
16 | |
17 | class MessageLoopImpl; |
18 | |
19 | class TaskRunner : public fml::RefCountedThreadSafe<TaskRunner> { |
20 | public: |
21 | virtual ~TaskRunner(); |
22 | |
23 | virtual void PostTask(const fml::closure& task); |
24 | |
25 | virtual void PostTaskForTime(const fml::closure& task, |
26 | fml::TimePoint target_time); |
27 | |
28 | virtual void PostDelayedTask(const fml::closure& task, fml::TimeDelta delay); |
29 | |
30 | virtual bool RunsTasksOnCurrentThread(); |
31 | |
32 | virtual TaskQueueId GetTaskQueueId(); |
33 | |
34 | static void RunNowOrPostTask(fml::RefPtr<fml::TaskRunner> runner, |
35 | const fml::closure& task); |
36 | |
37 | protected: |
38 | TaskRunner(fml::RefPtr<MessageLoopImpl> loop); |
39 | |
40 | private: |
41 | fml::RefPtr<MessageLoopImpl> loop_; |
42 | |
43 | FML_FRIEND_MAKE_REF_COUNTED(TaskRunner); |
44 | FML_FRIEND_REF_COUNTED_THREAD_SAFE(TaskRunner); |
45 | FML_DISALLOW_COPY_AND_ASSIGN(TaskRunner); |
46 | }; |
47 | |
48 | } // namespace fml |
49 | |
50 | #endif // FLUTTER_FML_TASK_RUNNER_H_ |
51 |