| 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/system/message_pipe.h" | 5 #include "mojo/system/message_pipe.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/system/channel_endpoint.h" |
| 8 #include "mojo/system/local_message_pipe_endpoint.h" | 9 #include "mojo/system/local_message_pipe_endpoint.h" |
| 9 #include "mojo/system/message_in_transit.h" | 10 #include "mojo/system/message_in_transit.h" |
| 10 #include "mojo/system/message_pipe_dispatcher.h" | 11 #include "mojo/system/message_pipe_dispatcher.h" |
| 11 #include "mojo/system/message_pipe_endpoint.h" | 12 #include "mojo/system/message_pipe_endpoint.h" |
| 12 #include "mojo/system/proxy_message_pipe_endpoint.h" | 13 #include "mojo/system/proxy_message_pipe_endpoint.h" |
| 13 | 14 |
| 14 namespace mojo { | 15 namespace mojo { |
| 15 namespace system { | 16 namespace system { |
| 16 | 17 |
| 17 MessagePipe::MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint0, | 18 MessagePipe::MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint0, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 Waiter* waiter, | 139 Waiter* waiter, |
| 139 HandleSignalsState* signals_state) { | 140 HandleSignalsState* signals_state) { |
| 140 DCHECK(port == 0 || port == 1); | 141 DCHECK(port == 0 || port == 1); |
| 141 | 142 |
| 142 base::AutoLock locker(lock_); | 143 base::AutoLock locker(lock_); |
| 143 DCHECK(endpoints_[port]); | 144 DCHECK(endpoints_[port]); |
| 144 | 145 |
| 145 endpoints_[port]->RemoveWaiter(waiter, signals_state); | 146 endpoints_[port]->RemoveWaiter(waiter, signals_state); |
| 146 } | 147 } |
| 147 | 148 |
| 148 void MessagePipe::ConvertLocalToProxy(unsigned port) { | 149 scoped_refptr<ChannelEndpoint> MessagePipe::ConvertLocalToProxy(unsigned port) { |
| 149 DCHECK(port == 0 || port == 1); | 150 DCHECK(port == 0 || port == 1); |
| 150 | 151 |
| 151 base::AutoLock locker(lock_); | 152 base::AutoLock locker(lock_); |
| 152 DCHECK(endpoints_[port]); | 153 DCHECK(endpoints_[port]); |
| 153 DCHECK_EQ(endpoints_[port]->GetType(), MessagePipeEndpoint::kTypeLocal); | 154 DCHECK_EQ(endpoints_[port]->GetType(), MessagePipeEndpoint::kTypeLocal); |
| 154 | 155 |
| 155 bool is_peer_open = !!endpoints_[GetPeerPort(port)]; | 156 bool is_peer_open = !!endpoints_[GetPeerPort(port)]; |
| 156 | 157 |
| 157 // TODO(vtl): Allowing this case is a temporary hack. It'll set up a | 158 // TODO(vtl): Allowing this case is a temporary hack. It'll set up a |
| 158 // |MessagePipe| with two proxy endpoints, which will then act as a proxy | 159 // |MessagePipe| with two proxy endpoints, which will then act as a proxy |
| 159 // (rather than trying to connect the two ends directly). | 160 // (rather than trying to connect the two ends directly). |
| 160 DLOG_IF(WARNING, | 161 DLOG_IF(WARNING, |
| 161 is_peer_open && | 162 is_peer_open && |
| 162 endpoints_[GetPeerPort(port)]->GetType() != | 163 endpoints_[GetPeerPort(port)]->GetType() != |
| 163 MessagePipeEndpoint::kTypeLocal) | 164 MessagePipeEndpoint::kTypeLocal) |
| 164 << "Direct message pipe passing across multiple channels not yet " | 165 << "Direct message pipe passing across multiple channels not yet " |
| 165 "implemented; will proxy"; | 166 "implemented; will proxy"; |
| 166 | 167 |
| 167 scoped_ptr<MessagePipeEndpoint> replacement_endpoint( | 168 scoped_ptr<MessagePipeEndpoint> replacement_endpoint( |
| 168 new ProxyMessagePipeEndpoint( | 169 new ProxyMessagePipeEndpoint( |
| 169 static_cast<LocalMessagePipeEndpoint*>(endpoints_[port].get()), | 170 static_cast<LocalMessagePipeEndpoint*>(endpoints_[port].get()), |
| 170 is_peer_open)); | 171 is_peer_open)); |
| 171 endpoints_[port].swap(replacement_endpoint); | 172 endpoints_[port].swap(replacement_endpoint); |
| 173 |
| 174 return make_scoped_refptr(new ChannelEndpoint(this, port)); |
| 172 } | 175 } |
| 173 | 176 |
| 174 MojoResult MessagePipe::EnqueueMessage(unsigned port, | 177 MojoResult MessagePipe::EnqueueMessage(unsigned port, |
| 175 scoped_ptr<MessageInTransit> message) { | 178 scoped_ptr<MessageInTransit> message) { |
| 176 return EnqueueMessageInternal(port, message.Pass(), NULL); | 179 return EnqueueMessageInternal(port, message.Pass(), NULL); |
| 177 } | 180 } |
| 178 | 181 |
| 179 bool MessagePipe::Attach(unsigned port, ChannelEndpoint* channel_endpoint) { | 182 bool MessagePipe::Attach(unsigned port, ChannelEndpoint* channel_endpoint) { |
| 180 DCHECK(port == 0 || port == 1); | 183 DCHECK(port == 0 || port == 1); |
| 181 DCHECK(channel_endpoint); | 184 DCHECK(channel_endpoint); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 MojoResult MessagePipe::HandleControlMessage( | 304 MojoResult MessagePipe::HandleControlMessage( |
| 302 unsigned /*port*/, | 305 unsigned /*port*/, |
| 303 scoped_ptr<MessageInTransit> message) { | 306 scoped_ptr<MessageInTransit> message) { |
| 304 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " | 307 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " |
| 305 << message->subtype(); | 308 << message->subtype(); |
| 306 return MOJO_RESULT_UNKNOWN; | 309 return MOJO_RESULT_UNKNOWN; |
| 307 } | 310 } |
| 308 | 311 |
| 309 } // namespace system | 312 } // namespace system |
| 310 } // namespace mojo | 313 } // namespace mojo |
| OLD | NEW |