OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_BASE_ASYNCINVOKER_INL_H_ | 11 #ifndef WEBRTC_BASE_ASYNCINVOKER_INL_H_ |
12 #define WEBRTC_BASE_ASYNCINVOKER_INL_H_ | 12 #define WEBRTC_BASE_ASYNCINVOKER_INL_H_ |
13 | 13 |
14 #include "webrtc/base/bind.h" | 14 #include "webrtc/base/bind.h" |
15 #include "webrtc/base/callback.h" | 15 #include "webrtc/base/callback.h" |
16 #include "webrtc/base/criticalsection.h" | 16 #include "webrtc/base/criticalsection.h" |
17 #include "webrtc/base/messagehandler.h" | 17 #include "webrtc/base/messagehandler.h" |
| 18 #include "webrtc/base/refcount.h" |
| 19 #include "webrtc/base/scoped_ref_ptr.h" |
18 #include "webrtc/base/sigslot.h" | 20 #include "webrtc/base/sigslot.h" |
19 #include "webrtc/base/thread.h" | 21 #include "webrtc/base/thread.h" |
20 | 22 |
21 namespace rtc { | 23 namespace rtc { |
22 | 24 |
23 class AsyncInvoker; | 25 class AsyncInvoker; |
24 | 26 |
25 // Helper class for AsyncInvoker. Runs a task and triggers a callback | 27 // Helper class for AsyncInvoker. Runs a task and triggers a callback |
26 // on the calling thread if necessary. | 28 // on the calling thread if necessary. Instances are ref-counted so their |
27 class AsyncClosure { | 29 // lifetime can be independent of AsyncInvoker. |
| 30 class AsyncClosure : public RefCountInterface { |
28 public: | 31 public: |
29 virtual ~AsyncClosure() {} | |
30 // Runs the asynchronous task, and triggers a callback to the calling | 32 // Runs the asynchronous task, and triggers a callback to the calling |
31 // thread if needed. Should be called from the target thread. | 33 // thread if needed. Should be called from the target thread. |
32 virtual void Execute() = 0; | 34 virtual void Execute() = 0; |
| 35 protected: |
| 36 ~AsyncClosure() override {} |
33 }; | 37 }; |
34 | 38 |
35 // Simple closure that doesn't trigger a callback for the calling thread. | 39 // Simple closure that doesn't trigger a callback for the calling thread. |
36 template <class FunctorT> | 40 template <class FunctorT> |
37 class FireAndForgetAsyncClosure : public AsyncClosure { | 41 class FireAndForgetAsyncClosure : public AsyncClosure { |
38 public: | 42 public: |
39 explicit FireAndForgetAsyncClosure(const FunctorT& functor) | 43 explicit FireAndForgetAsyncClosure(const FunctorT& functor) |
40 : functor_(functor) {} | 44 : functor_(functor) {} |
41 virtual void Execute() { | 45 virtual void Execute() { |
42 functor_(); | 46 functor_(); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 TriggerCallback(); | 130 TriggerCallback(); |
127 } | 131 } |
128 | 132 |
129 private: | 133 private: |
130 FunctorT functor_; | 134 FunctorT functor_; |
131 }; | 135 }; |
132 | 136 |
133 } // namespace rtc | 137 } // namespace rtc |
134 | 138 |
135 #endif // WEBRTC_BASE_ASYNCINVOKER_INL_H_ | 139 #endif // WEBRTC_BASE_ASYNCINVOKER_INL_H_ |
OLD | NEW |