Flutter Engine
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 60 of file embedder_unittests_util.h.

Member Typedef Documentation

◆ TaskExpiryCallback

Constructor & Destructor Documentation

◆ EmbedderTestTaskRunner()

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

Definition at line 63 of file embedder_unittests_util.h.

References FML_CHECK, fml::TimePoint::FromEpochDelta(), fml::TimeDelta::FromNanoseconds(), FlutterTaskRunnerDescription::identifier, FlutterTaskRunnerDescription::post_task_callback, fml::TaskRunner::PostTaskForTime(), FlutterTaskRunnerDescription::runs_task_on_current_thread_callback, fml::TaskRunner::RunsTasksOnCurrentThread(), FlutterTaskRunnerDescription::struct_size, user_data, and FlutterTaskRunnerDescription::user_data.

65  : identifier_(++sEmbedderTaskRunnerIdentifiers),
66  real_task_runner_(real_task_runner),
67  on_task_expired_(on_task_expired) {
68  FML_CHECK(real_task_runner_);
69  FML_CHECK(on_task_expired_);
70 
71  task_runner_description_.struct_size = sizeof(FlutterTaskRunnerDescription);
72  task_runner_description_.user_data = this;
73  task_runner_description_.runs_task_on_current_thread_callback =
74  [](void* user_data) -> bool {
75  return reinterpret_cast<EmbedderTestTaskRunner*>(user_data)
76  ->real_task_runner_->RunsTasksOnCurrentThread();
77  };
78  task_runner_description_.post_task_callback = [](FlutterTask task,
79  uint64_t target_time_nanos,
80  void* user_data) -> void {
81  auto thiz = reinterpret_cast<EmbedderTestTaskRunner*>(user_data);
82 
83  auto target_time = fml::TimePoint::FromEpochDelta(
84  fml::TimeDelta::FromNanoseconds(target_time_nanos));
85  auto on_task_expired = thiz->on_task_expired_;
86  auto invoke_task = [task, on_task_expired]() { on_task_expired(task); };
87  auto real_task_runner = thiz->real_task_runner_;
88 
89  real_task_runner->PostTaskForTime(invoke_task, target_time);
90  };
91  task_runner_description_.identifier = identifier_;
92  }
static constexpr TimeDelta FromNanoseconds(int64_t nanos)
Definition: time_delta.h:40
size_t struct_size
The size of this struct. Must be sizeof(FlutterTaskRunnerDescription).
Definition: embedder.h:718
static constexpr TimePoint FromEpochDelta(TimeDelta ticks)
Definition: time_point.h:36
virtual void PostTaskForTime(const fml::closure &task, fml::TimePoint target_time)
Definition: task_runner.cc:28
G_BEGIN_DECLS FlMethodCall gpointer user_data
#define FML_CHECK(condition)
Definition: logging.h:68
FlutterTaskRunnerPostTaskCallback post_task_callback
Definition: embedder.h:735
virtual bool RunsTasksOnCurrentThread()
Definition: task_runner.cc:43
BoolCallback runs_task_on_current_thread_callback
Definition: embedder.h:724
EmbedderTestTaskRunner(fml::RefPtr< fml::TaskRunner > real_task_runner, TaskExpiryCallback on_task_expired)

Member Function Documentation

◆ GetFlutterTaskRunnerDescription()

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

Definition at line 94 of file embedder_unittests_util.h.

94  {
95  return task_runner_description_;
96  }

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