diff options
author | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-30 00:22:48 +0000 |
---|---|---|
committer | darin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-30 00:22:48 +0000 |
commit | 9bcbf478c173d91958cdabc8a8902619392b7f1f (patch) | |
tree | bad2b3022719370e6eb01a66f94924a1f848a968 /base/message_loop.cc | |
parent | 3f9f500b82c82402d9eef92606ebd149762e9f0c (diff) | |
download | chromium_src-9bcbf478c173d91958cdabc8a8902619392b7f1f.zip chromium_src-9bcbf478c173d91958cdabc8a8902619392b7f1f.tar.gz chromium_src-9bcbf478c173d91958cdabc8a8902619392b7f1f.tar.bz2 |
Switch SharedTimerWin over to using PostDelayedTask. I made some tweaks to the
PostDelayedTask implementation to ensure that perf is still good. This
involved recording the intended fire time of PostDelayedTask on the Task object
so that it can be used to properly determine the delay passed to the StartTimer
call. With this change, I am able to service timers (call DoDelayedWork) more
often from within the MessagePump implementations.
R=mbelshe
BUG=1346553
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1578 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_loop.cc')
-rw-r--r-- | base/message_loop.cc | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/base/message_loop.cc b/base/message_loop.cc index cd44b92..410394f 100644 --- a/base/message_loop.cc +++ b/base/message_loop.cc @@ -66,7 +66,11 @@ MessageLoop::MessageLoop(Type type) // TODO(darin): Choose the pump based on the requested type. #if defined(OS_WIN) - pump_ = new base::MessagePumpWin(); + if (type_ == TYPE_DEFAULT) { + pump_ = new base::MessagePumpDefault(); + } else { + pump_ = new base::MessagePumpWin(); + } #else pump_ = new base::MessagePumpDefault(); #endif @@ -180,10 +184,17 @@ void MessageLoop::Quit() { void MessageLoop::PostDelayedTask(const tracked_objects::Location& from_here, Task* task, int delay_ms) { task->SetBirthPlace(from_here); - DCHECK(delay_ms >= 0); - DCHECK(!task->is_owned_by_message_loop()); - task->set_posted_task_delay(delay_ms); - DCHECK(task->is_owned_by_message_loop()); + + DCHECK(!task->owned_by_message_loop_); + task->owned_by_message_loop_ = true; + + if (delay_ms > 0) { + task->delayed_run_time_ = + Time::Now() + TimeDelta::FromMilliseconds(delay_ms); + } else { + DCHECK(delay_ms == 0) << "delay should not be negative"; + } + PostTaskInternal(task); } @@ -231,7 +242,7 @@ bool MessageLoop::RunTimerTask(Timer* timer) { HistogramEvent(kTimerEvent); Task* task = timer->task(); - if (task->is_owned_by_message_loop()) { + if (task->owned_by_message_loop_) { // We constructed it through PostDelayedTask(). DCHECK(!timer->repeating()); timer->set_task(NULL); @@ -249,7 +260,7 @@ bool MessageLoop::RunTimerTask(Timer* timer) { void MessageLoop::DiscardTimer(Timer* timer) { Task* task = timer->task(); - if (task->is_owned_by_message_loop()) { + if (task->owned_by_message_loop_) { DCHECK(!timer->repeating()); timer->set_task(NULL); delete timer; // We constructed it through PostDelayedTask(). @@ -292,7 +303,7 @@ void MessageLoop::RunTask(Task* task) { HistogramEvent(kTaskRunEvent); // task may self-delete during Run() if we don't happen to own it. // ...so check *before* we Run, since we can't check after. - bool we_own_task = task->is_owned_by_message_loop(); + bool we_own_task = task->owned_by_message_loop_; task->Run(); if (we_own_task) task->RecycleOrDelete(); // Relinquish control, and probably delete. @@ -331,12 +342,16 @@ void MessageLoop::ReloadWorkQueue() { while (!new_task_list.Empty()) { Task* task = new_task_list.Pop(); - DCHECK(task->is_owned_by_message_loop()); - - if (task->posted_task_delay() > 0) - timer_manager_.StartTimer(task->posted_task_delay(), task, false); - else + DCHECK(task->owned_by_message_loop_); + + // TODO(darin): We should probably postpone starting the timer until we + // process the work queue as starting the timer here breaks the FIFO + // ordering of tasks. + if (!task->delayed_run_time_.is_null()) { + timer_manager_.StartTimer(new Timer(task->delayed_run_time_, task)); + } else { work_queue_.Push(task); + } } } |