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..3dc22b7fc7e3c019da2eda07250a048aba8b88ab 100644 |
--- a/third_party/WebKit/public/platform/WebTaskRunner.h |
+++ b/third_party/WebKit/public/platform/WebTaskRunner.h |
@@ -12,6 +12,8 @@ |
#ifdef INSIDE_BLINK |
#include "wtf/Functional.h" |
+#include "wtf/RefCounted.h" |
+#include "wtf/WeakPtr.h" |
#endif |
namespace base { |
@@ -22,6 +24,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 +129,14 @@ 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>); |
+ RefPtr<TaskHandle> postDelayedCancellableTask(const WebTraceLocation&, |
dcheng
2016/10/26 01:58:54
Does it make sense to mark these as WARN_UNUSED_RE
tzik
2016/10/27 06:38:53
Done.
|
+ std::unique_ptr<WTF::Closure>, |
+ long long delayMs); |
#endif |
}; |