| 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_endpoint.h" |    8 #include "mojo/edk/system/channel_endpoint.h" | 
|    9 #include "mojo/edk/system/local_message_pipe_endpoint.h" |    9 #include "mojo/edk/system/local_message_pipe_endpoint.h" | 
|   10 #include "mojo/edk/system/message_in_transit.h" |   10 #include "mojo/edk/system/message_in_transit.h" | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   93     unsigned port, |   93     unsigned port, | 
|   94     UserPointer<const void> bytes, |   94     UserPointer<const void> bytes, | 
|   95     uint32_t num_bytes, |   95     uint32_t num_bytes, | 
|   96     std::vector<DispatcherTransport>* transports, |   96     std::vector<DispatcherTransport>* transports, | 
|   97     MojoWriteMessageFlags flags) { |   97     MojoWriteMessageFlags flags) { | 
|   98   DCHECK(port == 0 || port == 1); |   98   DCHECK(port == 0 || port == 1); | 
|   99   return EnqueueMessageInternal( |   99   return EnqueueMessageInternal( | 
|  100       GetPeerPort(port), |  100       GetPeerPort(port), | 
|  101       make_scoped_ptr(new MessageInTransit( |  101       make_scoped_ptr(new MessageInTransit( | 
|  102           MessageInTransit::kTypeMessagePipeEndpoint, |  102           MessageInTransit::kTypeMessagePipeEndpoint, | 
|  103           MessageInTransit::kSubtypeMessagePipeEndpointData, |  103           MessageInTransit::kSubtypeMessagePipeEndpointData, num_bytes, bytes)), | 
|  104           num_bytes, |  | 
|  105           bytes)), |  | 
|  106       transports); |  104       transports); | 
|  107 } |  105 } | 
|  108  |  106  | 
|  109 MojoResult MessagePipe::ReadMessage(unsigned port, |  107 MojoResult MessagePipe::ReadMessage(unsigned port, | 
|  110                                     UserPointer<void> bytes, |  108                                     UserPointer<void> bytes, | 
|  111                                     UserPointer<uint32_t> num_bytes, |  109                                     UserPointer<uint32_t> num_bytes, | 
|  112                                     DispatcherVector* dispatchers, |  110                                     DispatcherVector* dispatchers, | 
|  113                                     uint32_t* num_dispatchers, |  111                                     uint32_t* num_dispatchers, | 
|  114                                     MojoReadMessageFlags flags) { |  112                                     MojoReadMessageFlags flags) { | 
|  115   DCHECK(port == 0 || port == 1); |  113   DCHECK(port == 0 || port == 1); | 
|  116  |  114  | 
|  117   base::AutoLock locker(lock_); |  115   base::AutoLock locker(lock_); | 
|  118   DCHECK(endpoints_[port]); |  116   DCHECK(endpoints_[port]); | 
|  119  |  117  | 
|  120   return endpoints_[port]->ReadMessage( |  118   return endpoints_[port]->ReadMessage(bytes, num_bytes, dispatchers, | 
|  121       bytes, num_bytes, dispatchers, num_dispatchers, flags); |  119                                        num_dispatchers, flags); | 
|  122 } |  120 } | 
|  123  |  121  | 
|  124 HandleSignalsState MessagePipe::GetHandleSignalsState(unsigned port) const { |  122 HandleSignalsState MessagePipe::GetHandleSignalsState(unsigned port) const { | 
|  125   DCHECK(port == 0 || port == 1); |  123   DCHECK(port == 0 || port == 1); | 
|  126  |  124  | 
|  127   base::AutoLock locker(const_cast<base::Lock&>(lock_)); |  125   base::AutoLock locker(const_cast<base::Lock&>(lock_)); | 
|  128   DCHECK(endpoints_[port]); |  126   DCHECK(endpoints_[port]); | 
|  129  |  127  | 
|  130   return endpoints_[port]->GetHandleSignalsState(); |  128   return endpoints_[port]->GetHandleSignalsState(); | 
|  131 } |  129 } | 
| (...skipping 26 matching lines...) Expand all  Loading... | 
|  158   DCHECK(port == 0 || port == 1); |  156   DCHECK(port == 0 || port == 1); | 
|  159  |  157  | 
|  160   base::AutoLock locker(lock_); |  158   base::AutoLock locker(lock_); | 
|  161   DCHECK(endpoints_[port]); |  159   DCHECK(endpoints_[port]); | 
|  162   DCHECK_EQ(endpoints_[port]->GetType(), MessagePipeEndpoint::kTypeLocal); |  160   DCHECK_EQ(endpoints_[port]->GetType(), MessagePipeEndpoint::kTypeLocal); | 
|  163  |  161  | 
|  164   // The local peer is already closed, so just make a |ChannelEndpoint| that'll |  162   // The local peer is already closed, so just make a |ChannelEndpoint| that'll | 
|  165   // send the already-queued messages. |  163   // send the already-queued messages. | 
|  166   if (!endpoints_[GetPeerPort(port)]) { |  164   if (!endpoints_[GetPeerPort(port)]) { | 
|  167     scoped_refptr<ChannelEndpoint> channel_endpoint(new ChannelEndpoint( |  165     scoped_refptr<ChannelEndpoint> channel_endpoint(new ChannelEndpoint( | 
|  168         nullptr, |  166         nullptr, 0, static_cast<LocalMessagePipeEndpoint*>( | 
|  169         0, |  167                         endpoints_[port].get())->message_queue())); | 
|  170         static_cast<LocalMessagePipeEndpoint*>(endpoints_[port].get()) |  | 
|  171             ->message_queue())); |  | 
|  172     endpoints_[port]->Close(); |  168     endpoints_[port]->Close(); | 
|  173     endpoints_[port].reset(); |  169     endpoints_[port].reset(); | 
|  174     return channel_endpoint; |  170     return channel_endpoint; | 
|  175   } |  171   } | 
|  176  |  172  | 
|  177   // TODO(vtl): Allowing this case is a temporary hack. It'll set up a |  173   // TODO(vtl): Allowing this case is a temporary hack. It'll set up a | 
|  178   // |MessagePipe| with two proxy endpoints, which will then act as a proxy |  174   // |MessagePipe| with two proxy endpoints, which will then act as a proxy | 
|  179   // (rather than trying to connect the two ends directly). |  175   // (rather than trying to connect the two ends directly). | 
|  180   DLOG_IF(WARNING, |  176   DLOG_IF(WARNING, endpoints_[GetPeerPort(port)]->GetType() != | 
|  181           endpoints_[GetPeerPort(port)]->GetType() != |  177                        MessagePipeEndpoint::kTypeLocal) | 
|  182               MessagePipeEndpoint::kTypeLocal) |  | 
|  183       << "Direct message pipe passing across multiple channels not yet " |  178       << "Direct message pipe passing across multiple channels not yet " | 
|  184          "implemented; will proxy"; |  179          "implemented; will proxy"; | 
|  185  |  180  | 
|  186   scoped_ptr<MessagePipeEndpoint> old_endpoint(endpoints_[port].Pass()); |  181   scoped_ptr<MessagePipeEndpoint> old_endpoint(endpoints_[port].Pass()); | 
|  187   scoped_refptr<ChannelEndpoint> channel_endpoint(new ChannelEndpoint( |  182   scoped_refptr<ChannelEndpoint> channel_endpoint(new ChannelEndpoint( | 
|  188       this, |  183       this, port, static_cast<LocalMessagePipeEndpoint*>(old_endpoint.get()) | 
|  189       port, |  184                       ->message_queue())); | 
|  190       static_cast<LocalMessagePipeEndpoint*>(old_endpoint.get()) |  | 
|  191           ->message_queue())); |  | 
|  192   endpoints_[port].reset(new ProxyMessagePipeEndpoint(channel_endpoint.get())); |  185   endpoints_[port].reset(new ProxyMessagePipeEndpoint(channel_endpoint.get())); | 
|  193   old_endpoint->Close(); |  186   old_endpoint->Close(); | 
|  194  |  187  | 
|  195   return channel_endpoint; |  188   return channel_endpoint; | 
|  196 } |  189 } | 
|  197  |  190  | 
|  198 MojoResult MessagePipe::EnqueueMessage(unsigned port, |  191 MojoResult MessagePipe::EnqueueMessage(unsigned port, | 
|  199                                        scoped_ptr<MessageInTransit> message) { |  192                                        scoped_ptr<MessageInTransit> message) { | 
|  200   return EnqueueMessageInternal(port, message.Pass(), nullptr); |  193   return EnqueueMessageInternal(port, message.Pass(), nullptr); | 
|  201 } |  194 } | 
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  290 MojoResult MessagePipe::HandleControlMessage( |  283 MojoResult MessagePipe::HandleControlMessage( | 
|  291     unsigned /*port*/, |  284     unsigned /*port*/, | 
|  292     scoped_ptr<MessageInTransit> message) { |  285     scoped_ptr<MessageInTransit> message) { | 
|  293   LOG(WARNING) << "Unrecognized MessagePipe control message subtype " |  286   LOG(WARNING) << "Unrecognized MessagePipe control message subtype " | 
|  294                << message->subtype(); |  287                << message->subtype(); | 
|  295   return MOJO_RESULT_UNKNOWN; |  288   return MOJO_RESULT_UNKNOWN; | 
|  296 } |  289 } | 
|  297  |  290  | 
|  298 }  // namespace system |  291 }  // namespace system | 
|  299 }  // namespace mojo |  292 }  // namespace mojo | 
| OLD | NEW |