Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Unified Diff: cc/test/ordered_simple_task_runner.cc

Issue 1132753008: Replaced TestNowSource with SimpleTestTickClock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased again. Replaces TimeSource with TickClock in TestAlwaysFailTimeSource Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/test/ordered_simple_task_runner.cc
diff --git a/cc/test/ordered_simple_task_runner.cc b/cc/test/ordered_simple_task_runner.cc
index 4bf97837371973ccbb2821c922e4ea4add8cf18d..377414b9ef9643ebd01ce3ef5a8b812a7f9ef39e 100644
--- a/cc/test/ordered_simple_task_runner.cc
+++ b/cc/test/ordered_simple_task_runner.cc
@@ -77,13 +77,13 @@ void TestOrderablePendingTask::AsValueInto(
OrderedSimpleTaskRunner::OrderedSimpleTaskRunner()
: advance_now_(true),
- now_src_(TestNowSource::Create(0)),
+ now_src_(new base::SimpleTestTickClock()),
max_tasks_(kAbsoluteMaxTasks),
inside_run_tasks_until_(false) {
}
OrderedSimpleTaskRunner::OrderedSimpleTaskRunner(
- scoped_refptr<TestNowSource> now_src,
+ base::SimpleTestTickClock* now_src,
bool advance_now)
: advance_now_(advance_now),
now_src_(now_src),
@@ -93,14 +93,17 @@ OrderedSimpleTaskRunner::OrderedSimpleTaskRunner(
OrderedSimpleTaskRunner::~OrderedSimpleTaskRunner() {}
+const base::TimeTicks OrderedSimpleTaskRunner::kAbsoluteMaxNow =
Sami 2015/06/05 17:11:07 No non-POD global static initializers please. You
Ankur Verma 2015/06/08 07:11:34 Done. Changed to helper function.
+ base::TimeTicks::FromInternalValue(std::numeric_limits<int64_t>::max());
+
// base::TestSimpleTaskRunner implementation
bool OrderedSimpleTaskRunner::PostDelayedTask(
const tracked_objects::Location& from_here,
const base::Closure& task,
base::TimeDelta delay) {
DCHECK(thread_checker_.CalledOnValidThread());
- TestOrderablePendingTask pt(
- from_here, task, now_src_->Now(), delay, base::TestPendingTask::NESTABLE);
+ TestOrderablePendingTask pt(from_here, task, now_src_->NowTicks(), delay,
+ base::TestPendingTask::NESTABLE);
TRACE_TASK("OrderedSimpleTaskRunner::PostDelayedTask", pt);
pending_tasks_.insert(pt);
@@ -112,10 +115,7 @@ bool OrderedSimpleTaskRunner::PostNonNestableDelayedTask(
const base::Closure& task,
base::TimeDelta delay) {
DCHECK(thread_checker_.CalledOnValidThread());
- TestOrderablePendingTask pt(from_here,
- task,
- now_src_->Now(),
- delay,
+ TestOrderablePendingTask pt(from_here, task, now_src_->NowTicks(), delay,
base::TestPendingTask::NON_NESTABLE);
TRACE_TASK("OrderedSimpleTaskRunner::PostNonNestableDelayedTask", pt);
@@ -138,7 +138,7 @@ bool OrderedSimpleTaskRunner::HasPendingTasks() const {
base::TimeTicks OrderedSimpleTaskRunner::NextTaskTime() {
if (pending_tasks_.size() <= 0) {
- return TestNowSource::kAbsoluteMaxNow;
+ return kAbsoluteMaxNow;
}
return pending_tasks_.begin()->GetTimeToRun();
@@ -148,10 +148,10 @@ base::TimeDelta OrderedSimpleTaskRunner::DelayToNextTaskTime() {
DCHECK(thread_checker_.CalledOnValidThread());
if (pending_tasks_.size() <= 0) {
- return TestNowSource::kAbsoluteMaxNow - base::TimeTicks();
+ return kAbsoluteMaxNow - base::TimeTicks();
}
- base::TimeDelta delay = NextTaskTime() - now_src_->Now();
+ base::TimeDelta delay = NextTaskTime() - now_src_->NowTicks();
if (delay > base::TimeDelta())
return delay;
return base::TimeDelta();
@@ -192,7 +192,7 @@ bool OrderedSimpleTaskRunner::RunTasksWhile(
// If to advance now or not
if (!advance_now_) {
- modifiable_conditions.push_back(NowBefore(now_src_->Now()));
+ modifiable_conditions.push_back(NowBefore(now_src_->NowTicks()));
} else {
modifiable_conditions.push_back(AdvanceNow());
}
@@ -241,23 +241,23 @@ bool OrderedSimpleTaskRunner::RunUntilIdle() {
bool OrderedSimpleTaskRunner::RunUntilTime(base::TimeTicks time) {
// If we are not auto advancing, force now forward to the time.
- if (!advance_now_ && now_src_->Now() < time)
- now_src_->SetNow(time);
+ if (!advance_now_ && now_src_->NowTicks() < time)
+ now_src_->Advance(time - now_src_->NowTicks());
// Run tasks
bool result = RunTasksWhile(NowBefore(time));
// If the next task is after the stopping time and auto-advancing now, then
// force time to be the stopping time.
- if (!result && advance_now_ && now_src_->Now() < time) {
- now_src_->SetNow(time);
+ if (!result && advance_now_ && now_src_->NowTicks() < time) {
+ now_src_->Advance(time - now_src_->NowTicks());
}
return result;
}
bool OrderedSimpleTaskRunner::RunForPeriod(base::TimeDelta period) {
- return RunUntilTime(now_src_->Now() + period);
+ return RunUntilTime(now_src_->NowTicks() + period);
}
// base::trace_event tracing functionality
@@ -285,7 +285,8 @@ void OrderedSimpleTaskRunner::AsValueInto(
state->EndArray();
state->BeginDictionary("now_src");
- now_src_->AsValueInto(state);
+ state->SetInteger("now_in_microseconds",
+ (now_src_->NowTicks()).ToInternalValue());
state->EndDictionary();
state->SetBoolean("advance_now", advance_now_);
@@ -334,8 +335,8 @@ base::Callback<bool(void)> OrderedSimpleTaskRunner::AdvanceNow() {
bool OrderedSimpleTaskRunner::AdvanceNowCallback() {
base::TimeTicks next_task_time = NextTaskTime();
- if (now_src_->Now() < next_task_time) {
- now_src_->SetNow(next_task_time);
+ if (now_src_->NowTicks() < next_task_time) {
+ now_src_->Advance(next_task_time - now_src_->NowTicks());
}
return true;
}

Powered by Google App Engine
This is Rietveld 408576698