| 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 #include "mojo/edk/system/message_pipe.h" | 5 #include "mojo/edk/system/message_pipe.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/edk/system/channel.h" | 8 #include "mojo/edk/system/channel.h" |
| 9 #include "mojo/edk/system/channel_endpoint.h" | 9 #include "mojo/edk/system/channel_endpoint.h" |
| 10 #include "mojo/edk/system/channel_endpoint_id.h" | 10 #include "mojo/edk/system/channel_endpoint_id.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 } | 132 } |
| 133 | 133 |
| 134 // TODO(vtl): Handle flags. | 134 // TODO(vtl): Handle flags. |
| 135 MojoResult MessagePipe::WriteMessage( | 135 MojoResult MessagePipe::WriteMessage( |
| 136 unsigned port, | 136 unsigned port, |
| 137 UserPointer<const void> bytes, | 137 UserPointer<const void> bytes, |
| 138 uint32_t num_bytes, | 138 uint32_t num_bytes, |
| 139 std::vector<DispatcherTransport>* transports, | 139 std::vector<DispatcherTransport>* transports, |
| 140 MojoWriteMessageFlags flags) { | 140 MojoWriteMessageFlags flags) { |
| 141 DCHECK(port == 0 || port == 1); | 141 DCHECK(port == 0 || port == 1); |
| 142 return EnqueueMessageInternal( | 142 return EnqueueMessage( |
| 143 GetPeerPort(port), | 143 GetPeerPort(port), |
| 144 make_scoped_ptr(new MessageInTransit( | 144 make_scoped_ptr(new MessageInTransit( |
| 145 MessageInTransit::kTypeMessagePipeEndpoint, | 145 MessageInTransit::kTypeMessagePipeEndpoint, |
| 146 MessageInTransit::kSubtypeMessagePipeEndpointData, num_bytes, bytes)), | 146 MessageInTransit::kSubtypeMessagePipeEndpointData, num_bytes, bytes)), |
| 147 transports); | 147 transports); |
| 148 } | 148 } |
| 149 | 149 |
| 150 MojoResult MessagePipe::ReadMessage(unsigned port, | 150 MojoResult MessagePipe::ReadMessage(unsigned port, |
| 151 UserPointer<void> bytes, | 151 UserPointer<void> bytes, |
| 152 UserPointer<uint32_t> num_bytes, | 152 UserPointer<uint32_t> num_bytes, |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 scoped_ptr<MessagePipeEndpoint> old_endpoint(endpoints_[port].Pass()); | 250 scoped_ptr<MessagePipeEndpoint> old_endpoint(endpoints_[port].Pass()); |
| 251 scoped_refptr<ChannelEndpoint> channel_endpoint(new ChannelEndpoint( | 251 scoped_refptr<ChannelEndpoint> channel_endpoint(new ChannelEndpoint( |
| 252 this, port, static_cast<LocalMessagePipeEndpoint*>(old_endpoint.get()) | 252 this, port, static_cast<LocalMessagePipeEndpoint*>(old_endpoint.get()) |
| 253 ->message_queue())); | 253 ->message_queue())); |
| 254 endpoints_[port].reset(new ProxyMessagePipeEndpoint(channel_endpoint.get())); | 254 endpoints_[port].reset(new ProxyMessagePipeEndpoint(channel_endpoint.get())); |
| 255 old_endpoint->Close(); | 255 old_endpoint->Close(); |
| 256 | 256 |
| 257 return channel_endpoint; | 257 return channel_endpoint; |
| 258 } | 258 } |
| 259 | 259 |
| 260 MojoResult MessagePipe::EnqueueMessage(unsigned port, | 260 bool MessagePipe::OnReadMessage(unsigned port, |
| 261 scoped_ptr<MessageInTransit> message) { | 261 scoped_ptr<MessageInTransit> message) { |
| 262 return EnqueueMessageInternal(port, message.Pass(), nullptr); | 262 // This is called when the |ChannelEndpoint| for the |
| 263 // |ProxyMessagePipeEndpoint| |port| receives a message (from the |Channel|). |
| 264 // We need to pass this message on to its peer port (typically a |
| 265 // |LocalMessagePipeEndpoint|). |
| 266 return EnqueueMessage(GetPeerPort(port), message.Pass(), nullptr) == |
| 267 MOJO_RESULT_OK; |
| 268 } |
| 269 |
| 270 void MessagePipe::OnDetachFromChannel(unsigned port) { |
| 271 Close(port); |
| 263 } | 272 } |
| 264 | 273 |
| 265 MessagePipe::MessagePipe() { | 274 MessagePipe::MessagePipe() { |
| 266 } | 275 } |
| 267 | 276 |
| 268 MessagePipe::~MessagePipe() { | 277 MessagePipe::~MessagePipe() { |
| 269 // Owned by the dispatchers. The owning dispatchers should only release us via | 278 // Owned by the dispatchers. The owning dispatchers should only release us via |
| 270 // their |Close()| method, which should inform us of being closed via our | 279 // their |Close()| method, which should inform us of being closed via our |
| 271 // |Close()|. Thus these should already be null. | 280 // |Close()|. Thus these should already be null. |
| 272 DCHECK(!endpoints_[0]); | 281 DCHECK(!endpoints_[0]); |
| 273 DCHECK(!endpoints_[1]); | 282 DCHECK(!endpoints_[1]); |
| 274 } | 283 } |
| 275 | 284 |
| 276 MojoResult MessagePipe::EnqueueMessageInternal( | 285 MojoResult MessagePipe::EnqueueMessage( |
| 277 unsigned port, | 286 unsigned port, |
| 278 scoped_ptr<MessageInTransit> message, | 287 scoped_ptr<MessageInTransit> message, |
| 279 std::vector<DispatcherTransport>* transports) { | 288 std::vector<DispatcherTransport>* transports) { |
| 280 DCHECK(port == 0 || port == 1); | 289 DCHECK(port == 0 || port == 1); |
| 281 DCHECK(message); | 290 DCHECK(message); |
| 282 | 291 |
| 283 if (message->type() == MessageInTransit::kTypeMessagePipe) { | 292 if (message->type() == MessageInTransit::kTypeMessagePipe) { |
| 284 DCHECK(!transports); | 293 DCHECK(!transports); |
| 285 return HandleControlMessage(port, message.Pass()); | 294 return HandleControlMessage(port, message.Pass()); |
| 286 } | 295 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 MojoResult MessagePipe::HandleControlMessage( | 361 MojoResult MessagePipe::HandleControlMessage( |
| 353 unsigned /*port*/, | 362 unsigned /*port*/, |
| 354 scoped_ptr<MessageInTransit> message) { | 363 scoped_ptr<MessageInTransit> message) { |
| 355 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " | 364 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " |
| 356 << message->subtype(); | 365 << message->subtype(); |
| 357 return MOJO_RESULT_UNKNOWN; | 366 return MOJO_RESULT_UNKNOWN; |
| 358 } | 367 } |
| 359 | 368 |
| 360 } // namespace system | 369 } // namespace system |
| 361 } // namespace mojo | 370 } // namespace mojo |
| OLD | NEW |