| 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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 13 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 14 #include "base/threading/thread_checker.h" | 15 #include "base/threading/thread_checker.h" |
| 16 #include "mojo/public/cpp/bindings/bindings_export.h" |
| 15 #include "mojo/public/cpp/bindings/message.h" | 17 #include "mojo/public/cpp/bindings/message.h" |
| 16 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" | 18 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" |
| 17 #include "mojo/public/cpp/system/core.h" | 19 #include "mojo/public/cpp/system/core.h" |
| 18 #include "mojo/public/cpp/system/watcher.h" | 20 #include "mojo/public/cpp/system/watcher.h" |
| 19 | 21 |
| 20 namespace base { | 22 namespace base { |
| 21 class Lock; | 23 class Lock; |
| 22 } | 24 } |
| 23 | 25 |
| 24 namespace mojo { | 26 namespace mojo { |
| 25 | 27 |
| 26 // The Connector class is responsible for performing read/write operations on a | 28 // The Connector class is responsible for performing read/write operations on a |
| 27 // MessagePipe. It writes messages it receives through the MessageReceiver | 29 // MessagePipe. It writes messages it receives through the MessageReceiver |
| 28 // interface that it subclasses, and it forwards messages it reads through the | 30 // interface that it subclasses, and it forwards messages it reads through the |
| 29 // MessageReceiver interface assigned as its incoming receiver. | 31 // MessageReceiver interface assigned as its incoming receiver. |
| 30 // | 32 // |
| 31 // NOTE: | 33 // NOTE: |
| 32 // - MessagePipe I/O is non-blocking. | 34 // - MessagePipe I/O is non-blocking. |
| 33 // - Sending messages can be configured to be thread safe (please see comments | 35 // - Sending messages can be configured to be thread safe (please see comments |
| 34 // of the constructor). Other than that, the object should only be accessed | 36 // of the constructor). Other than that, the object should only be accessed |
| 35 // on the creating thread. | 37 // on the creating thread. |
| 36 class Connector : public MessageReceiver { | 38 class MOJO_CPP_BINDINGS_EXPORT Connector |
| 39 : NON_EXPORTED_BASE(public MessageReceiver) { |
| 37 public: | 40 public: |
| 38 enum ConnectorConfig { | 41 enum ConnectorConfig { |
| 39 // Connector::Accept() is only called from a single thread. | 42 // Connector::Accept() is only called from a single thread. |
| 40 SINGLE_THREADED_SEND, | 43 SINGLE_THREADED_SEND, |
| 41 // Connector::Accept() is allowed to be called from multiple threads. | 44 // Connector::Accept() is allowed to be called from multiple threads. |
| 42 MULTI_THREADED_SEND | 45 MULTI_THREADED_SEND |
| 43 }; | 46 }; |
| 44 | 47 |
| 45 // The Connector takes ownership of |message_pipe|. | 48 // The Connector takes ownership of |message_pipe|. |
| 46 Connector(ScopedMessagePipeHandle message_pipe, | 49 Connector(ScopedMessagePipeHandle message_pipe, |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // transferred (i.e., when |connected_| is set to false). | 212 // transferred (i.e., when |connected_| is set to false). |
| 210 base::WeakPtr<Connector> weak_self_; | 213 base::WeakPtr<Connector> weak_self_; |
| 211 base::WeakPtrFactory<Connector> weak_factory_; | 214 base::WeakPtrFactory<Connector> weak_factory_; |
| 212 | 215 |
| 213 DISALLOW_COPY_AND_ASSIGN(Connector); | 216 DISALLOW_COPY_AND_ASSIGN(Connector); |
| 214 }; | 217 }; |
| 215 | 218 |
| 216 } // namespace mojo | 219 } // namespace mojo |
| 217 | 220 |
| 218 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ | 221 #endif // MOJO_PUBLIC_CPP_BINDINGS_CONNECTOR_H_ |
| OLD | NEW |