| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WebTaskRunner_h | 5 #ifndef WebTaskRunner_h |
| 6 #define WebTaskRunner_h | 6 #define WebTaskRunner_h |
| 7 | 7 |
| 8 #include "WebCommon.h" | 8 #include "WebCommon.h" |
| 9 #include "base/callback_forward.h" | 9 #include "base/callback_forward.h" |
| 10 #include "public/platform/WebTraceLocation.h" | 10 #include "public/platform/WebTraceLocation.h" |
| 11 #include <memory> | 11 #include <memory> |
| 12 | 12 |
| 13 #ifdef INSIDE_BLINK | 13 #ifdef INSIDE_BLINK |
| 14 #include "wtf/Compiler.h" |
| 14 #include "wtf/Functional.h" | 15 #include "wtf/Functional.h" |
| 16 #include "wtf/RefCounted.h" |
| 17 #include "wtf/WeakPtr.h" |
| 15 #endif | 18 #endif |
| 16 | 19 |
| 17 namespace base { | 20 namespace base { |
| 18 class SingleThreadTaskRunner; | 21 class SingleThreadTaskRunner; |
| 19 } | 22 } |
| 20 | 23 |
| 21 namespace blink { | 24 namespace blink { |
| 22 | 25 |
| 23 using SingleThreadTaskRunner = base::SingleThreadTaskRunner; | 26 using SingleThreadTaskRunner = base::SingleThreadTaskRunner; |
| 24 | 27 |
| 28 #ifdef INSIDE_BLINK |
| 29 |
| 30 class BLINK_PLATFORM_EXPORT TaskHandle |
| 31 : public WTF::ThreadSafeRefCounted<TaskHandle> { |
| 32 public: |
| 33 // Returns true if the task will run later. Returns false if the task is |
| 34 // cancelled or the task is run already. |
| 35 // This function is not thread safe. Call this on the thread that has posted |
| 36 // the task. |
| 37 bool isActive() const; |
| 38 |
| 39 // Cancels the task invocation. Do nothing if the task is cancelled or run |
| 40 // already. |
| 41 // This function is not thread safe. Call this on the thread that has posted |
| 42 // the task. |
| 43 void cancel(); |
| 44 |
| 45 ~TaskHandle(); |
| 46 |
| 47 private: |
| 48 class CancelOnTaskDestruction; |
| 49 friend class WebTaskRunner; |
| 50 |
| 51 explicit TaskHandle(std::unique_ptr<WTF::Closure> task); |
| 52 void run(const CancelOnTaskDestruction&); |
| 53 WTF::WeakPtr<TaskHandle> asWeakPtr(); |
| 54 |
| 55 std::unique_ptr<WTF::Closure> m_task; |
| 56 WTF::WeakPtrFactory<TaskHandle> m_weakPtrFactory; |
| 57 |
| 58 DISALLOW_COPY_AND_ASSIGN(TaskHandle); |
| 59 }; |
| 60 |
| 61 #endif |
| 62 |
| 25 // The blink representation of a chromium SingleThreadTaskRunner. | 63 // The blink representation of a chromium SingleThreadTaskRunner. |
| 26 class BLINK_PLATFORM_EXPORT WebTaskRunner { | 64 class BLINK_PLATFORM_EXPORT WebTaskRunner { |
| 27 public: | 65 public: |
| 28 virtual ~WebTaskRunner() {} | 66 virtual ~WebTaskRunner() {} |
| 29 | 67 |
| 30 class BLINK_PLATFORM_EXPORT Task { | 68 class BLINK_PLATFORM_EXPORT Task { |
| 31 public: | 69 public: |
| 32 virtual ~Task() {} | 70 virtual ~Task() {} |
| 33 virtual void run() = 0; | 71 virtual void run() = 0; |
| 34 }; | 72 }; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 void postTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); | 123 void postTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); |
| 86 void postDelayedTask(const WebTraceLocation&, | 124 void postDelayedTask(const WebTraceLocation&, |
| 87 std::unique_ptr<CrossThreadClosure>, | 125 std::unique_ptr<CrossThreadClosure>, |
| 88 long long delayMs); | 126 long long delayMs); |
| 89 | 127 |
| 90 // For same-thread posting. Must be called from the associated WebThread. | 128 // For same-thread posting. Must be called from the associated WebThread. |
| 91 void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); | 129 void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); |
| 92 void postDelayedTask(const WebTraceLocation&, | 130 void postDelayedTask(const WebTraceLocation&, |
| 93 std::unique_ptr<WTF::Closure>, | 131 std::unique_ptr<WTF::Closure>, |
| 94 long long delayMs); | 132 long long delayMs); |
| 133 |
| 134 // For same-thread cancellable task posting. Returns a TaskHandle object for |
| 135 // cancellation. |
| 136 RefPtr<TaskHandle> postCancellableTask(const WebTraceLocation&, |
| 137 std::unique_ptr<WTF::Closure>) |
| 138 WARN_UNUSED_RETURN; |
| 139 RefPtr<TaskHandle> postDelayedCancellableTask(const WebTraceLocation&, |
| 140 std::unique_ptr<WTF::Closure>, |
| 141 long long delayMs) |
| 142 WARN_UNUSED_RETURN; |
| 95 #endif | 143 #endif |
| 96 }; | 144 }; |
| 97 | 145 |
| 98 } // namespace blink | 146 } // namespace blink |
| 99 | 147 |
| 100 #endif // WebTaskRunner_h | 148 #endif // WebTaskRunner_h |
| OLD | NEW |