summaryrefslogtreecommitdiffstats
path: root/base/timer.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/timer.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/timer.cc')
-rw-r--r--base/timer.cc20
1 files changed, 15 insertions, 5 deletions
diff --git a/base/timer.cc b/base/timer.cc
index aced8cb..46fae6e 100644
--- a/base/timer.cc
+++ b/base/timer.cc
@@ -55,6 +55,14 @@ Timer::Timer(int delay, Task* task, bool repeating)
Reset();
}
+int Timer::GetCurrentDelay() const {
+ // Be careful here. Timers have a precision of microseconds, but this API is
+ // in milliseconds. If there are 5.5ms left, should the delay be 5 or 6? It
+ // should be 6 to avoid timers firing early.
+ double delay = ceil((fire_time_ - Time::Now()).InMillisecondsF());
+ return static_cast<int>(delay);
+}
+
void Timer::Reset() {
creation_time_ = Time::Now();
fire_time_ = creation_time_ + TimeDelta::FromMilliseconds(delay_);
@@ -155,7 +163,7 @@ bool TimerManager::RunSomePendingTimers() {
// timers have been set.
const int kMaxTimersPerCall = 2;
for (int i = 0; i < kMaxTimersPerCall; ++i) {
- if (timers_.empty() || timers_.top()->fire_time() > Time::Now())
+ if (timers_.empty() || GetCurrentDelay() > 0)
break;
// Get a pending timer. Deal with updating the timers_ queue and setting
@@ -203,11 +211,13 @@ void TimerManager::StartTimer(Timer* timer) {
DidChangeNextTimer();
}
-Time TimerManager::GetNextFireTime() const {
+int TimerManager::GetCurrentDelay() {
if (timers_.empty())
- return Time();
-
- return timers_.top()->fire_time();
+ return -1;
+ int delay = timers_.top()->GetCurrentDelay();
+ if (delay < 0)
+ delay = 0;
+ return delay;
}
void TimerManager::DidChangeNextTimer() {