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

Unified Diff: Source/platform/Timer.cpp

Issue 1185643002: Lazily constructed bespoke cancellable timer task. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix UAF bug that occured on worker shutdown, where ~CancellableTimerTask wasn't clearing backref Created 5 years, 6 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
« no previous file with comments | « Source/platform/Timer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/Timer.cpp
diff --git a/Source/platform/Timer.cpp b/Source/platform/Timer.cpp
index 235966fbe161907dcd30d864fa748b1284e644e4..33f33481e0e166583ae9c0817637767e09da58e0 100644
--- a/Source/platform/Timer.cpp
+++ b/Source/platform/Timer.cpp
@@ -29,6 +29,7 @@
#include "platform/TraceEvent.h"
#include "public/platform/Platform.h"
+#include "public/platform/WebScheduler.h"
#include "wtf/AddressSanitizer.h"
#include "wtf/Atomics.h"
#include "wtf/CurrentTime.h"
@@ -44,7 +45,7 @@ TimerBase::TimerBase()
: m_nextFireTime(0)
, m_unalignedNextFireTime(0)
, m_repeatInterval(0)
- , m_cancellableTaskFactory(WTF::bind(&TimerBase::run, this))
+ , m_cancellableTimerTask(nullptr)
, m_webScheduler(Platform::current()->currentThread()->scheduler())
#if ENABLE(ASSERT)
, m_thread(currentThread())
@@ -72,7 +73,9 @@ void TimerBase::stop()
m_repeatInterval = 0;
m_nextFireTime = 0;
- m_cancellableTaskFactory.cancel();
+ if (m_cancellableTimerTask)
+ m_cancellableTimerTask->cancel();
+ m_cancellableTimerTask = nullptr;
}
double TimerBase::nextFireInterval() const
@@ -98,12 +101,15 @@ void TimerBase::setNextFireTime(double now, double delay)
long long delayMs = static_cast<long long>(ceil((newTime - now) * 1000.0));
if (delayMs < 0)
delayMs = 0;
- m_webScheduler->postTimerTask(m_location, m_cancellableTaskFactory.cancelAndCreate(), delayMs);
+ if (m_cancellableTimerTask)
+ m_cancellableTimerTask->cancel();
+ m_cancellableTimerTask = new CancellableTimerTask(this);
+ m_webScheduler->postTimerTask(m_location, m_cancellableTimerTask, delayMs);
}
}
NO_LAZY_SWEEP_SANITIZE_ADDRESS
-void TimerBase::run()
+void TimerBase::runInternal()
{
if (!canFire())
return;
« no previous file with comments | « Source/platform/Timer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698