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

Unified Diff: third_party/WebKit/public/platform/scheduler/base/task_queue.h

Issue 2258713004: Make tasks cancellable inside the blink scheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Various comment nits addressed Created 4 years, 4 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 | « third_party/WebKit/Source/platform/scheduler/child/webthread_impl_for_worker_scheduler.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/scheduler/base/task_queue.h
diff --git a/third_party/WebKit/public/platform/scheduler/base/task_queue.h b/third_party/WebKit/public/platform/scheduler/base/task_queue.h
index 9dc47a325956e74bf4ccc6025fdbe84020a5b6ff..a38cb330afe30c750e592e99735054409b8660ab 100644
--- a/third_party/WebKit/public/platform/scheduler/base/task_queue.h
+++ b/third_party/WebKit/public/platform/scheduler/base/task_queue.h
@@ -8,7 +8,6 @@
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "base/single_thread_task_runner.h"
-#include "base/trace_event/trace_event.h"
#include "public/platform/WebCommon.h"
namespace base {
@@ -19,6 +18,10 @@ class BlameContext;
namespace blink {
namespace scheduler {
+namespace internal {
+class TaskQueueImpl;
+} // namespace internal
+class FakeWebTaskRunner;
class LazyNow;
class TimeDomain;
@@ -136,6 +139,49 @@ class BLINK_PLATFORM_EXPORT TaskQueue : public base::SingleThreadTaskRunner {
bool should_report_when_execution_blocked;
};
+ // Intended to be used as an opaque handle to a task posted by
+ // PostCancellableDelayedTask.
+ class BLINK_PLATFORM_EXPORT TaskHandle {
+ public:
+ TaskHandle();
+
+ // Returns false if the handle is equivalent to TaskHandle(), i.e. the
+ // handle doesn't represent a task that got posted.
+ operator bool() const;
+
+ private:
+ friend internal::TaskQueueImpl;
+ friend FakeWebTaskRunner;
+
+ // For immediate tasks.
+ TaskHandle(TaskQueue* task_queue, uint64_t enqueue_order);
+
+ // For delayed tasks.
+ TaskHandle(TaskQueue* task_queue,
+ base::TimeTicks scheduled_run_time,
+ int sequence_number);
+
+ uint64_t enqueue_order_;
+ base::TimeTicks scheduled_run_time_;
+#if DCHECK_IS_ON()
+ TaskQueue* task_queue_;
+#endif
+ int sequence_number_;
+ };
+
+ // 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 on the thread this TaskQueue was created by.
+ virtual TaskHandle PostCancellableDelayedTask(
+ const tracked_objects::Location& from_here,
+ const base::Closure& task,
+ base::TimeDelta delay) = 0;
+
+ // Attempts to cancel a task posted by PostCancellableDelayedTask. Returns
+ // true on success or false otherwise. NOTE this must be called on the thread
+ // this TaskQueue was created by.
+ virtual bool CancelTask(const TaskHandle& handle) = 0;
+
// Enable or disable task execution for this queue. NOTE this must be called
// on the thread this TaskQueue was created by.
virtual void SetQueueEnabled(bool enabled) = 0;
« no previous file with comments | « third_party/WebKit/Source/platform/scheduler/child/webthread_impl_for_worker_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698