Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | List of all members
flutter::testing::EmbedderTestTaskRunner Class Reference

A task runner that we expect the embedder to provide but whose implementation is a real FML task runner. More...

#include <embedder_unittests_util.h>

Public Types

using TaskExpiryCallback = std::function< void(FlutterTask)>
 

Public Member Functions

 EmbedderTestTaskRunner (fml::RefPtr< fml::TaskRunner > real_task_runner, TaskExpiryCallback on_task_expired)
 
const FlutterTaskRunnerDescriptionGetFlutterTaskRunnerDescription ()
 

Detailed Description

A task runner that we expect the embedder to provide but whose implementation is a real FML task runner.

Definition at line 102 of file embedder_unittests_util.h.

Member Typedef Documentation

◆ TaskExpiryCallback

Definition at line 104 of file embedder_unittests_util.h.

Constructor & Destructor Documentation

◆ EmbedderTestTaskRunner()

flutter::testing::EmbedderTestTaskRunner::EmbedderTestTaskRunner ( fml::RefPtr< fml::TaskRunner real_task_runner,
TaskExpiryCallback  on_task_expired 
)
inline

Definition at line 105 of file embedder_unittests_util.h.

107 : identifier_(++sEmbedderTaskRunnerIdentifiers),
108 real_task_runner_(std::move(real_task_runner)),
109 on_task_expired_(std::move(on_task_expired)) {
110 FML_CHECK(real_task_runner_);
111 FML_CHECK(on_task_expired_);
112
113 task_runner_description_.struct_size = sizeof(FlutterTaskRunnerDescription);
114 task_runner_description_.user_data = this;
115 task_runner_description_.runs_task_on_current_thread_callback =
116 [](void* user_data) -> bool {
117 return reinterpret_cast<EmbedderTestTaskRunner*>(user_data)
118 ->real_task_runner_->RunsTasksOnCurrentThread();
119 };
120 task_runner_description_.post_task_callback = [](FlutterTask task,
121 uint64_t target_time_nanos,
122 void* user_data) -> void {
123 auto thiz = reinterpret_cast<EmbedderTestTaskRunner*>(user_data);
124
125 auto target_time = fml::TimePoint::FromEpochDelta(
126 fml::TimeDelta::FromNanoseconds(target_time_nanos));
127 auto on_task_expired = thiz->on_task_expired_;
128 auto invoke_task = [task, on_task_expired]() { on_task_expired(task); };
129 auto real_task_runner = thiz->real_task_runner_;
130
131 real_task_runner->PostTaskForTime(invoke_task, target_time);
132 };
133 task_runner_description_.identifier = identifier_;
134 }
EmbedderTestTaskRunner(fml::RefPtr< fml::TaskRunner > real_task_runner, TaskExpiryCallback on_task_expired)
virtual void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time)
Definition: task_runner.cc:28
virtual bool RunsTasksOnCurrentThread()
Definition: task_runner.cc:43
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition: time_delta.h:40
static constexpr TimePoint FromEpochDelta(TimeDelta ticks)
Definition: time_point.h:43
#define FML_CHECK(condition)
Definition: logging.h:85
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition: embedder.h:1566
BoolCallback runs_task_on_current_thread_callback
Definition: embedder.h:1572
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition: embedder.h:1583
void * user_data

Member Function Documentation

◆ GetFlutterTaskRunnerDescription()

const FlutterTaskRunnerDescription & flutter::testing::EmbedderTestTaskRunner::GetFlutterTaskRunnerDescription ( )
inline

Definition at line 136 of file embedder_unittests_util.h.

136 {
137 return task_runner_description_;
138 }

The documentation for this class was generated from the following files: