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/message.h" | 18 #include "mojo/public/cpp/bindings/message.h" |
19 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" | 19 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" |
20 #include "mojo/public/cpp/system/core.h" | 20 #include "mojo/public/cpp/system/core.h" |
21 #include "mojo/public/cpp/system/watcher.h" | 21 #include "mojo/public/cpp/system/simple_watcher.h" |
22 | 22 |
23 namespace base { | 23 namespace base { |
24 class Lock; | 24 class Lock; |
25 } | 25 } |
26 | 26 |
27 namespace mojo { | 27 namespace mojo { |
28 | 28 |
29 // The Connector class is responsible for performing read/write operations on a | 29 // The Connector class is responsible for performing read/write operations on a |
30 // MessagePipe. It writes messages it receives through the MessageReceiver | 30 // MessagePipe. It writes messages it receives through the MessageReceiver |
31 // interface that it subclasses, and it forwards messages it reads through the | 31 // interface that it subclasses, and it forwards messages it reads through the |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 148 } |
149 | 149 |
150 base::SingleThreadTaskRunner* task_runner() const { | 150 base::SingleThreadTaskRunner* task_runner() const { |
151 return task_runner_.get(); | 151 return task_runner_.get(); |
152 } | 152 } |
153 | 153 |
154 // Sets the tag used by the heap profiler. | 154 // Sets the tag used by the heap profiler. |
155 // |tag| must be a const string literal. | 155 // |tag| must be a const string literal. |
156 void SetWatcherHeapProfilerTag(const char* tag); | 156 void SetWatcherHeapProfilerTag(const char* tag); |
157 | 157 |
| 158 // Enables support for nested message dispatch so that the Connector can |
| 159 // continue dispatching inbound messages even if one of them spins a nested |
| 160 // message loop. This should be enabled only when needed, as dispatch in this |
| 161 // mode is generally less efficient. |
| 162 void EnableNestedDispatch(bool enabled); |
| 163 |
158 private: | 164 private: |
159 // Callback of mojo::Watcher. | 165 // Callback of mojo::SimpleWatcher. |
160 void OnWatcherHandleReady(MojoResult result); | 166 void OnWatcherHandleReady(MojoResult result); |
161 // Callback of SyncHandleWatcher. | 167 // Callback of SyncHandleWatcher. |
162 void OnSyncHandleWatcherHandleReady(MojoResult result); | 168 void OnSyncHandleWatcherHandleReady(MojoResult result); |
163 void OnHandleReadyInternal(MojoResult result); | 169 void OnHandleReadyInternal(MojoResult result); |
164 | 170 |
165 void WaitToReadMore(); | 171 void WaitToReadMore(); |
166 | 172 |
167 // Returns false if it is impossible to receive more messages in the future. | 173 // Returns false if it is impossible to receive more messages in the future. |
168 // |this| may have been destroyed in that case. | 174 // |this| may have been destroyed in that case. |
169 WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); | 175 WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); |
(...skipping 11 matching lines...) Expand all Loading... |
181 void CancelWait(); | 187 void CancelWait(); |
182 | 188 |
183 void EnsureSyncWatcherExists(); | 189 void EnsureSyncWatcherExists(); |
184 | 190 |
185 base::Closure connection_error_handler_; | 191 base::Closure connection_error_handler_; |
186 | 192 |
187 ScopedMessagePipeHandle message_pipe_; | 193 ScopedMessagePipeHandle message_pipe_; |
188 MessageReceiver* incoming_receiver_ = nullptr; | 194 MessageReceiver* incoming_receiver_ = nullptr; |
189 | 195 |
190 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 196 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
191 std::unique_ptr<Watcher> handle_watcher_; | 197 std::unique_ptr<SimpleWatcher> handle_watcher_; |
192 | 198 |
193 bool error_ = false; | 199 bool error_ = false; |
194 bool drop_writes_ = false; | 200 bool drop_writes_ = false; |
195 bool enforce_errors_from_incoming_receiver_ = true; | 201 bool enforce_errors_from_incoming_receiver_ = true; |
196 | 202 |
197 bool paused_ = false; | 203 bool paused_ = false; |
198 | 204 |
| 205 bool nested_dispatch_enabled_ = false; |
| 206 |
199 // If sending messages is allowed from multiple threads, |lock_| is used to | 207 // If sending messages is allowed from multiple threads, |lock_| is used to |
200 // protect modifications to |message_pipe_| and |drop_writes_|. | 208 // protect modifications to |message_pipe_| and |drop_writes_|. |
201 base::Optional<base::Lock> lock_; | 209 base::Optional<base::Lock> lock_; |
202 | 210 |
203 std::unique_ptr<SyncHandleWatcher> sync_watcher_; | 211 std::unique_ptr<SyncHandleWatcher> sync_watcher_; |
204 bool allow_woken_up_by_others_ = false; | 212 bool allow_woken_up_by_others_ = false; |
205 // If non-zero, currently the control flow is inside the sync handle watcher | 213 // If non-zero, currently the control flow is inside the sync handle watcher |
206 // callback. | 214 // callback. |
207 size_t sync_handle_watcher_callback_count_ = 0; | 215 size_t sync_handle_watcher_callback_count_ = 0; |
208 | 216 |
(...skipping 12 matching lines...) Expand all Loading... |
221 // transferred (i.e., when |connected_| is set to false). | 229 // transferred (i.e., when |connected_| is set to false). |
222 base::WeakPtr<Connector> weak_self_; | 230 base::WeakPtr<Connector> weak_self_; |
223 base::WeakPtrFactory<Connector> weak_factory_; | 231 base::WeakPtrFactory<Connector> weak_factory_; |
224 | 232 |
225 DISALLOW_COPY_AND_ASSIGN(Connector); | 233 DISALLOW_COPY_AND_ASSIGN(Connector); |
226 }; | 234 }; |
227 | 235 |
228 } // namespace mojo | 236 } // namespace mojo |
229 | 237 |
230 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ | 238 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
OLD | NEW |