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

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

Issue 2550373005: Make WebTaskRunner ThreadSafeRefCounted (Closed)
Patch Set: mac fix Created 4 years 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 "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
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 class BLINK_PLATFORM_EXPORT Task { 62 class BLINK_PLATFORM_EXPORT Task {
64 public: 63 public:
65 virtual ~Task() {} 64 virtual ~Task() {}
66 virtual void run() = 0; 65 virtual void run() = 0;
67 }; 66 };
68 67
69 // Schedule a task to be run on the the associated WebThread. 68 // Schedule a task to be run on the the associated WebThread.
70 // Takes ownership of |Task|. Can be called from any thread. 69 // Takes ownership of |Task|. Can be called from any thread.
71 virtual void postTask(const WebTraceLocation&, Task*) = 0; 70 virtual void postTask(const WebTraceLocation&, Task*) = 0;
72 71
73 // Schedule a task to be run after |delayMs| on the the associated WebThread. 72 // Schedule a task to be run after |delayMs| on the the associated WebThread.
74 // Takes ownership of |Task|. Can be called from any thread. 73 // Takes ownership of |Task|. Can be called from any thread.
75 virtual void postDelayedTask(const WebTraceLocation&, 74 virtual void postDelayedTask(const WebTraceLocation&,
76 Task*, 75 Task*,
77 double delayMs) = 0; 76 double delayMs) = 0;
78 77
79 // Schedule a task to be run after |delayMs| on the the associated WebThread. 78 // Schedule a task to be run after |delayMs| on the the associated WebThread.
80 // Can be called from any thread. 79 // Can be called from any thread.
81 virtual void postDelayedTask(const WebTraceLocation&, 80 virtual void postDelayedTask(const WebTraceLocation&,
82 const base::Closure&, 81 const base::Closure&,
83 double delayMs) = 0; 82 double delayMs) = 0;
84 83
85 // Returns a clone of the WebTaskRunner.
86 virtual std::unique_ptr<WebTaskRunner> clone() = 0;
87
88 // Returns true if the current thread is a thread on which a task may be run. 84 // Returns true if the current thread is a thread on which a task may be run.
89 // Can be called from any thread. 85 // Can be called from any thread.
90 virtual bool runsTasksOnCurrentThread() = 0; 86 virtual bool runsTasksOnCurrentThread() = 0;
91 87
92 // --- 88 // ---
93 89
94 // Headless Chrome virtualises time for determinism and performance (fast 90 // Headless Chrome virtualises time for determinism and performance (fast
95 // forwarding of timers). To make this work some parts of blink (e.g. Timers) 91 // forwarding of timers). To make this work some parts of blink (e.g. Timers)
96 // need to use virtual time, however by default new code should use the normal 92 // need to use virtual time, however by default new code should use the normal
97 // non-virtual time APIs. 93 // non-virtual time APIs.
(...skipping 28 matching lines...) Expand all
126 long long delayMs); 122 long long delayMs);
127 123
128 // For same-thread cancellable task posting. Returns a TaskHandle object for 124 // For same-thread cancellable task posting. Returns a TaskHandle object for
129 // cancellation. 125 // cancellation.
130 WARN_UNUSED_RESULT TaskHandle 126 WARN_UNUSED_RESULT TaskHandle
131 postCancellableTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); 127 postCancellableTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>);
132 WARN_UNUSED_RESULT TaskHandle 128 WARN_UNUSED_RESULT TaskHandle
133 postDelayedCancellableTask(const WebTraceLocation&, 129 postDelayedCancellableTask(const WebTraceLocation&,
134 std::unique_ptr<WTF::Closure>, 130 std::unique_ptr<WTF::Closure>,
135 long long delayMs); 131 long long delayMs);
132
133 protected:
134 friend ThreadSafeRefCounted<WebTaskRunner>;
135 WebTaskRunner() = default;
136 virtual ~WebTaskRunner();
137
138 private:
139 DISALLOW_COPY_AND_ASSIGN(WebTaskRunner);
136 }; 140 };
137 141
138 } // namespace blink 142 } // namespace blink
139 143
140 #endif // WebTaskRunner_h 144 #endif // WebTaskRunner_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698