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/Functional.h" | 14 #include "wtf/Functional.h" |
15 #include "wtf/RefCounted.h" | |
16 #include "wtf/WeakPtr.h" | |
15 #endif | 17 #endif |
16 | 18 |
17 namespace base { | 19 namespace base { |
18 class SingleThreadTaskRunner; | 20 class SingleThreadTaskRunner; |
19 } | 21 } |
20 | 22 |
21 namespace blink { | 23 namespace blink { |
22 | 24 |
23 using SingleThreadTaskRunner = base::SingleThreadTaskRunner; | 25 using SingleThreadTaskRunner = base::SingleThreadTaskRunner; |
24 | 26 |
27 #ifdef INSIDE_BLINK | |
28 | |
29 class BLINK_PLATFORM_EXPORT TaskHandle | |
30 : public WTF::ThreadSafeRefCounted<TaskHandle> { | |
31 public: | |
32 // Returns true if the task will run later. Returns false if the task is | |
33 // 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.
| |
34 // This function is not thread safe. Call this on the thread that has posted | |
35 // the task. | |
36 bool isActive() const; | |
37 | |
38 // 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.
| |
39 // already. | |
40 // This function is not thread safe. Call this on the thread that has posted | |
41 // the task. | |
42 void cancel(); | |
43 | |
44 ~TaskHandle(); | |
45 | |
46 private: | |
47 class CancelOnScopeOut; | |
48 friend class WebTaskRunner; | |
49 | |
50 explicit TaskHandle(std::unique_ptr<WTF::Closure> task); | |
51 void run(const ClearOnScopeOut&); | |
52 WTF::WeakPtr<TaskHandle> asWeakPtr(); | |
53 | |
54 std::unique_ptr<WTF::Closure> m_task; | |
55 WTF::WeakPtrFactory<TaskHandle> m_weakPtrFactory; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(TaskHandle); | |
58 }; | |
59 | |
60 #endif | |
61 | |
25 // The blink representation of a chromium SingleThreadTaskRunner. | 62 // The blink representation of a chromium SingleThreadTaskRunner. |
26 class BLINK_PLATFORM_EXPORT WebTaskRunner { | 63 class BLINK_PLATFORM_EXPORT WebTaskRunner { |
27 public: | 64 public: |
28 virtual ~WebTaskRunner() {} | 65 virtual ~WebTaskRunner() {} |
29 | 66 |
30 class BLINK_PLATFORM_EXPORT Task { | 67 class BLINK_PLATFORM_EXPORT Task { |
31 public: | 68 public: |
32 virtual ~Task() {} | 69 virtual ~Task() {} |
33 virtual void run() = 0; | 70 virtual void run() = 0; |
34 }; | 71 }; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 void postTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); | 122 void postTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); |
86 void postDelayedTask(const WebTraceLocation&, | 123 void postDelayedTask(const WebTraceLocation&, |
87 std::unique_ptr<CrossThreadClosure>, | 124 std::unique_ptr<CrossThreadClosure>, |
88 long long delayMs); | 125 long long delayMs); |
89 | 126 |
90 // For same-thread posting. Must be called from the associated WebThread. | 127 // For same-thread posting. Must be called from the associated WebThread. |
91 void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); | 128 void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); |
92 void postDelayedTask(const WebTraceLocation&, | 129 void postDelayedTask(const WebTraceLocation&, |
93 std::unique_ptr<WTF::Closure>, | 130 std::unique_ptr<WTF::Closure>, |
94 long long delayMs); | 131 long long delayMs); |
132 | |
133 // For same-thread cancellable task posting. Returns a TaskHandle object for | |
134 // cancellation. | |
135 RefPtr<TaskHandle> postCancellableTask(const WebTraceLocation&, | |
136 std::unique_ptr<WTF::Closure>); | |
137 RefPtr<TaskHandle> postDelayedCancellableTask(const WebTraceLocation&, | |
138 std::unique_ptr<WTF::Closure>, | |
139 long long delayMs); | |
95 #endif | 140 #endif |
96 }; | 141 }; |
97 | 142 |
98 } // namespace blink | 143 } // namespace blink |
99 | 144 |
100 #endif // WebTaskRunner_h | 145 #endif // WebTaskRunner_h |
OLD | NEW |