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

Unified Diff: third_party/WebKit/Source/platform/WebTaskRunner.cpp

Issue 2487493004: Support external task cancellation mechanisms in base::Callback::IsCancelled (Closed)
Patch Set: . 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
Index: third_party/WebKit/Source/platform/WebTaskRunner.cpp
diff --git a/third_party/WebKit/Source/platform/WebTaskRunner.cpp b/third_party/WebKit/Source/platform/WebTaskRunner.cpp
index 059abdf83d05f66c7baf472599d312d4509ab646..2e800aee93f7afd21a026284e34fc7d516adf287 100644
--- a/third_party/WebKit/Source/platform/WebTaskRunner.cpp
+++ b/third_party/WebKit/Source/platform/WebTaskRunner.cpp
@@ -4,8 +4,29 @@
#include "platform/WebTaskRunner.h"
+#include "base/bind_helpers.h"
#include "base/single_thread_task_runner.h"
+namespace base {
+
+using RunnerMethodType =
+ void (blink::TaskHandle::Runner::*)(const blink::TaskHandle&);
+
+template <>
+struct BindCancellationChecker<
+ RunnerMethodType,
+ std::tuple<WTF::WeakPtr<blink::TaskHandle::Runner>, blink::TaskHandle>> {
+ static constexpr bool is_cancellable = true;
+
+ static bool Run(RunnerMethodType,
+ const WTF::WeakPtr<blink::TaskHandle::Runner>&,
+ const blink::TaskHandle& handle) {
+ return !handle.isActive();
+ }
+};
+
+} // namespace base
+
namespace blink {
class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> {
@@ -15,7 +36,7 @@ class TaskHandle::Runner : public WTF::ThreadSafeRefCounted<Runner> {
WTF::WeakPtr<Runner> asWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
- bool isActive() { return static_cast<bool>(m_task); }
+ bool isActive() const { return m_task && !m_task->isCancelled(); }
void cancel() {
std::unique_ptr<WTF::Closure> task = std::move(m_task);

Powered by Google App Engine
This is Rietveld 408576698