| 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/simple_watcher.h" | 21 #include "mojo/public/cpp/system/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 | |
| 164 private: | 158 private: |
| 165 // Callback of mojo::SimpleWatcher. | 159 // Callback of mojo::Watcher. |
| 166 void OnWatcherHandleReady(MojoResult result); | 160 void OnWatcherHandleReady(MojoResult result); |
| 167 // Callback of SyncHandleWatcher. | 161 // Callback of SyncHandleWatcher. |
| 168 void OnSyncHandleWatcherHandleReady(MojoResult result); | 162 void OnSyncHandleWatcherHandleReady(MojoResult result); |
| 169 void OnHandleReadyInternal(MojoResult result); | 163 void OnHandleReadyInternal(MojoResult result); |
| 170 | 164 |
| 171 void WaitToReadMore(); | 165 void WaitToReadMore(); |
| 172 | 166 |
| 173 // Returns false if it is impossible to receive more messages in the future. | 167 // Returns false if it is impossible to receive more messages in the future. |
| 174 // |this| may have been destroyed in that case. | 168 // |this| may have been destroyed in that case. |
| 175 WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); | 169 WARN_UNUSED_RESULT bool ReadSingleMessage(MojoResult* read_result); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 187 void CancelWait(); | 181 void CancelWait(); |
| 188 | 182 |
| 189 void EnsureSyncWatcherExists(); | 183 void EnsureSyncWatcherExists(); |
| 190 | 184 |
| 191 base::Closure connection_error_handler_; | 185 base::Closure connection_error_handler_; |
| 192 | 186 |
| 193 ScopedMessagePipeHandle message_pipe_; | 187 ScopedMessagePipeHandle message_pipe_; |
| 194 MessageReceiver* incoming_receiver_ = nullptr; | 188 MessageReceiver* incoming_receiver_ = nullptr; |
| 195 | 189 |
| 196 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 190 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 197 std::unique_ptr<SimpleWatcher> handle_watcher_; | 191 std::unique_ptr<Watcher> handle_watcher_; |
| 198 | 192 |
| 199 bool error_ = false; | 193 bool error_ = false; |
| 200 bool drop_writes_ = false; | 194 bool drop_writes_ = false; |
| 201 bool enforce_errors_from_incoming_receiver_ = true; | 195 bool enforce_errors_from_incoming_receiver_ = true; |
| 202 | 196 |
| 203 bool paused_ = false; | 197 bool paused_ = false; |
| 204 | 198 |
| 205 bool nested_dispatch_enabled_ = false; | |
| 206 | |
| 207 // If sending messages is allowed from multiple threads, |lock_| is used to | 199 // If sending messages is allowed from multiple threads, |lock_| is used to |
| 208 // protect modifications to |message_pipe_| and |drop_writes_|. | 200 // protect modifications to |message_pipe_| and |drop_writes_|. |
| 209 base::Optional<base::Lock> lock_; | 201 base::Optional<base::Lock> lock_; |
| 210 | 202 |
| 211 std::unique_ptr<SyncHandleWatcher> sync_watcher_; | 203 std::unique_ptr<SyncHandleWatcher> sync_watcher_; |
| 212 bool allow_woken_up_by_others_ = false; | 204 bool allow_woken_up_by_others_ = false; |
| 213 // If non-zero, currently the control flow is inside the sync handle watcher | 205 // If non-zero, currently the control flow is inside the sync handle watcher |
| 214 // callback. | 206 // callback. |
| 215 size_t sync_handle_watcher_callback_count_ = 0; | 207 size_t sync_handle_watcher_callback_count_ = 0; |
| 216 | 208 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 229 // transferred (i.e., when |connected_| is set to false). | 221 // transferred (i.e., when |connected_| is set to false). |
| 230 base::WeakPtr<Connector> weak_self_; | 222 base::WeakPtr<Connector> weak_self_; |
| 231 base::WeakPtrFactory<Connector> weak_factory_; | 223 base::WeakPtrFactory<Connector> weak_factory_; |
| 232 | 224 |
| 233 DISALLOW_COPY_AND_ASSIGN(Connector); | 225 DISALLOW_COPY_AND_ASSIGN(Connector); |
| 234 }; | 226 }; |
| 235 | 227 |
| 236 } // namespace mojo | 228 } // namespace mojo |
| 237 | 229 |
| 238 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ | 230 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
| OLD | NEW |