This source file includes following definitions.
- PostDelayedTask
- RunsTasksOnCurrentThread
- RunTasks
- PostNonNestableDelayedTask
#include "media/cast/test/fake_single_thread_task_runner.h"
#include "base/logging.h"
#include "base/time/tick_clock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace cast {
namespace test {
FakeSingleThreadTaskRunner::FakeSingleThreadTaskRunner(
base::SimpleTestTickClock* clock)
: clock_(clock) {}
FakeSingleThreadTaskRunner::~FakeSingleThreadTaskRunner() {}
bool FakeSingleThreadTaskRunner::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
EXPECT_GE(delay, base::TimeDelta());
PostedTask posed_task(from_here,
task,
clock_->NowTicks(),
delay,
base::TestPendingTask::NESTABLE);
tasks_.insert(std::make_pair(posed_task.GetTimeToRun(), posed_task));
return false;
}
bool FakeSingleThreadTaskRunner::RunsTasksOnCurrentThread() const {
return true;
}
void FakeSingleThreadTaskRunner::RunTasks() {
while(true) {
std::multimap<base::TimeTicks, PostedTask>::iterator it = tasks_.begin();
if (it == tasks_.end())
return;
PostedTask task = it->second;
if (clock_->NowTicks() < task.GetTimeToRun())
return;
tasks_.erase(it);
task.task.Run();
}
}
bool FakeSingleThreadTaskRunner::PostNonNestableDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
NOTIMPLEMENTED();
return false;
}
}
}
}