| 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 <memory> | 8 #include <memory> |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "platform/wtf/Compiler.h" | 10 #include "platform/wtf/Compiler.h" |
| 11 #include "platform/wtf/Functional.h" | 11 #include "platform/wtf/Functional.h" |
| 12 #include "platform/wtf/RefCounted.h" | 12 #include "platform/wtf/RefCounted.h" |
| 13 #include "platform/wtf/Time.h" |
| 13 #include "platform/wtf/WeakPtr.h" | 14 #include "platform/wtf/WeakPtr.h" |
| 14 #include "public/platform/WebCommon.h" | 15 #include "public/platform/WebCommon.h" |
| 15 #include "public/platform/WebTraceLocation.h" | 16 #include "public/platform/WebTraceLocation.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 | 23 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 friend class WebTaskRunner; | 53 friend class WebTaskRunner; |
| 53 | 54 |
| 54 explicit TaskHandle(RefPtr<Runner>); | 55 explicit TaskHandle(RefPtr<Runner>); |
| 55 RefPtr<Runner> runner_; | 56 RefPtr<Runner> runner_; |
| 56 }; | 57 }; |
| 57 | 58 |
| 58 // The blink representation of a chromium SingleThreadTaskRunner. | 59 // The blink representation of a chromium SingleThreadTaskRunner. |
| 59 class BLINK_PLATFORM_EXPORT WebTaskRunner | 60 class BLINK_PLATFORM_EXPORT WebTaskRunner |
| 60 : public ThreadSafeRefCounted<WebTaskRunner> { | 61 : public ThreadSafeRefCounted<WebTaskRunner> { |
| 61 public: | 62 public: |
| 62 // Schedule a task to be run after |delayMs| on the the associated WebThread. | |
| 63 // Can be called from any thread. | |
| 64 virtual void PostDelayedTask(const WebTraceLocation&, | |
| 65 base::OnceClosure, | |
| 66 double delay_ms) = 0; | |
| 67 | |
| 68 // Drepecated: favor RunsTasksInCurrentSequence(). | 63 // Drepecated: favor RunsTasksInCurrentSequence(). |
| 69 // TODO(http://crbug.com/665062): mass redirect callers and remove this. | 64 // TODO(http://crbug.com/665062): mass redirect callers and remove this. |
| 70 bool RunsTasksOnCurrentThread(); | 65 bool RunsTasksOnCurrentThread(); |
| 71 | 66 |
| 72 // Returns true if tasks posted to this TaskRunner are sequenced | 67 // Returns true if tasks posted to this TaskRunner are sequenced |
| 73 // with this call. | 68 // with this call. |
| 74 virtual bool RunsTasksInCurrentSequence() = 0; | 69 virtual bool RunsTasksInCurrentSequence() = 0; |
| 75 | 70 |
| 76 // --- | 71 // --- |
| 77 | 72 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 94 | 89 |
| 95 // Returns the underlying task runner object. | 90 // Returns the underlying task runner object. |
| 96 virtual SingleThreadTaskRunner* ToSingleThreadTaskRunner() = 0; | 91 virtual SingleThreadTaskRunner* ToSingleThreadTaskRunner() = 0; |
| 97 | 92 |
| 98 // Helpers for posting bound functions as tasks. | 93 // Helpers for posting bound functions as tasks. |
| 99 | 94 |
| 100 // For cross-thread posting. Can be called from any thread. | 95 // For cross-thread posting. Can be called from any thread. |
| 101 void PostTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); | 96 void PostTask(const WebTraceLocation&, std::unique_ptr<CrossThreadClosure>); |
| 102 void PostDelayedTask(const WebTraceLocation&, | 97 void PostDelayedTask(const WebTraceLocation&, |
| 103 std::unique_ptr<CrossThreadClosure>, | 98 std::unique_ptr<CrossThreadClosure>, |
| 104 long long delay_ms); | 99 TimeDelta delay); |
| 105 | 100 |
| 106 // For same-thread posting. Must be called from the associated WebThread. | 101 // For same-thread posting. Must be called from the associated WebThread. |
| 107 void PostTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); | 102 void PostTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); |
| 108 void PostDelayedTask(const WebTraceLocation&, | 103 void PostDelayedTask(const WebTraceLocation&, |
| 109 std::unique_ptr<WTF::Closure>, | 104 std::unique_ptr<WTF::Closure>, |
| 110 long long delay_ms); | 105 TimeDelta delay); |
| 111 | 106 |
| 112 // For same-thread cancellable task posting. Returns a TaskHandle object for | 107 // For same-thread cancellable task posting. Returns a TaskHandle object for |
| 113 // cancellation. | 108 // cancellation. |
| 114 WARN_UNUSED_RESULT TaskHandle | 109 WARN_UNUSED_RESULT TaskHandle |
| 115 PostCancellableTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); | 110 PostCancellableTask(const WebTraceLocation&, std::unique_ptr<WTF::Closure>); |
| 116 WARN_UNUSED_RESULT TaskHandle | 111 WARN_UNUSED_RESULT TaskHandle |
| 117 PostDelayedCancellableTask(const WebTraceLocation&, | 112 PostDelayedCancellableTask(const WebTraceLocation&, |
| 118 std::unique_ptr<WTF::Closure>, | 113 std::unique_ptr<WTF::Closure>, |
| 119 long long delay_ms); | 114 TimeDelta delay); |
| 120 | 115 |
| 121 protected: | 116 protected: |
| 122 friend ThreadSafeRefCounted<WebTaskRunner>; | 117 friend ThreadSafeRefCounted<WebTaskRunner>; |
| 123 WebTaskRunner() = default; | 118 WebTaskRunner() = default; |
| 124 virtual ~WebTaskRunner(); | 119 virtual ~WebTaskRunner(); |
| 125 | 120 |
| 126 private: | 121 private: |
| 127 DISALLOW_COPY_AND_ASSIGN(WebTaskRunner); | 122 DISALLOW_COPY_AND_ASSIGN(WebTaskRunner); |
| 128 }; | 123 }; |
| 129 | 124 |
| 130 } // namespace blink | 125 } // namespace blink |
| 131 | 126 |
| 132 #endif // WebTaskRunner_h | 127 #endif // WebTaskRunner_h |
| OLD | NEW |