Chromium Code Reviews| 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_LIB_CONNECTOR_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | |
| 8 #include "mojo/public/c/environment/async_waiter.h" | 9 #include "mojo/public/c/environment/async_waiter.h" |
| 9 #include "mojo/public/cpp/bindings/callback.h" | 10 #include "mojo/public/cpp/bindings/callback.h" |
| 10 #include "mojo/public/cpp/bindings/message.h" | 11 #include "mojo/public/cpp/bindings/message.h" |
| 11 #include "mojo/public/cpp/environment/environment.h" | 12 #include "mojo/public/cpp/environment/environment.h" |
| 12 #include "mojo/public/cpp/system/core.h" | 13 #include "mojo/public/cpp/system/core.h" |
| 13 | 14 |
| 15 namespace base { | |
| 16 class Lock; | |
| 17 } | |
| 18 | |
| 14 namespace mojo { | 19 namespace mojo { |
| 15 class ErrorHandler; | |
| 16 | |
| 17 namespace internal { | 20 namespace internal { |
| 18 | 21 |
| 19 // The Connector class is responsible for performing read/write operations on a | 22 // The Connector class is responsible for performing read/write operations on a |
| 20 // MessagePipe. It writes messages it receives through the MessageReceiver | 23 // MessagePipe. It writes messages it receives through the MessageReceiver |
| 21 // interface that it subclasses, and it forwards messages it reads through the | 24 // interface that it subclasses, and it forwards messages it reads through the |
| 22 // MessageReceiver interface assigned as its incoming receiver. | 25 // MessageReceiver interface assigned as its incoming receiver. |
| 23 // | 26 // |
| 24 // NOTE: MessagePipe I/O is non-blocking. | 27 // NOTE: |
| 25 // | 28 // - MessagePipe I/O is non-blocking. |
| 29 // - Sending messages can be configured to be thread safe (please see comments | |
|
sky
2015/11/19 17:16:26
Can you use threading asserts to verify this(Threa
yzshen1
2015/11/19 22:00:40
Done.
| |
| 30 // of the constructor). Other than that, the object should only be accessed | |
| 31 // on the creating thread. | |
| 26 class Connector : public MessageReceiver { | 32 class Connector : public MessageReceiver { |
| 27 public: | 33 public: |
| 34 enum SendingThreadSaftyType { SINGLE_THREADED_SEND, MULTI_THREADED_SEND }; | |
|
sky
2015/11/19 17:16:27
nit: enum class
yzshen1
2015/11/19 22:00:40
Currently I refer to the values at the callsites u
sky
2015/11/20 01:00:19
Would using address that?
Part of this is because
yzshen1
2015/11/20 17:01:00
Using doesn't help in this case unfortunately.
| |
| 35 | |
| 28 // The Connector takes ownership of |message_pipe|. | 36 // The Connector takes ownership of |message_pipe|. |
| 29 explicit Connector( | 37 // If |sending_thread_safty_type| is set to MULTI_THREADED_SEND, Accept() is |
|
sky
2015/11/19 17:16:27
safty->safety
yzshen1
2015/11/19 22:00:40
Ah, sorry. :)
| |
| 38 // safe to call from multiple threads. | |
| 39 Connector( | |
| 30 ScopedMessagePipeHandle message_pipe, | 40 ScopedMessagePipeHandle message_pipe, |
| 41 SendingThreadSaftyType sending_thread_safty_type, | |
| 31 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()); | 42 const MojoAsyncWaiter* waiter = Environment::GetDefaultAsyncWaiter()); |
| 32 ~Connector() override; | 43 ~Connector() override; |
| 33 | 44 |
| 34 // Sets the receiver to handle messages read from the message pipe. The | 45 // Sets the receiver to handle messages read from the message pipe. The |
| 35 // Connector will read messages from the pipe regardless of whether or not an | 46 // Connector will read messages from the pipe regardless of whether or not an |
| 36 // incoming receiver has been set. | 47 // incoming receiver has been set. |
| 37 void set_incoming_receiver(MessageReceiver* receiver) { | 48 void set_incoming_receiver(MessageReceiver* receiver) { |
| 38 incoming_receiver_ = receiver; | 49 incoming_receiver_ = receiver; |
| 39 } | 50 } |
| 40 | 51 |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 126 bool drop_writes_; | 137 bool drop_writes_; |
| 127 bool enforce_errors_from_incoming_receiver_; | 138 bool enforce_errors_from_incoming_receiver_; |
| 128 | 139 |
| 129 bool paused_; | 140 bool paused_; |
| 130 | 141 |
| 131 // If non-null, this will be set to true when the Connector is destroyed. We | 142 // If non-null, this will be set to true when the Connector is destroyed. We |
| 132 // use this flag to allow for the Connector to be destroyed as a side-effect | 143 // use this flag to allow for the Connector to be destroyed as a side-effect |
| 133 // of dispatching an incoming message. | 144 // of dispatching an incoming message. |
| 134 bool* destroyed_flag_; | 145 bool* destroyed_flag_; |
| 135 | 146 |
| 147 // If sending messages is allowed from multiple threads, |lock_| is used to | |
| 148 // protect modifications to |message_pipe_| and |drop_writes_|. | |
| 149 scoped_ptr<base::Lock> lock_; | |
| 150 | |
| 136 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); | 151 MOJO_DISALLOW_COPY_AND_ASSIGN(Connector); |
| 137 }; | 152 }; |
| 138 | 153 |
| 139 } // namespace internal | 154 } // namespace internal |
| 140 } // namespace mojo | 155 } // namespace mojo |
| 141 | 156 |
| 142 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ | 157 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_CONNECTOR_H_ |
| OLD | NEW |