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 "public/platform/WebTraceLocation.h" | 9 #include "public/platform/WebTraceLocation.h" |
| 10 #include <memory> |
10 | 11 |
11 #ifdef INSIDE_BLINK | 12 #ifdef INSIDE_BLINK |
12 #include "wtf/Functional.h" | 13 #include "wtf/Functional.h" |
13 #include "wtf/PtrUtil.h" | |
14 #include <memory> | |
15 #endif | 14 #endif |
16 | 15 |
17 namespace blink { | 16 namespace blink { |
18 | 17 |
19 // The blink representation of a chromium SingleThreadTaskRunner. | 18 // The blink representation of a chromium SingleThreadTaskRunner. |
20 class BLINK_PLATFORM_EXPORT WebTaskRunner { | 19 class BLINK_PLATFORM_EXPORT WebTaskRunner { |
21 public: | 20 public: |
22 virtual ~WebTaskRunner() {} | 21 virtual ~WebTaskRunner() {} |
23 | 22 |
24 class BLINK_PLATFORM_EXPORT Task { | 23 class BLINK_PLATFORM_EXPORT Task { |
25 public: | 24 public: |
26 virtual ~Task() { } | 25 virtual ~Task() { } |
27 virtual void run() = 0; | 26 virtual void run() = 0; |
28 }; | 27 }; |
29 | 28 |
30 // Schedule a task to be run on the the associated WebThread. | 29 // Schedule a task to be run on the the associated WebThread. |
31 // Takes ownership of |Task|. Can be called from any thread. | 30 // Takes ownership of |Task|. Can be called from any thread. |
32 virtual void postTask(const WebTraceLocation&, Task*) = 0; | 31 virtual void postTask(const WebTraceLocation&, Task*) = 0; |
33 | 32 |
34 // Schedule a task to be run after |delayMs| on the the associated WebThread
. | 33 // Schedule a task to be run after |delayMs| on the the associated WebThread
. |
35 // Takes ownership of |Task|. Can be called from any thread. | 34 // Takes ownership of |Task|. Can be called from any thread. |
36 virtual void postDelayedTask(const WebTraceLocation&, Task*, double delayMs)
= 0; | 35 virtual void postDelayedTask(const WebTraceLocation&, Task*, double delayMs)
= 0; |
37 | 36 |
38 // Returns a clone of the WebTaskRunner. | 37 // Returns a clone of the WebTaskRunner. |
39 virtual WebTaskRunner* clone() = 0; | 38 virtual std::unique_ptr<WebTaskRunner> clone() = 0; |
40 | 39 |
41 // Returns true if the current thread is a thread on which a task may be run
. | 40 // Returns true if the current thread is a thread on which a task may be run
. |
42 // Can be called from any thread. | 41 // Can be called from any thread. |
43 virtual bool runsTasksOnCurrentThread() = 0; | 42 virtual bool runsTasksOnCurrentThread() = 0; |
44 | 43 |
45 // --- | 44 // --- |
46 | 45 |
47 // Headless Chrome virtualises time for determinism and performance (fast fo
rwarding | 46 // Headless Chrome virtualises time for determinism and performance (fast fo
rwarding |
48 // of timers). To make this work some parts of blink (e.g. Timers) need to u
se virtual | 47 // of timers). To make this work some parts of blink (e.g. Timers) need to u
se virtual |
49 // time, however by default new code should use the normal non-virtual time
APIs. | 48 // time, however by default new code should use the normal non-virtual time
APIs. |
(...skipping 13 matching lines...) Expand all Loading... |
63 #ifdef INSIDE_BLINK | 62 #ifdef INSIDE_BLINK |
64 // Helpers for posting bound functions as tasks. | 63 // Helpers for posting bound functions as tasks. |
65 | 64 |
66 // For cross-thread posting. Can be called from any thread. | 65 // For cross-thread posting. Can be called from any thread. |
67 void postTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); | 66 void postTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); |
68 void postDelayedTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClo
sure>, long long delayMs); | 67 void postDelayedTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClo
sure>, long long delayMs); |
69 | 68 |
70 // For same-thread posting. Must be called from the associated WebThread. | 69 // For same-thread posting. Must be called from the associated WebThread. |
71 void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); | 70 void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); |
72 void postDelayedTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>,
long long delayMs); | 71 void postDelayedTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>,
long long delayMs); |
73 | |
74 std::unique_ptr<WebTaskRunner> adoptClone() | |
75 { | |
76 return wrapUnique(clone()); | |
77 } | |
78 #endif | 72 #endif |
79 }; | 73 }; |
80 | 74 |
81 } // namespace blink | 75 } // namespace blink |
82 | 76 |
83 #endif // WebTaskRunner_h | 77 #endif // WebTaskRunner_h |
OLD | NEW |