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(fml::closure task); 24 25 virtual void PostTaskForTime(fml::closure task, fml::TimePoint target_time); 26 27 virtual void PostDelayedTask(fml::closure task, fml::TimeDelta delay); 28 29 virtual bool RunsTasksOnCurrentThread(); 30 31 virtual TaskQueueId GetTaskQueueId(); 32 33 static void RunNowOrPostTask(fml::RefPtr<fml::TaskRunner> runner, 34 fml::closure task); 35 36 protected: 37 TaskRunner(fml::RefPtr<MessageLoopImpl> loop); 38 39 private: 40 fml::RefPtr<MessageLoopImpl> loop_; 41 42 FML_FRIEND_MAKE_REF_COUNTED(TaskRunner); 43 FML_FRIEND_REF_COUNTED_THREAD_SAFE(TaskRunner); 44 FML_DISALLOW_COPY_AND_ASSIGN(TaskRunner); 45 }; 46 47 } // namespace fml 48 49 #endif // FLUTTER_FML_TASK_RUNNER_H_ 50