Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Unified Diff: third_party/WebKit/Source/platform/Timer.cpp

Issue 1477353002: Revert of Move throttling of background timers into the renderer scheduler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/platform/Timer.h ('k') | third_party/WebKit/Source/platform/TimerTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/Timer.cpp
diff --git a/third_party/WebKit/Source/platform/Timer.cpp b/third_party/WebKit/Source/platform/Timer.cpp
index e27520d7f0a88df31102229e70df637a1ccbab0b..ad619a3cf12d69041cb403d9afafdd874e4e1037 100644
--- a/third_party/WebKit/Source/platform/Timer.cpp
+++ b/third_party/WebKit/Source/platform/Timer.cpp
@@ -43,6 +43,7 @@
TimerBase::TimerBase()
: m_nextFireTime(0)
+ , m_unalignedNextFireTime(0)
, m_repeatInterval(0)
, m_cancellableTimerTask(nullptr)
, m_webScheduler(Platform::current()->currentThread()->scheduler())
@@ -95,16 +96,23 @@
{
ASSERT(m_thread == currentThread());
- double newTime = now + delay;
+ m_unalignedNextFireTime = now + delay;
+ double newTime = alignedFireTime(m_unalignedNextFireTime);
if (m_nextFireTime != newTime) {
m_nextFireTime = newTime;
if (m_cancellableTimerTask)
m_cancellableTimerTask->cancel();
m_cancellableTimerTask = new CancellableTimerTask(this);
-
- double delayMs = 1000.0 * (newTime - now);
- timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTask, delayMs);
+ if (newTime != m_unalignedNextFireTime) {
+ // If the timer is being aligned, use postTimerTaskAt() to schedule it
+ // so that the relative order of aligned timers is preserved.
+ // TODO(skyostil): Move timer alignment into the scheduler.
+ m_webScheduler->postTimerTaskAt(m_location, m_cancellableTimerTask, m_nextFireTime);
+ } else {
+ double delayMs = 1000.0 * (newTime - now);
+ m_webScheduler->timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTask, delayMs);
+ }
}
}
@@ -118,24 +126,34 @@
ASSERT_WITH_MESSAGE(m_thread == currentThread(), "Timer posted by %s %s was run on a different thread", m_location.functionName(), m_location.fileName());
TRACE_EVENT_SET_SAMPLING_STATE("blink", "BlinkInternal");
+ m_nextFireTime = 0;
if (m_repeatInterval) {
double now = monotonicallyIncreasingTime();
// This computation should be drift free, and it will cope if we miss a beat,
// which can easily happen if the thread is busy. It will also cope if we get
// called slightly before m_unalignedNextFireTime, which can happen due to lack
// of timer precision.
- double intervalToNextFireTime = m_repeatInterval - fmod(now - m_nextFireTime, m_repeatInterval);
+ double intervalToNextFireTime = m_repeatInterval - fmod(now - m_unalignedNextFireTime, m_repeatInterval);
setNextFireTime(monotonicallyIncreasingTime(), intervalToNextFireTime);
- } else {
- m_nextFireTime = 0;
}
fired();
TRACE_EVENT_SET_SAMPLING_STATE("blink", "Sleeping");
}
+void TimerBase::didChangeAlignmentInterval(double now)
+{
+ setNextFireTime(now, m_unalignedNextFireTime - now);
+}
+
+double TimerBase::nextUnalignedFireInterval() const
+{
+ ASSERT(isActive());
+ return std::max(m_unalignedNextFireTime - monotonicallyIncreasingTime(), 0.0);
+}
+
bool TimerBase::Comparator::operator()(const TimerBase* a, const TimerBase* b) const
{
- return a->m_nextFireTime < b->m_nextFireTime;
+ return a->m_unalignedNextFireTime < b->m_unalignedNextFireTime;
}
} // namespace blink
« no previous file with comments | « third_party/WebKit/Source/platform/Timer.h ('k') | third_party/WebKit/Source/platform/TimerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698