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

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

Issue 876623002: Adds a CancellableTaskFactory and exposes postLoadingTasks to Blink (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 5 years, 11 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/blink_platform.gypi ('k') | Source/platform/scheduler/CancellableTaskFactory.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/scheduler/CancellableTaskFactory.h
diff --git a/Source/platform/scheduler/CancellableTaskFactory.h b/Source/platform/scheduler/CancellableTaskFactory.h
new file mode 100644
index 0000000000000000000000000000000000000000..7e44bcb5ffc50b550e317d9bc521a0540c7d098d
--- /dev/null
+++ b/Source/platform/scheduler/CancellableTaskFactory.h
@@ -0,0 +1,63 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CancellableTaskFactory_h
+#define CancellableTaskFactory_h
+
+#include "platform/PlatformExport.h"
+#include "public/platform/WebScheduler.h"
+#include "wtf/Functional.h"
+#include "wtf/Noncopyable.h"
+#include "wtf/OwnPtr.h"
+#include "wtf/PassOwnPtr.h"
+#include "wtf/RefCounted.h"
+#include "wtf/WeakPtr.h"
+
+namespace blink {
+class TraceLocation;
+
+class PLATFORM_EXPORT CancellableTaskFactory {
+ WTF_MAKE_NONCOPYABLE(CancellableTaskFactory);
+
+public:
+ explicit CancellableTaskFactory(PassOwnPtr<Closure> closure)
+ : m_closure(closure)
+ , m_weakPtrFactory(this)
+ {
+ }
+
+ bool isPending() const
+ {
+ return m_weakPtrFactory.hasWeakPtrs();
+ }
+
+ void cancel();
+
+ // Returns a task that can be disabled by calling cancel(). The user takes
+ // ownership of the task. Creating a new task cancels any previous ones.
+ WebThread::Task* task();
+
+private:
+ class CancellableTask : public WebThread::Task {
+ WTF_MAKE_NONCOPYABLE(CancellableTask);
+
+ public:
+ explicit CancellableTask(WeakPtr<CancellableTaskFactory> weakPtr)
+ : m_weakPtr(weakPtr) { }
+
+ virtual ~CancellableTask() { }
+
+ void run() override;
+
+ private:
+ WeakPtr<CancellableTaskFactory> m_weakPtr;
+ };
+
+ OwnPtr<Closure> m_closure;
+ WeakPtrFactory<CancellableTaskFactory> m_weakPtrFactory;
+};
+
+} // namespace blink
+
+#endif // CancellableTaskFactory_h
« no previous file with comments | « Source/platform/blink_platform.gypi ('k') | Source/platform/scheduler/CancellableTaskFactory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698