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

Unified Diff: third_party/WebKit/public/platform/WebTaskRunner.h

Issue 2353913005: Add WebTaskRunner::postCancellableTask (Closed)
Patch Set: rebase Created 4 years, 1 month 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 | « third_party/WebKit/Source/platform/scheduler/test/fake_web_task_runner.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/public/platform/WebTaskRunner.h
diff --git a/third_party/WebKit/public/platform/WebTaskRunner.h b/third_party/WebKit/public/platform/WebTaskRunner.h
index c3997edf93925498118ec104038b6191146328d9..c1ec7e6cf97bf6e3529c56631cb8367bc0945bae 100644
--- a/third_party/WebKit/public/platform/WebTaskRunner.h
+++ b/third_party/WebKit/public/platform/WebTaskRunner.h
@@ -11,7 +11,10 @@
#include <memory>
#ifdef INSIDE_BLINK
+#include "wtf/Compiler.h"
#include "wtf/Functional.h"
+#include "wtf/RefCounted.h"
+#include "wtf/WeakPtr.h"
#endif
namespace base {
@@ -22,6 +25,41 @@ namespace blink {
using SingleThreadTaskRunner = base::SingleThreadTaskRunner;
+#ifdef INSIDE_BLINK
+
+class BLINK_PLATFORM_EXPORT TaskHandle
+ : public WTF::ThreadSafeRefCounted<TaskHandle> {
+ public:
+ // Returns true if the task will run later. Returns false if the task is
+ // cancelled or the task is run already.
+ // This function is not thread safe. Call this on the thread that has posted
+ // the task.
+ bool isActive() const;
+
+ // Cancels the task invocation. Do nothing if the task is cancelled or run
+ // already.
+ // This function is not thread safe. Call this on the thread that has posted
+ // the task.
+ void cancel();
+
+ ~TaskHandle();
+
+ private:
+ class CancelOnTaskDestruction;
+ friend class WebTaskRunner;
+
+ explicit TaskHandle(std::unique_ptr<WTF::Closure> task);
+ void run(const CancelOnTaskDestruction&);
+ WTF::WeakPtr<TaskHandle> asWeakPtr();
+
+ std::unique_ptr<WTF::Closure> m_task;
+ WTF::WeakPtrFactory<TaskHandle> m_weakPtrFactory;
+
+ DISALLOW_COPY_AND_ASSIGN(TaskHandle);
+};
+
+#endif
+
// The blink representation of a chromium SingleThreadTaskRunner.
class BLINK_PLATFORM_EXPORT WebTaskRunner {
public:
@@ -92,6 +130,16 @@ class BLINK_PLATFORM_EXPORT WebTaskRunner {
void postDelayedTask(const WebTraceLocation&,
std::unique_ptr<WTF::Closure>,
long long delayMs);
+
+ // For same-thread cancellable task posting. Returns a TaskHandle object for
+ // cancellation.
+ RefPtr<TaskHandle> postCancellableTask(const WebTraceLocation&,
+ std::unique_ptr<WTF::Closure>)
+ WARN_UNUSED_RETURN;
+ RefPtr<TaskHandle> postDelayedCancellableTask(const WebTraceLocation&,
+ std::unique_ptr<WTF::Closure>,
+ long long delayMs)
+ WARN_UNUSED_RETURN;
#endif
};
« no previous file with comments | « third_party/WebKit/Source/platform/scheduler/test/fake_web_task_runner.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698