Index: base/timer/timer.cc |
diff --git a/base/timer/timer.cc b/base/timer/timer.cc |
index 1916ccc34ebb7c7bf328533ba8911ddd11679b17..11f73ca4290e4947a537cfa370dadcef7dca85d5 100644 |
--- a/base/timer/timer.cc |
+++ b/base/timer/timer.cc |
@@ -93,6 +93,12 @@ TimeDelta Timer::GetCurrentDelay() const { |
return delay_; |
} |
+void Timer::SetTaskRunner(scoped_refptr<SingleThreadTaskRunner> task_runner) { |
+ // Do not allow changing the task runner once something has been scheduled. |
+ DCHECK_EQ(thread_id_, 0); |
+ task_runner_.swap(task_runner); |
+} |
+ |
void Timer::Start(const tracked_objects::Location& posted_from, |
TimeDelta delay, |
const base::Closure& user_task) { |
@@ -146,12 +152,12 @@ void Timer::PostNewScheduledTask(TimeDelta delay) { |
is_running_ = true; |
scheduled_task_ = new BaseTimerTaskInternal(this); |
if (delay > TimeDelta::FromMicroseconds(0)) { |
- ThreadTaskRunnerHandle::Get()->PostDelayedTask(posted_from_, |
+ GetTaskRunner()->PostDelayedTask(posted_from_, |
base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_)), |
delay); |
scheduled_run_time_ = desired_run_time_ = TimeTicks::Now() + delay; |
} else { |
- ThreadTaskRunnerHandle::Get()->PostTask(posted_from_, |
+ GetTaskRunner()->PostTask(posted_from_, |
base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_))); |
scheduled_run_time_ = desired_run_time_ = TimeTicks(); |
} |
@@ -161,6 +167,10 @@ void Timer::PostNewScheduledTask(TimeDelta delay) { |
thread_id_ = static_cast<int>(PlatformThread::CurrentId()); |
} |
+scoped_refptr<SingleThreadTaskRunner> Timer::GetTaskRunner() { |
+ return task_runner_.get() ? task_runner_ : ThreadTaskRunnerHandle::Get(); |
+} |
+ |
void Timer::AbandonScheduledTask() { |
DCHECK(thread_id_ == 0 || |
thread_id_ == static_cast<int>(PlatformThread::CurrentId())); |