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

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

Issue 2319053004: [Reland] Make canceling Timers fast. (Closed)
Patch Set: Rebased Created 4 years, 3 months 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
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 8ed079f3f31502703bc065e987c83d3562cddd48..58f59f0f5def11cedf1975d647b8700581b058bf 100644
--- a/third_party/WebKit/Source/platform/Timer.cpp
+++ b/third_party/WebKit/Source/platform/Timer.cpp
@@ -43,11 +43,11 @@ namespace blink {
TimerBase::TimerBase(WebTaskRunner* webTaskRunner)
: m_nextFireTime(0)
, m_repeatInterval(0)
- , m_cancellableTimerTask(nullptr)
, m_webTaskRunner(webTaskRunner->clone())
#if DCHECK_IS_ON()
, m_thread(currentThread())
#endif
+ , m_weakPtrFactory(this)
{
ASSERT(m_webTaskRunner);
}
@@ -72,9 +72,7 @@ void TimerBase::stop()
m_repeatInterval = 0;
m_nextFireTime = 0;
- if (m_cancellableTimerTask)
- m_cancellableTimerTask->cancel();
- m_cancellableTimerTask = nullptr;
+ m_weakPtrFactory.revokeAll();
}
double TimerBase::nextFireInterval() const
@@ -111,12 +109,12 @@ void TimerBase::setNextFireTime(double now, double delay)
if (m_nextFireTime != newTime) {
m_nextFireTime = newTime;
- if (m_cancellableTimerTask)
- m_cancellableTimerTask->cancel();
- m_cancellableTimerTask = new CancellableTimerTask(this);
+
+ // Cancel any previously posted task.
+ m_weakPtrFactory.revokeAll();
double delayMs = 1000.0 * (newTime - now);
- timerTaskRunner()->postDelayedTask(m_location, m_cancellableTimerTask, delayMs);
+ timerTaskRunner()->postDelayedTask(m_location, base::Bind(&TimerBase::runInternal, m_weakPtrFactory.createWeakPtr()), delayMs);
}
}
@@ -126,6 +124,8 @@ void TimerBase::runInternal()
if (!canFire())
return;
+ m_weakPtrFactory.revokeAll();
+
TRACE_EVENT0("blink", "TimerBase::run");
#if DCHECK_IS_ON()
DCHECK_EQ(m_thread, currentThread()) << "Timer posted by " << m_location.function_name() << " " << m_location.file_name() << " was run on a different thread";
« no previous file with comments | « third_party/WebKit/Source/platform/Timer.h ('k') | third_party/WebKit/Source/platform/scheduler/base/task_queue_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698