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

Side by Side Diff: third_party/WebKit/public/platform/WebTaskRunner.h

Issue 2266443002: Optimize posting of WTF::Closure and improve scheduler test mocks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix FakeWebTaskRunner leak Created 4 years, 4 months 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 unified diff | Download patch
OLDNEW
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 "public/platform/scheduler/base/task_queue.h"
10 #include <memory> 11 #include <memory>
11 12
12 #ifdef INSIDE_BLINK 13 #ifdef INSIDE_BLINK
13 #include "wtf/Functional.h" 14 #include "wtf/Functional.h"
14 #endif 15 #endif
15 16
16 namespace base { 17 namespace base {
17 class SingleThreadTaskRunner; 18 class SingleThreadTaskRunner;
18 } 19 }
19 20
20 namespace blink { 21 namespace blink {
21 22
22 using SingleThreadTaskRunner = base::SingleThreadTaskRunner; 23 using SingleThreadTaskRunner = base::SingleThreadTaskRunner;
23 24
24 // The blink representation of a chromium SingleThreadTaskRunner. 25 // The blink representation of a chromium SingleThreadTaskRunner.
26 // TODO(alexclarke): Rename to PlatformTaskRunner and move onto the oilpan heap.
27 // TODO(alexclarke): Consider using base::TimeDelta for the delays. (crbug.com/4 02027)
25 class BLINK_PLATFORM_EXPORT WebTaskRunner { 28 class BLINK_PLATFORM_EXPORT WebTaskRunner {
26 public: 29 public:
27 virtual ~WebTaskRunner() {} 30 virtual ~WebTaskRunner() {}
28 31
32 using TaskHandle = scheduler::TaskQueue::TaskHandle;
33
29 class BLINK_PLATFORM_EXPORT Task { 34 class BLINK_PLATFORM_EXPORT Task {
30 public: 35 public:
31 virtual ~Task() { } 36 virtual ~Task() { }
32 virtual void run() = 0; 37 virtual void run() = 0;
33 }; 38 };
34 39
35 // Schedule a task to be run on the the associated WebThread. 40 // Schedule a task to be run on the the associated WebThread.
36 // Takes ownership of |Task|. Can be called from any thread. 41 // Takes ownership of |Task|. Can be called from any thread.
37 virtual void postTask(const WebTraceLocation&, Task*) = 0; 42 virtual void postTask(const WebTraceLocation&, Task*) = 0;
38 43
39 // Schedule a task to be run after |delayMs| on the the associated WebThread . 44 // Schedule a task to be run after |delayMs| on the the associated WebThread .
40 // Takes ownership of |Task|. Can be called from any thread. 45 // Takes ownership of |Task|. Can be called from any thread.
41 virtual void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) = 0; 46 virtual void postDelayedTask(const WebTraceLocation&, Task*, double delayMs) = 0;
42 47
48 // Posts the given task to be run after |delay| has passed. Returns a handle
49 // which can be passed to cancelTask to cancel the task before it has run.
50 // Note this must be called from the thread the tasks are run on (i.e the
51 // thread where runsTasksOnCurrentThread returns true).
52 virtual TaskHandle postCancellableDelayedTask(const tracked_objects::Locatio n&, const base::Closure&, double delayMs) = 0;
alex clarke (OOO till 29th) 2016/08/22 17:43:01 Daniel on the other patch you expressed some API c
53
54 // Attempts to cancel a task posted by PostCancellableDelayedTask. Returns
55 // true on success or false otherwise. Note this will fail unless called on
56 // the same WebTaskRunner that was used to post the task. Note this must be
57 // called from the thread the tasks are run on (i.e the thread where
58 // runsTasksOnCurrentThread returns true).
59 virtual bool cancelTask(const TaskHandle&) = 0;
60
43 // Returns a clone of the WebTaskRunner. 61 // Returns a clone of the WebTaskRunner.
44 virtual std::unique_ptr<WebTaskRunner> clone() = 0; 62 virtual std::unique_ptr<WebTaskRunner> clone() = 0;
45 63
46 // Returns true if the current thread is a thread on which a task may be run . 64 // Returns true if the current thread is a thread on which a task may be run .
47 // Can be called from any thread. 65 // Can be called from any thread.
48 virtual bool runsTasksOnCurrentThread() = 0; 66 virtual bool runsTasksOnCurrentThread() = 0;
49 67
50 // --- 68 // ---
51 69
52 // Headless Chrome virtualises time for determinism and performance (fast fo rwarding 70 // Headless Chrome virtualises time for determinism and performance (fast fo rwarding
53 // of timers). To make this work some parts of blink (e.g. Timers) need to u se virtual 71 // of timers). To make this work some parts of blink (e.g. Timers) need to u se virtual
54 // time, however by default new code should use the normal non-virtual time APIs. 72 // time, however by default new code should use the normal non-virtual time APIs.
55 73
56 // Returns a double which is the number of seconds since epoch (Jan 1, 1970) . 74 // Returns a double which is the number of seconds since epoch (Jan 1, 1970) .
57 // This may represent either the real time, or a virtual time depending on 75 // This may represent either the real time, or a virtual time depending on
58 // whether or not the WebTaskRunner is associated with a virtual time domain or a 76 // whether or not the WebTaskRunner is associated with a virtual time domain or a
59 // real time domain. 77 // real time domain.
60 virtual double virtualTimeSeconds() const = 0; 78 virtual double virtualTimeSeconds() const = 0;
61 79
62 // Returns a microsecond resolution platform dependant time source. 80 // Returns a microsecond resolution platform dependant time source.
63 // This may represent either the real time, or a virtual time depending on 81 // This may represent either the real time, or a virtual time depending on
64 // whether or not the WebTaskRunner is associated with a virtual time domain or a 82 // whether or not the WebTaskRunner is associated with a virtual time domain or a
65 // real time domain. 83 // real time domain.
66 virtual double monotonicallyIncreasingVirtualTimeSeconds() const = 0; 84 virtual double monotonicallyIncreasingVirtualTimeSeconds() const = 0;
67 85
68 // Returns the underlying task runner object. 86 // Returns the underlying task runner object.
69 virtual SingleThreadTaskRunner* taskRunner() = 0; 87 virtual SingleThreadTaskRunner* toSingleThreadTaskRunner() = 0;
70 88
71 #ifdef INSIDE_BLINK 89 #ifdef INSIDE_BLINK
72 // Helpers for posting bound functions as tasks. 90 // Helpers for posting bound functions as tasks.
73 91
74 // For cross-thread posting. Can be called from any thread. 92 // For cross-thread posting. Can be called from any thread.
75 void postTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); 93 void postTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>);
76 void postDelayedTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClo sure>, long long delayMs); 94 void postDelayedTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClo sure>, long long delayMs);
77 95
78 // For same-thread posting. Must be called from the associated WebThread. 96 // For same-thread posting. Must be called from the associated WebThread.
79 void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); 97 void postTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>);
80 void postDelayedTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>, long long delayMs); 98 void postDelayedTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>, long long delayMs);
99
100 // Posts the given same-thread closure to be run after |delay| has passed.
101 // Returns a handle which can be passed to cancelTask to cancel the task
102 // before it has run. Note this must be called from the thread the tasks are
103 // run on (i.e the thread where runsTasksOnCurrentThread returns true).
104 TaskHandle postCancellableDelayedTask(const WebTraceLocation&, std::unique_p tr<WTF::Closure>, double delayMs);
81 #endif 105 #endif
82 }; 106 };
83 107
84 } // namespace blink 108 } // namespace blink
85 109
86 #endif // WebTaskRunner_h 110 #endif // WebTaskRunner_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698