Chromium Code Reviews| 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..5b73e35bcebb86da2c06b4de0603bfaf5639cd6a 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 ran already. |
|
haraken
2016/10/20 17:07:37
run (or completed)
tzik
2016/10/25 07:03:52
Done.
|
| + // 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 ran |
|
haraken
2016/10/20 17:07:37
Ditto.
tzik
2016/10/25 07:03:52
Done.
|
| + // already. |
| + // This function is not thread safe. Call this on the thread that has posted |
| + // the task. |
| + void cancel(); |
| + |
| + ~TaskHandle(); |
| + |
| + private: |
| + class CancelOnScopeOut; |
| + friend class WebTaskRunner; |
| + |
| + explicit TaskHandle(std::unique_ptr<WTF::Closure> task); |
| + void run(const ClearOnScopeOut&); |
| + 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&, |
| + std::unique_ptr<WTF::Closure>, |
| + long long delayMs); |
| #endif |
| }; |