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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 DCHECK(endpoints_[port]); | 68 DCHECK(endpoints_[port]); |
69 endpoints_[port]->CancelAllWaiters(); | 69 endpoints_[port]->CancelAllWaiters(); |
70 } | 70 } |
71 | 71 |
72 void MessagePipe::Close(unsigned port) { | 72 void MessagePipe::Close(unsigned port) { |
73 DCHECK(port == 0 || port == 1); | 73 DCHECK(port == 0 || port == 1); |
74 | 74 |
75 unsigned destination_port = GetPeerPort(port); | 75 unsigned destination_port = GetPeerPort(port); |
76 | 76 |
77 base::AutoLock locker(lock_); | 77 base::AutoLock locker(lock_); |
78 DCHECK(endpoints_[port]); | 78 // The endpoint's |OnPeerClose()| may have been called first and returned |
| 79 // false, which would have resulted in its destruction. |
| 80 if (!endpoints_[port]) |
| 81 return; |
79 | 82 |
80 endpoints_[port]->Close(); | 83 endpoints_[port]->Close(); |
81 if (endpoints_[destination_port]) { | 84 if (endpoints_[destination_port]) { |
82 if (!endpoints_[destination_port]->OnPeerClose()) | 85 if (!endpoints_[destination_port]->OnPeerClose()) |
83 endpoints_[destination_port].reset(); | 86 endpoints_[destination_port].reset(); |
84 } | 87 } |
85 endpoints_[port].reset(); | 88 endpoints_[port].reset(); |
86 } | 89 } |
87 | 90 |
88 // TODO(vtl): Handle flags. | 91 // TODO(vtl): Handle flags. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 old_endpoint->Close(); | 180 old_endpoint->Close(); |
178 | 181 |
179 return channel_endpoint; | 182 return channel_endpoint; |
180 } | 183 } |
181 | 184 |
182 MojoResult MessagePipe::EnqueueMessage(unsigned port, | 185 MojoResult MessagePipe::EnqueueMessage(unsigned port, |
183 scoped_ptr<MessageInTransit> message) { | 186 scoped_ptr<MessageInTransit> message) { |
184 return EnqueueMessageInternal(port, message.Pass(), nullptr); | 187 return EnqueueMessageInternal(port, message.Pass(), nullptr); |
185 } | 188 } |
186 | 189 |
187 void MessagePipe::OnRemove(unsigned port) { | |
188 unsigned destination_port = GetPeerPort(port); | |
189 | |
190 base::AutoLock locker(lock_); | |
191 // A |OnPeerClose()| can come in first, before |OnRemove()| gets called. | |
192 if (!endpoints_[port]) | |
193 return; | |
194 | |
195 if (endpoints_[destination_port]) { | |
196 if (!endpoints_[destination_port]->OnPeerClose()) | |
197 endpoints_[destination_port].reset(); | |
198 } | |
199 endpoints_[port].reset(); | |
200 } | |
201 | |
202 MessagePipe::MessagePipe() { | 190 MessagePipe::MessagePipe() { |
203 } | 191 } |
204 | 192 |
205 MessagePipe::~MessagePipe() { | 193 MessagePipe::~MessagePipe() { |
206 // Owned by the dispatchers. The owning dispatchers should only release us via | 194 // Owned by the dispatchers. The owning dispatchers should only release us via |
207 // their |Close()| method, which should inform us of being closed via our | 195 // their |Close()| method, which should inform us of being closed via our |
208 // |Close()|. Thus these should already be null. | 196 // |Close()|. Thus these should already be null. |
209 DCHECK(!endpoints_[0]); | 197 DCHECK(!endpoints_[0]); |
210 DCHECK(!endpoints_[1]); | 198 DCHECK(!endpoints_[1]); |
211 } | 199 } |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 MojoResult MessagePipe::HandleControlMessage( | 277 MojoResult MessagePipe::HandleControlMessage( |
290 unsigned /*port*/, | 278 unsigned /*port*/, |
291 scoped_ptr<MessageInTransit> message) { | 279 scoped_ptr<MessageInTransit> message) { |
292 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " | 280 LOG(WARNING) << "Unrecognized MessagePipe control message subtype " |
293 << message->subtype(); | 281 << message->subtype(); |
294 return MOJO_RESULT_UNKNOWN; | 282 return MOJO_RESULT_UNKNOWN; |
295 } | 283 } |
296 | 284 |
297 } // namespace system | 285 } // namespace system |
298 } // namespace mojo | 286 } // namespace mojo |
OLD | NEW |