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 6e2bbd8e1647d3efd65dbe8562dcb11905a83621..9c8092064b0c996bf0adc709da58b5fc906cb46d 100644 |
--- a/third_party/WebKit/public/platform/WebTaskRunner.h |
+++ b/third_party/WebKit/public/platform/WebTaskRunner.h |
@@ -7,6 +7,7 @@ |
#include "WebCommon.h" |
#include "public/platform/WebTraceLocation.h" |
+#include "public/platform/scheduler/base/task_queue.h" |
#include <memory> |
#ifdef INSIDE_BLINK |
@@ -22,10 +23,14 @@ namespace blink { |
using SingleThreadTaskRunner = base::SingleThreadTaskRunner; |
// The blink representation of a chromium SingleThreadTaskRunner. |
+// TODO(alexclarke): Rename to PlatformTaskRunner and move onto the oilpan heap. |
+// TODO(alexclarke): Consider using base::TimeDelta for the delays. (crbug.com/402027) |
class BLINK_PLATFORM_EXPORT WebTaskRunner { |
public: |
virtual ~WebTaskRunner() {} |
+ using TaskHandle = scheduler::TaskQueue::TaskHandle; |
+ |
class BLINK_PLATFORM_EXPORT Task { |
public: |
virtual ~Task() { } |
@@ -40,6 +45,19 @@ public: |
// Takes ownership of |Task|. Can be called from any thread. |
virtual void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) = 0; |
+ // Posts the given task to be run after |delay| has passed. Returns a handle |
+ // which can be passed to cancelTask to cancel the task before it has run. |
+ // Note this must be called from the thread the tasks are run on (i.e the |
+ // thread where runsTasksOnCurrentThread returns true). |
+ virtual TaskHandle postCancellableDelayedTask(const tracked_objects::Location&, const base::Closure&, double delayMs) = 0; |
alex clarke (OOO till 29th)
2016/08/22 17:43:01
Daniel on the other patch you expressed some API c
|
+ |
+ // Attempts to cancel a task posted by PostCancellableDelayedTask. Returns |
+ // true on success or false otherwise. Note this will fail unless called on |
+ // the same WebTaskRunner that was used to post the task. Note this must be |
+ // called from the thread the tasks are run on (i.e the thread where |
+ // runsTasksOnCurrentThread returns true). |
+ virtual bool cancelTask(const TaskHandle&) = 0; |
+ |
// Returns a clone of the WebTaskRunner. |
virtual std::unique_ptr<WebTaskRunner> clone() = 0; |
@@ -66,7 +84,7 @@ public: |
virtual double monotonicallyIncreasingVirtualTimeSeconds() const = 0; |
// Returns the underlying task runner object. |
- virtual SingleThreadTaskRunner* taskRunner() = 0; |
+ virtual SingleThreadTaskRunner* toSingleThreadTaskRunner() = 0; |
#ifdef INSIDE_BLINK |
// Helpers for posting bound functions as tasks. |
@@ -78,6 +96,12 @@ public: |
// For same-thread posting. Must be called from the associated WebThread. |
void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); |
void postDelayedTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>, long long delayMs); |
+ |
+ // Posts the given same-thread closure to be run after |delay| has passed. |
+ // Returns a handle which can be passed to cancelTask to cancel the task |
+ // before it has run. Note this must be called from the thread the tasks are |
+ // run on (i.e the thread where runsTasksOnCurrentThread returns true). |
+ TaskHandle postCancellableDelayedTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>, double delayMs); |
#endif |
}; |