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 "base/callback_forward.h" | 8 #include "base/callback_forward.h" |
9 #include "public/platform/WebCommon.h" | 9 #include "public/platform/WebCommon.h" |
10 #include "public/platform/WebTraceLocation.h" | 10 #include "public/platform/WebTraceLocation.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 class Runner; | 49 class Runner; |
50 | 50 |
51 private: | 51 private: |
52 friend class WebTaskRunner; | 52 friend class WebTaskRunner; |
53 | 53 |
54 explicit TaskHandle(RefPtr<Runner>); | 54 explicit TaskHandle(RefPtr<Runner>); |
55 RefPtr<Runner> m_runner; | 55 RefPtr<Runner> m_runner; |
56 }; | 56 }; |
57 | 57 |
58 // The blink representation of a chromium SingleThreadTaskRunner. | 58 // The blink representation of a chromium SingleThreadTaskRunner. |
59 class BLINK_PLATFORM_EXPORT WebTaskRunner { | 59 class BLINK_PLATFORM_EXPORT WebTaskRunner |
| 60 : public ThreadSafeRefCounted<WebTaskRunner> { |
60 public: | 61 public: |
61 virtual ~WebTaskRunner() {} | |
62 | |
63 // Schedule a task to be run after |delayMs| on the the associated WebThread. | 62 // Schedule a task to be run after |delayMs| on the the associated WebThread. |
64 // Can be called from any thread. | 63 // Can be called from any thread. |
65 virtual void postDelayedTask(const WebTraceLocation&, | 64 virtual void postDelayedTask(const WebTraceLocation&, |
66 const base::Closure&, | 65 const base::Closure&, |
67 double delayMs) = 0; | 66 double delayMs) = 0; |
68 | 67 |
69 // Returns a clone of the WebTaskRunner. | |
70 virtual std::unique_ptr<WebTaskRunner> clone() = 0; | |
71 | |
72 // Returns true if the current thread is a thread on which a task may be run. | 68 // Returns true if the current thread is a thread on which a task may be run. |
73 // Can be called from any thread. | 69 // Can be called from any thread. |
74 virtual bool runsTasksOnCurrentThread() = 0; | 70 virtual bool runsTasksOnCurrentThread() = 0; |
75 | 71 |
76 // --- | 72 // --- |
77 | 73 |
78 // Headless Chrome virtualises time for determinism and performance (fast | 74 // Headless Chrome virtualises time for determinism and performance (fast |
79 // forwarding of timers). To make this work some parts of blink (e.g. Timers) | 75 // forwarding of timers). To make this work some parts of blink (e.g. Timers) |
80 // need to use virtual time, however by default new code should use the normal | 76 // need to use virtual time, however by default new code should use the normal |
81 // non-virtual time APIs. | 77 // non-virtual time APIs. |
(...skipping 28 matching lines...) Expand all Loading... |
110 long long delayMs); | 106 long long delayMs); |
111 | 107 |
112 // For same-thread cancellable task posting. Returns a TaskHandle object for | 108 // For same-thread cancellable task posting. Returns a TaskHandle object for |
113 // cancellation. | 109 // cancellation. |
114 WARN_UNUSED_RESULT TaskHandle | 110 WARN_UNUSED_RESULT TaskHandle |
115 postCancellableTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); | 111 postCancellableTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); |
116 WARN_UNUSED_RESULT TaskHandle | 112 WARN_UNUSED_RESULT TaskHandle |
117 postDelayedCancellableTask(const WebTraceLocation&, | 113 postDelayedCancellableTask(const WebTraceLocation&, |
118 std::unique_ptr<WTF::Closure>, | 114 std::unique_ptr<WTF::Closure>, |
119 long long delayMs); | 115 long long delayMs); |
| 116 |
| 117 protected: |
| 118 friend ThreadSafeRefCounted<WebTaskRunner>; |
| 119 WebTaskRunner() = default; |
| 120 virtual ~WebTaskRunner(); |
| 121 |
| 122 private: |
| 123 DISALLOW_COPY_AND_ASSIGN(WebTaskRunner); |
120 }; | 124 }; |
121 | 125 |
122 } // namespace blink | 126 } // namespace blink |
123 | 127 |
124 #endif // WebTaskRunner_h | 128 #endif // WebTaskRunner_h |
OLD | NEW |