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/channel_endpoint.h" |
9 #include "mojo/system/local_message_pipe_endpoint.h" | 9 #include "mojo/system/local_message_pipe_endpoint.h" |
10 #include "mojo/system/message_in_transit.h" | 10 #include "mojo/system/message_in_transit.h" |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 endpoints_[port]->RemoveWaiter(waiter, signals_state); | 151 endpoints_[port]->RemoveWaiter(waiter, signals_state); |
152 } | 152 } |
153 | 153 |
154 scoped_refptr<ChannelEndpoint> MessagePipe::ConvertLocalToProxy(unsigned port) { | 154 scoped_refptr<ChannelEndpoint> MessagePipe::ConvertLocalToProxy(unsigned port) { |
155 DCHECK(port == 0 || port == 1); | 155 DCHECK(port == 0 || port == 1); |
156 | 156 |
157 base::AutoLock locker(lock_); | 157 base::AutoLock locker(lock_); |
158 DCHECK(endpoints_[port]); | 158 DCHECK(endpoints_[port]); |
159 DCHECK_EQ(endpoints_[port]->GetType(), MessagePipeEndpoint::kTypeLocal); | 159 DCHECK_EQ(endpoints_[port]->GetType(), MessagePipeEndpoint::kTypeLocal); |
160 | 160 |
161 bool is_peer_open = !!endpoints_[GetPeerPort(port)]; | |
162 | |
163 // TODO(vtl): Allowing this case is a temporary hack. It'll set up a | 161 // TODO(vtl): Allowing this case is a temporary hack. It'll set up a |
164 // |MessagePipe| with two proxy endpoints, which will then act as a proxy | 162 // |MessagePipe| with two proxy endpoints, which will then act as a proxy |
165 // (rather than trying to connect the two ends directly). | 163 // (rather than trying to connect the two ends directly). |
166 DLOG_IF(WARNING, | 164 DLOG_IF(WARNING, |
167 is_peer_open && | 165 !!endpoints_[GetPeerPort(port)] && |
168 endpoints_[GetPeerPort(port)]->GetType() != | 166 endpoints_[GetPeerPort(port)]->GetType() != |
169 MessagePipeEndpoint::kTypeLocal) | 167 MessagePipeEndpoint::kTypeLocal) |
170 << "Direct message pipe passing across multiple channels not yet " | 168 << "Direct message pipe passing across multiple channels not yet " |
171 "implemented; will proxy"; | 169 "implemented; will proxy"; |
172 | 170 |
173 scoped_ptr<MessagePipeEndpoint> old_endpoint(endpoints_[port].Pass()); | 171 scoped_ptr<MessagePipeEndpoint> old_endpoint(endpoints_[port].Pass()); |
174 scoped_refptr<ChannelEndpoint> channel_endpoint( | 172 scoped_refptr<ChannelEndpoint> channel_endpoint( |
175 new ChannelEndpoint(this, port)); | 173 new ChannelEndpoint(this, port)); |
176 endpoints_[port].reset( | 174 endpoints_[port].reset(new ProxyMessagePipeEndpoint(channel_endpoint.get())); |
177 new ProxyMessagePipeEndpoint(channel_endpoint.get(), is_peer_open)); | |
178 channel_endpoint->TakeMessages(static_cast<LocalMessagePipeEndpoint*>( | 175 channel_endpoint->TakeMessages(static_cast<LocalMessagePipeEndpoint*>( |
179 old_endpoint.get())->message_queue()); | 176 old_endpoint.get())->message_queue()); |
180 old_endpoint->Close(); | 177 old_endpoint->Close(); |
181 | 178 |
182 return channel_endpoint; | 179 return channel_endpoint; |
183 } | 180 } |
184 | 181 |
185 MojoResult MessagePipe::EnqueueMessage(unsigned port, | 182 MojoResult MessagePipe::EnqueueMessage(unsigned port, |
186 scoped_ptr<MessageInTransit> message) { | 183 scoped_ptr<MessageInTransit> message) { |
187 return EnqueueMessageInternal(port, message.Pass(), nullptr); | 184 return EnqueueMessageInternal(port, message.Pass(), nullptr); |
188 } | 185 } |
189 | 186 |
190 void MessagePipe::Run(unsigned port) { | |
191 DCHECK(port == 0 || port == 1); | |
192 | |
193 base::AutoLock locker(lock_); | |
194 DCHECK(endpoints_[port]); | |
195 if (!endpoints_[port]->Run()) | |
196 endpoints_[port].reset(); | |
197 } | |
198 | |
199 void MessagePipe::OnRemove(unsigned port) { | 187 void MessagePipe::OnRemove(unsigned port) { |
200 unsigned destination_port = GetPeerPort(port); | 188 unsigned destination_port = GetPeerPort(port); |
201 | 189 |
202 base::AutoLock locker(lock_); | 190 base::AutoLock locker(lock_); |
203 // A |OnPeerClose()| can come in first, before |OnRemove()| gets called. | 191 // A |OnPeerClose()| can come in first, before |OnRemove()| gets called. |
204 if (!endpoints_[port]) | 192 if (!endpoints_[port]) |
205 return; | 193 return; |
206 | 194 |
207 endpoints_[port]->OnRemove(); | 195 endpoints_[port]->OnRemove(); |
208 if (endpoints_[destination_port]) { | 196 if (endpoints_[destination_port]) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 MojoResult MessagePipe::HandleControlMessage( | 290 MojoResult MessagePipe::HandleControlMessage( |
303 unsigned /*port*/, | 291 unsigned /*port*/, |
304 scoped_ptr<MessageInTransit> message) { | 292 scoped_ptr<MessageInTransit> message) { |
305 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " | 293 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " |
306 << message->subtype(); | 294 << message->subtype(); |
307 return MOJO_RESULT_UNKNOWN; | 295 return MOJO_RESULT_UNKNOWN; |
308 } | 296 } |
309 | 297 |
310 } // namespace system | 298 } // namespace system |
311 } // namespace mojo | 299 } // namespace mojo |
OLD | NEW |