OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "base/optional.h" | 14 #include "base/optional.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "mojo/public/cpp/bindings/bindings_export.h" | 17 #include "mojo/public/cpp/bindings/bindings_export.h" |
| 18 #include "mojo/public/cpp/bindings/lib/destruction_tracker.h" |
18 #include "mojo/public/cpp/bindings/message.h" | 19 #include "mojo/public/cpp/bindings/message.h" |
19 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" | 20 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" |
20 #include "mojo/public/cpp/system/core.h" | 21 #include "mojo/public/cpp/system/core.h" |
21 #include "mojo/public/cpp/system/watcher.h" | 22 #include "mojo/public/cpp/system/watcher.h" |
22 | 23 |
23 namespace base { | 24 namespace base { |
24 class Lock; | 25 class Lock; |
25 } | 26 } |
26 | 27 |
27 namespace mojo { | 28 namespace mojo { |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 149 } |
149 | 150 |
150 base::SingleThreadTaskRunner* task_runner() const { | 151 base::SingleThreadTaskRunner* task_runner() const { |
151 return task_runner_.get(); | 152 return task_runner_.get(); |
152 } | 153 } |
153 | 154 |
154 // Sets the tag used by the heap profiler. | 155 // Sets the tag used by the heap profiler. |
155 // |tag| must be a const string literal. | 156 // |tag| must be a const string literal. |
156 void SetWatcherHeapProfilerTag(const char* tag); | 157 void SetWatcherHeapProfilerTag(const char* tag); |
157 | 158 |
| 159 // Enables support for nested message dispatch so that the Connector can |
| 160 // continue dispatching inbound messages even if one of them spins a nested |
| 161 // message loop. This should be enabled only when needed, as dispatch in this |
| 162 // mode is generally less efficient. |
| 163 void EnableNestedDispatch(bool enabled); |
| 164 |
158 private: | 165 private: |
159 // Callback of mojo::Watcher. | 166 // Callback of mojo::Watcher. |
160 void OnWatcherHandleReady(MojoResult result); | 167 void OnWatcherHandleReady(MojoResult result); |
161 // Callback of SyncHandleWatcher. | 168 // Callback of SyncHandleWatcher. |
162 void OnSyncHandleWatcherHandleReady(MojoResult result); | 169 void OnSyncHandleWatcherHandleReady(MojoResult result); |
163 void OnHandleReadyInternal(MojoResult result); | 170 void OnHandleReadyInternal(MojoResult result); |
164 | 171 |
165 void WaitToReadMore(); | 172 void WaitToReadMore(); |
166 | 173 |
167 // Returns false if it is impossible to receive more messages in the future. | 174 // Returns false if it is impossible to receive more messages in the future. |
(...skipping 21 matching lines...) Expand all Loading... |
189 | 196 |
190 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 197 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
191 std::unique_ptr<Watcher> handle_watcher_; | 198 std::unique_ptr<Watcher> handle_watcher_; |
192 | 199 |
193 bool error_ = false; | 200 bool error_ = false; |
194 bool drop_writes_ = false; | 201 bool drop_writes_ = false; |
195 bool enforce_errors_from_incoming_receiver_ = true; | 202 bool enforce_errors_from_incoming_receiver_ = true; |
196 | 203 |
197 bool paused_ = false; | 204 bool paused_ = false; |
198 | 205 |
| 206 bool nested_dispatch_enabled_ = false; |
| 207 |
199 // If sending messages is allowed from multiple threads, |lock_| is used to | 208 // If sending messages is allowed from multiple threads, |lock_| is used to |
200 // protect modifications to |message_pipe_| and |drop_writes_|. | 209 // protect modifications to |message_pipe_| and |drop_writes_|. |
201 base::Optional<base::Lock> lock_; | 210 base::Optional<base::Lock> lock_; |
202 | 211 |
203 std::unique_ptr<SyncHandleWatcher> sync_watcher_; | 212 std::unique_ptr<SyncHandleWatcher> sync_watcher_; |
204 bool allow_woken_up_by_others_ = false; | 213 bool allow_woken_up_by_others_ = false; |
205 // If non-zero, currently the control flow is inside the sync handle watcher | 214 // If non-zero, currently the control flow is inside the sync handle watcher |
206 // callback. | 215 // callback. |
207 size_t sync_handle_watcher_callback_count_ = 0; | 216 size_t sync_handle_watcher_callback_count_ = 0; |
208 | 217 |
209 base::ThreadChecker thread_checker_; | 218 base::ThreadChecker thread_checker_; |
210 | 219 |
211 base::Lock connected_lock_; | 220 base::Lock connected_lock_; |
212 bool connected_ = true; | 221 bool connected_ = true; |
213 | 222 |
| 223 DestructionTracker destruction_tracker_; |
| 224 |
214 // The tag used to track heap allocations that originated from a Watcher | 225 // The tag used to track heap allocations that originated from a Watcher |
215 // notification. | 226 // notification. |
216 const char* heap_profiler_tag_ = nullptr; | 227 const char* heap_profiler_tag_ = nullptr; |
217 | 228 |
218 // Create a single weak ptr and use it everywhere, to avoid the malloc/free | 229 // Create a single weak ptr and use it everywhere, to avoid the malloc/free |
219 // cost of creating a new weak ptr whenever it is needed. | 230 // cost of creating a new weak ptr whenever it is needed. |
220 // NOTE: This weak pointer is invalidated when the message pipe is closed or | 231 // NOTE: This weak pointer is invalidated when the message pipe is closed or |
221 // transferred (i.e., when |connected_| is set to false). | 232 // transferred (i.e., when |connected_| is set to false). |
222 base::WeakPtr<Connector> weak_self_; | 233 base::WeakPtr<Connector> weak_self_; |
223 base::WeakPtrFactory<Connector> weak_factory_; | 234 base::WeakPtrFactory<Connector> weak_factory_; |
224 | 235 |
225 DISALLOW_COPY_AND_ASSIGN(Connector); | 236 DISALLOW_COPY_AND_ASSIGN(Connector); |
226 }; | 237 }; |
227 | 238 |
228 } // namespace mojo | 239 } // namespace mojo |
229 | 240 |
230 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ | 241 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
OLD | NEW |