summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-11 21:16:06 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-05-11 21:16:06 +0000
commitfd71ea33f86d7f9a8e454d16cbc3d315d42c882e (patch)
tree80991ec3f65eb167d8f98647b95bbf1bbe10dc48
parent13c41f039d1d675ad8172a01203b79ce298c8aa9 (diff)
downloadchromium_src-fd71ea33f86d7f9a8e454d16cbc3d315d42c882e.zip
chromium_src-fd71ea33f86d7f9a8e454d16cbc3d315d42c882e.tar.gz
chromium_src-fd71ea33f86d7f9a8e454d16cbc3d315d42c882e.tar.bz2
Use ThreadTaskRunnerHandle in base::Timer.
Now ThreadTaskRunnerHandle is used instead of MessageLoop::current(). This allows to use Timer classes on threads that don't have MessageLoop but have a different task runner. Review URL: https://chromiumcodereview.appspot.com/10213012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136667 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/timer.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/base/timer.cc b/base/timer.cc
index e51660c..410d1b7 100644
--- a/base/timer.cc
+++ b/base/timer.cc
@@ -5,14 +5,16 @@
#include "base/timer.h"
#include "base/logging.h"
-#include "base/message_loop.h"
+#include "base/single_thread_task_runner.h"
+#include "base/thread_task_runner_handle.h"
+#include "base/threading/platform_thread.h"
namespace base {
// BaseTimerTaskInternal is a simple delegate for scheduling a callback to
-// Timer in the MessageLoop. It also handles the following edge
-// cases:
-// - deleted by MessageLoop.
+// Timer in the thread's default task runner. It also handles the following
+// edge cases:
+// - deleted by the task runner.
// - abandoned (orphaned) by Timer.
class BaseTimerTaskInternal {
public:
@@ -21,7 +23,7 @@ class BaseTimerTaskInternal {
}
~BaseTimerTaskInternal() {
- // This task may be getting cleared because the MessageLoop has been
+ // This task may be getting cleared because the task runner has been
// destructed. If so, don't leave Timer with a dangling pointer
// to this.
if (timer_)
@@ -33,7 +35,7 @@ class BaseTimerTaskInternal {
if (!timer_)
return;
- // *this will be deleted by the MessageLoop, so Timer needs to
+ // *this will be deleted by the task runner, so Timer needs to
// forget us:
timer_->scheduled_task_ = NULL;
@@ -129,7 +131,7 @@ void Timer::PostNewScheduledTask(TimeDelta delay) {
DCHECK(scheduled_task_ == NULL);
is_running_ = true;
scheduled_task_ = new BaseTimerTaskInternal(this);
- MessageLoop::current()->PostDelayedTask(posted_from_,
+ ThreadTaskRunnerHandle::Get()->PostDelayedTask(posted_from_,
base::Bind(&BaseTimerTaskInternal::Run, base::Owned(scheduled_task_)),
delay);
scheduled_run_time_ = desired_run_time_ = TimeTicks::Now() + delay;
@@ -158,7 +160,7 @@ void Timer::RunScheduledTask() {
// TimeTicks::Now() can be expensive, so only call it if we know the user
// has changed the desired_run_time_.
TimeTicks now = TimeTicks::Now();
- // MessageLoop may have called us late anyway, so only post a continuation
+ // Task runner may have called us late anyway, so only post a continuation
// task if the desired_run_time_ is in the future.
if (desired_run_time_ > now) {
// Post a new task to span the remaining time.