Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
moko256 authored Jan 19, 2022
1 parent cef8bce commit 31b1a1d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions shell/platform/windows/task_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ TaskRunner::TaskRunner(CurrentTimeProc get_current_time,
on_task_expired_(std::move(on_task_expired)) {}

std::chrono::nanoseconds TaskRunner::ProcessTasks() {
const TaskTimePoint now = TaskTimePoint::clock::now();
const TaskTimePoint now = GetCurrentTimeForTask();

std::vector<Task> expired_tasks;

Expand Down Expand Up @@ -64,7 +64,7 @@ std::chrono::nanoseconds TaskRunner::ProcessTasks() {

TaskRunner::TaskTimePoint TaskRunner::TimePointFromFlutterTime(
uint64_t flutter_target_time_nanos) const {
const auto now = TaskTimePoint::clock::now();
const auto now = GetCurrentTimeForTask();
const auto flutter_duration = flutter_target_time_nanos - get_current_time_();
return now + std::chrono::nanoseconds(flutter_duration);
}
Expand All @@ -79,7 +79,7 @@ void TaskRunner::PostFlutterTask(FlutterTask flutter_task,

void TaskRunner::PostTask(TaskClosure closure) {
Task task;
task.fire_time = TaskTimePoint::clock::now();
task.fire_time = GetCurrentTimeForTask();
task.variant = std::move(closure);
EnqueueTask(std::move(task));
}
Expand Down
8 changes: 8 additions & 0 deletions shell/platform/windows/task_runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ class TaskRunner {
// Each platform implementations must call this to schedule the tasks.
std::chrono::nanoseconds ProcessTasks();

// Returns the current TaskTimePoint that can be used to determine whether a
// task is expired.
//
// Tests can override this to mock up the time.
virtual TaskTimePoint GetCurrentTimeForTask() const {
return TaskTimePoint::clock::now();
}

private:
typedef std::variant<FlutterTask, TaskClosure> TaskVariant;

Expand Down
6 changes: 6 additions & 0 deletions shell/platform/windows/task_runner_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class MockTaskRunner : public TaskRunner {
// Do nothing to avoid processing tasks immediately after the tasks is
// posted.
}

virtual TaskTimePoint GetCurrentTimeForTask() const override {
return TaskTimePoint(
std::chrono::duration_cast<std::chrono::steady_clock::duration>(
std::chrono::nanoseconds(10000)));
}
};

uint64_t MockGetCurrentTime() {
Expand Down

0 comments on commit 31b1a1d

Please sign in to comment.