summaryrefslogtreecommitdiffstats
path: root/base/message_pump_win.cc
diff options
context:
space:
mode:
authordarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 01:13:40 +0000
committerdarin@google.com <darin@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-20 01:13:40 +0000
commit3816f46725f7b8e42e352a063efd5206a46dbe9a (patch)
treed64edfcf741dcd927ce404f66dab723e8a0914c8 /base/message_pump_win.cc
parentbda05798c0609582075a3b872c37ad56021920c4 (diff)
downloadchromium_src-3816f46725f7b8e42e352a063efd5206a46dbe9a.zip
chromium_src-3816f46725f7b8e42e352a063efd5206a46dbe9a.tar.gz
chromium_src-3816f46725f7b8e42e352a063efd5206a46dbe9a.tar.bz2
rollback r1075 to see if it helps resolve test failures
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@1078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/message_pump_win.cc')
-rw-r--r--base/message_pump_win.cc37
1 files changed, 12 insertions, 25 deletions
diff --git a/base/message_pump_win.cc b/base/message_pump_win.cc
index 28191ea..f290e44 100644
--- a/base/message_pump_win.cc
+++ b/base/message_pump_win.cc
@@ -29,8 +29,6 @@
#include "base/message_pump_win.h"
-#include <math.h>
-
#include "base/histogram.h"
#include "base/win_util.h"
@@ -162,7 +160,7 @@ void MessagePumpWin::ScheduleWork() {
PostMessage(message_hwnd_, kMsgHaveWork, reinterpret_cast<WPARAM>(this), 0);
}
-void MessagePumpWin::ScheduleDelayedWork(const Time& delayed_work_time) {
+void MessagePumpWin::ScheduleDelayedWork(const TimeDelta& delay) {
//
// We would *like* to provide high resolution timers. Windows timers using
// SetTimer() have a 10ms granularity. We have to use WM_TIMER as a wakeup
@@ -183,9 +181,7 @@ void MessagePumpWin::ScheduleDelayedWork(const Time& delayed_work_time) {
// Getting a spurrious SetTimer event firing is benign, as we'll just be
// processing an empty timer queue.
//
- delayed_work_time_ = delayed_work_time;
-
- int delay_msec = GetCurrentDelay();
+ int delay_msec = static_cast<int>(delay.InMilliseconds());
DCHECK(delay_msec >= 0);
if (delay_msec < USER_TIMER_MINIMUM)
delay_msec = USER_TIMER_MINIMUM;
@@ -254,11 +250,10 @@ void MessagePumpWin::HandleTimerMessage() {
if (!state_)
return;
- state_->delegate->DoDelayedWork(&delayed_work_time_);
- if (!delayed_work_time_.is_null()) {
- // A bit gratuitous to set delayed_work_time_ again, but oh well.
- ScheduleDelayedWork(delayed_work_time_);
- }
+ TimeDelta next_delay;
+ state_->delegate->DoDelayedWork(&next_delay);
+ if (next_delay >= TimeDelta::FromMilliseconds(0))
+ ScheduleDelayedWork(next_delay);
}
void MessagePumpWin::DoRunLoop() {
@@ -300,13 +295,14 @@ void MessagePumpWin::DoRunLoop() {
if (more_work_is_plausible)
continue;
- more_work_is_plausible =
- state_->delegate->DoDelayedWork(&delayed_work_time_);
+ TimeDelta next_delay;
+ more_work_is_plausible = state_->delegate->DoDelayedWork(&next_delay);
// If we did not process any delayed work, then we can assume that our
// existing WM_TIMER if any will fire when delayed work should run. We
// don't want to disturb that timer if it is already in flight. However,
// if we did do all remaining delayed work, then lets kill the WM_TIMER.
- if (more_work_is_plausible && delayed_work_time_.is_null())
+ if (more_work_is_plausible &&
+ next_delay < TimeDelta::FromMilliseconds(0))
KillTimer(message_hwnd_, reinterpret_cast<UINT_PTR>(this));
if (state_->should_quit)
break;
@@ -523,17 +519,8 @@ int MessagePumpWin::GetCurrentDelay() const {
if (delayed_work_time_.is_null())
return -1;
- // Be careful here. TimeDelta has a precision of microseconds, but we want a
- // value in milliseconds. If there are 5.5ms left, should the delay be 5 or
- // 6? It should be 6 to avoid executing delayed work too early.
- double timeout = ceil((Time::Now() - delayed_work_time_).InMillisecondsF());
-
- // If this value is negative, then we need to run delayed work soon.
- int delay = static_cast<int>(timeout);
- if (delay < 0)
- delay = 0;
-
- return delay;
+ // This could be a negative value, but that's OK.
+ return static_cast<int>((Time::Now() - delayed_work_time_).InMilliseconds());
}
} // namespace base