Flutter Engine
task_runner_adapter.cc
Go to the documentation of this file.
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 #include "task_runner_adapter.h"
6 
7 #include <lib/async/cpp/task.h>
8 #include <lib/async/default.h>
9 #include <lib/zx/time.h>
10 
11 #include "flutter/fml/message_loop_impl.h"
12 
13 namespace flutter_runner {
14 
16  public:
17  CompatTaskRunner(async_dispatcher_t* dispatcher)
18  : fml::TaskRunner(nullptr), forwarding_target_(dispatcher) {
19  FML_DCHECK(forwarding_target_);
20  }
21 
22  void PostTask(const fml::closure& task) override {
23  async::PostTask(forwarding_target_, task);
24  }
25 
26  void PostTaskForTime(const fml::closure& task,
27  fml::TimePoint target_time) override {
28  async::PostTaskForTime(
29  forwarding_target_, task,
30  zx::time(target_time.ToEpochDelta().ToNanoseconds()));
31  }
32 
33  void PostDelayedTask(const fml::closure& task,
34  fml::TimeDelta delay) override {
35  async::PostDelayedTask(forwarding_target_, task,
36  zx::duration(delay.ToNanoseconds()));
37  }
38 
39  bool RunsTasksOnCurrentThread() override {
40  return forwarding_target_ == async_get_default_dispatcher();
41  }
42 
43  private:
44  async_dispatcher_t* forwarding_target_;
45 
46  FML_DISALLOW_COPY_AND_ASSIGN(CompatTaskRunner);
47  FML_FRIEND_MAKE_REF_COUNTED(CompatTaskRunner);
48  FML_FRIEND_REF_COUNTED_THREAD_SAFE(CompatTaskRunner);
49 };
50 
52  async_dispatcher_t* dispatcher) {
53  return fml::MakeRefCounted<CompatTaskRunner>(dispatcher);
54 }
55 
56 } // namespace flutter_runner
void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time) override
fml::RefPtr< fml::TaskRunner > CreateFMLTaskRunner(async_dispatcher_t *dispatcher)
#define FML_DCHECK(condition)
Definition: logging.h:86
TimeDelta ToEpochDelta() const
Definition: time_point.h:40
void PostTask(const fml::closure &task) override
Definition: ascii_trie.cc:9
std::function< void()> closure
Definition: closure.h:14
CompatTaskRunner(async_dispatcher_t *dispatcher)
constexpr int64_t ToNanoseconds() const
Definition: time_delta.h:61
TaskRunner(fml::RefPtr< MessageLoopImpl > loop)
Definition: task_runner.cc:19
void PostDelayedTask(const fml::closure &task, fml::TimeDelta delay) override