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