| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 EnqueueMessage( | 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::kTypeEndpoint, |
| 146 MessageInTransit::kSubtypeMessagePipeEndpointData, num_bytes, bytes)), | 146 MessageInTransit::kSubtypeEndpointData, 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, |
| 153 DispatcherVector* dispatchers, | 153 DispatcherVector* dispatchers, |
| 154 uint32_t* num_dispatchers, | 154 uint32_t* num_dispatchers, |
| 155 MojoReadMessageFlags flags) { | 155 MojoReadMessageFlags flags) { |
| 156 DCHECK(port == 0 || port == 1); | 156 DCHECK(port == 0 || port == 1); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 DCHECK(!endpoints_[1]); | 312 DCHECK(!endpoints_[1]); |
| 313 } | 313 } |
| 314 | 314 |
| 315 MojoResult MessagePipe::EnqueueMessage( | 315 MojoResult MessagePipe::EnqueueMessage( |
| 316 unsigned port, | 316 unsigned port, |
| 317 scoped_ptr<MessageInTransit> message, | 317 scoped_ptr<MessageInTransit> message, |
| 318 std::vector<DispatcherTransport>* transports) { | 318 std::vector<DispatcherTransport>* transports) { |
| 319 DCHECK(port == 0 || port == 1); | 319 DCHECK(port == 0 || port == 1); |
| 320 DCHECK(message); | 320 DCHECK(message); |
| 321 | 321 |
| 322 if (message->type() == MessageInTransit::kTypeMessagePipe) { | 322 DCHECK_EQ(message->type(), MessageInTransit::kTypeEndpoint); |
| 323 DCHECK(!transports); | |
| 324 return HandleControlMessage(port, message.Pass()); | |
| 325 } | |
| 326 | |
| 327 DCHECK_EQ(message->type(), MessageInTransit::kTypeMessagePipeEndpoint); | |
| 328 | 323 |
| 329 base::AutoLock locker(lock_); | 324 base::AutoLock locker(lock_); |
| 330 DCHECK(endpoints_[GetPeerPort(port)]); | 325 DCHECK(endpoints_[GetPeerPort(port)]); |
| 331 | 326 |
| 332 // The destination port need not be open, unlike the source port. | 327 // The destination port need not be open, unlike the source port. |
| 333 if (!endpoints_[port]) | 328 if (!endpoints_[port]) |
| 334 return MOJO_RESULT_FAILED_PRECONDITION; | 329 return MOJO_RESULT_FAILED_PRECONDITION; |
| 335 | 330 |
| 336 if (transports) { | 331 if (transports) { |
| 337 MojoResult result = AttachTransportsNoLock(port, message.get(), transports); | 332 MojoResult result = AttachTransportsNoLock(port, message.get(), transports); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 (*transports)[i].CreateEquivalentDispatcherAndClose()); | 376 (*transports)[i].CreateEquivalentDispatcherAndClose()); |
| 382 } else { | 377 } else { |
| 383 LOG(WARNING) << "Enqueueing null dispatcher"; | 378 LOG(WARNING) << "Enqueueing null dispatcher"; |
| 384 dispatchers->push_back(nullptr); | 379 dispatchers->push_back(nullptr); |
| 385 } | 380 } |
| 386 } | 381 } |
| 387 message->SetDispatchers(dispatchers.Pass()); | 382 message->SetDispatchers(dispatchers.Pass()); |
| 388 return MOJO_RESULT_OK; | 383 return MOJO_RESULT_OK; |
| 389 } | 384 } |
| 390 | 385 |
| 391 MojoResult MessagePipe::HandleControlMessage( | |
| 392 unsigned /*port*/, | |
| 393 scoped_ptr<MessageInTransit> message) { | |
| 394 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " | |
| 395 << message->subtype(); | |
| 396 return MOJO_RESULT_UNKNOWN; | |
| 397 } | |
| 398 | |
| 399 } // namespace system | 386 } // namespace system |
| 400 } // namespace mojo | 387 } // namespace mojo |
| OLD | NEW |