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 "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "mojo/system/channel.h" | 9 #include "mojo/system/channel.h" |
10 #include "mojo/system/local_message_pipe_endpoint.h" | 10 #include "mojo/system/local_message_pipe_endpoint.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 129 |
130 base::AutoLock locker(lock_); | 130 base::AutoLock locker(lock_); |
131 DCHECK(endpoints_[GetPeerPort(port)].get()); | 131 DCHECK(endpoints_[GetPeerPort(port)].get()); |
132 | 132 |
133 // The destination port need not be open, unlike the source port. | 133 // The destination port need not be open, unlike the source port. |
134 if (!endpoints_[port].get()) { | 134 if (!endpoints_[port].get()) { |
135 message->Destroy(); | 135 message->Destroy(); |
136 return MOJO_RESULT_FAILED_PRECONDITION; | 136 return MOJO_RESULT_FAILED_PRECONDITION; |
137 } | 137 } |
138 | 138 |
139 return endpoints_[port]->EnqueueMessage(message, dispatchers); | 139 MojoResult result = endpoints_[port]->CanEnqueueMessage(message, dispatchers); |
| 140 if (result != MOJO_RESULT_OK) { |
| 141 message->Destroy(); |
| 142 return result; |
| 143 } |
| 144 |
| 145 // TODO(vtl): No endpoints currently support transferring dispatchers, so we |
| 146 // can get away with this. What we really need to do is create equivalent |
| 147 // dispatchers here (and close the original dispatchers). |
| 148 DCHECK(!dispatchers); |
| 149 |
| 150 endpoints_[port]->EnqueueMessage(message, NULL); |
| 151 return MOJO_RESULT_OK; |
140 } | 152 } |
141 | 153 |
142 void MessagePipe::Attach(unsigned port, | 154 void MessagePipe::Attach(unsigned port, |
143 scoped_refptr<Channel> channel, | 155 scoped_refptr<Channel> channel, |
144 MessageInTransit::EndpointId local_id) { | 156 MessageInTransit::EndpointId local_id) { |
145 DCHECK(port == 0 || port == 1); | 157 DCHECK(port == 0 || port == 1); |
146 DCHECK(channel.get()); | 158 DCHECK(channel.get()); |
147 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); | 159 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); |
148 | 160 |
149 base::AutoLock locker(lock_); | 161 base::AutoLock locker(lock_); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 rv = MOJO_RESULT_UNKNOWN; | 212 rv = MOJO_RESULT_UNKNOWN; |
201 break; | 213 break; |
202 } | 214 } |
203 | 215 |
204 message->Destroy(); | 216 message->Destroy(); |
205 return rv; | 217 return rv; |
206 } | 218 } |
207 | 219 |
208 } // namespace system | 220 } // namespace system |
209 } // namespace mojo | 221 } // namespace mojo |
OLD | NEW |