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

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

Issue 2326313003: Revert of Make canceling Timers fast. (Closed)
Patch Set: 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/Timer.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.h
diff --git a/third_party/WebKit/Source/platform/Timer.h b/third_party/WebKit/Source/platform/Timer.h
index 1a1b6f60001b496f95995f03ae92f241a2302d14..6269416f8e85f0a0b4ded5f5c8cee0b5f70bd47a 100644
--- a/third_party/WebKit/Source/platform/Timer.h
+++ b/third_party/WebKit/Source/platform/Timer.h
@@ -36,7 +36,6 @@
#include "wtf/Noncopyable.h"
#include "wtf/Threading.h"
#include "wtf/Vector.h"
-#include "wtf/WeakPtr.h"
namespace blink {
@@ -59,8 +58,8 @@
start(interval, 0, caller);
}
- // Timer cancellation is fast enough that you shouldn't have to worry
- // about it unless you're canceling tens of thousands of tasks.
+ // Timer cancellation is supported but not free. Please be careful not to
+ // cause a flood of timer cancellations.
void stop();
bool isActive() const;
const WebTraceLocation& location() const { return m_location; }
@@ -96,15 +95,46 @@
void runInternal();
+ class CancellableTimerTask final : public WebTaskRunner::Task {
+ WTF_MAKE_NONCOPYABLE(CancellableTimerTask);
+ public:
+ explicit CancellableTimerTask(TimerBase* timer) : m_timer(timer) { }
+
+ NO_LAZY_SWEEP_SANITIZE_ADDRESS
+ ~CancellableTimerTask() override
+ {
+ if (m_timer)
+ m_timer->m_cancellableTimerTask = nullptr;
+ }
+
+ NO_LAZY_SWEEP_SANITIZE_ADDRESS
+ void run() override
+ {
+ if (m_timer) {
+ m_timer->m_cancellableTimerTask = nullptr;
+ m_timer->runInternal();
+ m_timer = nullptr;
+ }
+ }
+
+ void cancel()
+ {
+ m_timer = nullptr;
+ }
+
+ private:
+ TimerBase* m_timer; // NOT OWNED
+ };
+
double m_nextFireTime; // 0 if inactive
double m_repeatInterval; // 0 if not repeating
WebTraceLocation m_location;
+ CancellableTimerTask* m_cancellableTimerTask; // NOT OWNED
std::unique_ptr<WebTaskRunner> m_webTaskRunner;
#if DCHECK_IS_ON()
ThreadIdentifier m_thread;
#endif
- WTF::WeakPtrFactory<TimerBase> m_weakPtrFactory;
friend class ThreadTimers;
friend class TimerHeapLessThanFunction;
@@ -197,7 +227,7 @@
inline bool TimerBase::isActive() const
{
ASSERT(m_thread == currentThread());
- return m_weakPtrFactory.hasWeakPtrs();
+ return m_cancellableTimerTask;
}
} // namespace blink
« no previous file with comments | « no previous file | third_party/WebKit/Source/platform/Timer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698