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 #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 |ChannelEndpoint| for the |ProxyMessagePipeEndpoint| on |
|
yzshen1
2014/11/18 00:28:17
nit: called -> called by
viettrungluu
2014/11/18 00:47:30
"called when"
| |
| 263 // |port| receives a message (from the |Channel|). We need to pass this | |
| 264 // message on to its peer port (typically a |LocalMessagePipeEndpoint|). | |
| 265 return EnqueueMessage(GetPeerPort(port), message.Pass(), nullptr) == | |
| 266 MOJO_RESULT_OK; | |
| 267 } | |
| 268 | |
| 269 void MessagePipe::OnDetachFromChannel(unsigned port) { | |
| 270 Close(port); | |
| 263 } | 271 } |
| 264 | 272 |
| 265 MessagePipe::MessagePipe() { | 273 MessagePipe::MessagePipe() { |
| 266 } | 274 } |
| 267 | 275 |
| 268 MessagePipe::~MessagePipe() { | 276 MessagePipe::~MessagePipe() { |
| 269 // Owned by the dispatchers. The owning dispatchers should only release us via | 277 // 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 | 278 // their |Close()| method, which should inform us of being closed via our |
| 271 // |Close()|. Thus these should already be null. | 279 // |Close()|. Thus these should already be null. |
| 272 DCHECK(!endpoints_[0]); | 280 DCHECK(!endpoints_[0]); |
| 273 DCHECK(!endpoints_[1]); | 281 DCHECK(!endpoints_[1]); |
| 274 } | 282 } |
| 275 | 283 |
| 276 MojoResult MessagePipe::EnqueueMessageInternal( | 284 MojoResult MessagePipe::EnqueueMessage( |
| 277 unsigned port, | 285 unsigned port, |
| 278 scoped_ptr<MessageInTransit> message, | 286 scoped_ptr<MessageInTransit> message, |
| 279 std::vector<DispatcherTransport>* transports) { | 287 std::vector<DispatcherTransport>* transports) { |
| 280 DCHECK(port == 0 || port == 1); | 288 DCHECK(port == 0 || port == 1); |
| 281 DCHECK(message); | 289 DCHECK(message); |
| 282 | 290 |
| 283 if (message->type() == MessageInTransit::kTypeMessagePipe) { | 291 if (message->type() == MessageInTransit::kTypeMessagePipe) { |
| 284 DCHECK(!transports); | 292 DCHECK(!transports); |
| 285 return HandleControlMessage(port, message.Pass()); | 293 return HandleControlMessage(port, message.Pass()); |
| 286 } | 294 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 352 MojoResult MessagePipe::HandleControlMessage( | 360 MojoResult MessagePipe::HandleControlMessage( |
| 353 unsigned /*port*/, | 361 unsigned /*port*/, |
| 354 scoped_ptr<MessageInTransit> message) { | 362 scoped_ptr<MessageInTransit> message) { |
| 355 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " | 363 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " |
| 356 << message->subtype(); | 364 << message->subtype(); |
| 357 return MOJO_RESULT_UNKNOWN; | 365 return MOJO_RESULT_UNKNOWN; |
| 358 } | 366 } |
| 359 | 367 |
| 360 } // namespace system | 368 } // namespace system |
| 361 } // namespace mojo | 369 } // namespace mojo |
| OLD | NEW |