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

Unified Diff: Source/platform/scheduler/CancellableTaskFactory.h

Issue 956333002: Refactor TimeBase to post tasks. Workers to use real Idle tasks. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix a bunch of stuff Created 5 years, 10 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: Source/platform/scheduler/CancellableTaskFactory.h
diff --git a/Source/platform/scheduler/CancellableTaskFactory.h b/Source/platform/scheduler/CancellableTaskFactory.h
index 7e44bcb5ffc50b550e317d9bc521a0540c7d098d..3ba126a70f73f2b3a7963116800cc46baa20e16d 100644
--- a/Source/platform/scheduler/CancellableTaskFactory.h
+++ b/Source/platform/scheduler/CancellableTaskFactory.h
@@ -17,19 +17,28 @@
namespace blink {
class TraceLocation;
+// NOTE CancellableTaskFactory is NOT threadsafe.
class PLATFORM_EXPORT CancellableTaskFactory {
WTF_MAKE_NONCOPYABLE(CancellableTaskFactory);
public:
explicit CancellableTaskFactory(PassOwnPtr<Closure> closure)
: m_closure(closure)
- , m_weakPtrFactory(this)
+ , m_task(nullptr)
+#if ENABLE(ASSERT)
+ , m_thread(currentThread())
+#endif
{
}
+ ~CancellableTaskFactory()
+ {
+ cancel();
+ }
+
bool isPending() const
{
- return m_weakPtrFactory.hasWeakPtrs();
+ return m_task;
}
void cancel();
@@ -41,21 +50,33 @@ public:
private:
class CancellableTask : public WebThread::Task {
WTF_MAKE_NONCOPYABLE(CancellableTask);
+ WTF_MAKE_FAST_ALLOCATED;
public:
- explicit CancellableTask(WeakPtr<CancellableTaskFactory> weakPtr)
- : m_weakPtr(weakPtr) { }
+ explicit CancellableTask(CancellableTaskFactory* factory)
+ : m_factory(factory)
+ {
+ }
virtual ~CancellableTask() { }
void run() override;
+ void cancel()
+ {
+ m_factory = nullptr;
+ }
+
private:
- WeakPtr<CancellableTaskFactory> m_weakPtr;
+ CancellableTaskFactory* m_factory; // NOT OWNED
};
OwnPtr<Closure> m_closure;
- WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory;
+ CancellableTask* m_task; // NOT OWNED
+
+#if ENABLE(ASSERT)
+ ThreadIdentifier m_thread;
+#endif
};
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698