| 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/dispatcher.h" |
| 10 #include "mojo/system/local_message_pipe_endpoint.h" | 11 #include "mojo/system/local_message_pipe_endpoint.h" |
| 11 #include "mojo/system/message_in_transit.h" | 12 #include "mojo/system/message_in_transit.h" |
| 12 #include "mojo/system/message_pipe_endpoint.h" | 13 #include "mojo/system/message_pipe_endpoint.h" |
| 13 #include "mojo/system/proxy_message_pipe_endpoint.h" | 14 #include "mojo/system/proxy_message_pipe_endpoint.h" |
| 14 | 15 |
| 15 namespace mojo { | 16 namespace mojo { |
| 16 namespace system { | 17 namespace system { |
| 17 | 18 |
| 18 MessagePipe::MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint_0, | 19 MessagePipe::MessagePipe(scoped_ptr<MessagePipeEndpoint> endpoint_0, |
| 19 scoped_ptr<MessagePipeEndpoint> endpoint_1) { | 20 scoped_ptr<MessagePipeEndpoint> endpoint_1) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 MessageInTransit::Create( | 73 MessageInTransit::Create( |
| 73 MessageInTransit::kTypeMessagePipeEndpoint, | 74 MessageInTransit::kTypeMessagePipeEndpoint, |
| 74 MessageInTransit::kSubtypeMessagePipeEndpointData, | 75 MessageInTransit::kSubtypeMessagePipeEndpointData, |
| 75 bytes, num_bytes), | 76 bytes, num_bytes), |
| 76 dispatchers); | 77 dispatchers); |
| 77 } | 78 } |
| 78 | 79 |
| 79 MojoResult MessagePipe::ReadMessage( | 80 MojoResult MessagePipe::ReadMessage( |
| 80 unsigned port, | 81 unsigned port, |
| 81 void* bytes, uint32_t* num_bytes, | 82 void* bytes, uint32_t* num_bytes, |
| 82 uint32_t max_num_dispatchers, | |
| 83 std::vector<scoped_refptr<Dispatcher> >* dispatchers, | 83 std::vector<scoped_refptr<Dispatcher> >* dispatchers, |
| 84 uint32_t* num_dispatchers, |
| 84 MojoReadMessageFlags flags) { | 85 MojoReadMessageFlags flags) { |
| 85 DCHECK(port == 0 || port == 1); | 86 DCHECK(port == 0 || port == 1); |
| 86 | 87 |
| 87 base::AutoLock locker(lock_); | 88 base::AutoLock locker(lock_); |
| 88 DCHECK(endpoints_[port].get()); | 89 DCHECK(endpoints_[port].get()); |
| 89 | 90 |
| 90 return endpoints_[port]->ReadMessage(bytes, num_bytes, | 91 return endpoints_[port]->ReadMessage(bytes, num_bytes, |
| 91 max_num_dispatchers, dispatchers, | 92 dispatchers, num_dispatchers, |
| 92 flags); | 93 flags); |
| 93 } | 94 } |
| 94 | 95 |
| 95 MojoResult MessagePipe::AddWaiter(unsigned port, | 96 MojoResult MessagePipe::AddWaiter(unsigned port, |
| 96 Waiter* waiter, | 97 Waiter* waiter, |
| 97 MojoWaitFlags flags, | 98 MojoWaitFlags flags, |
| 98 MojoResult wake_result) { | 99 MojoResult wake_result) { |
| 99 DCHECK(port == 0 || port == 1); | 100 DCHECK(port == 0 || port == 1); |
| 100 | 101 |
| 101 base::AutoLock locker(lock_); | 102 base::AutoLock locker(lock_); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 message->Destroy(); | 136 message->Destroy(); |
| 136 return MOJO_RESULT_FAILED_PRECONDITION; | 137 return MOJO_RESULT_FAILED_PRECONDITION; |
| 137 } | 138 } |
| 138 | 139 |
| 139 MojoResult result = endpoints_[port]->CanEnqueueMessage(message, dispatchers); | 140 MojoResult result = endpoints_[port]->CanEnqueueMessage(message, dispatchers); |
| 140 if (result != MOJO_RESULT_OK) { | 141 if (result != MOJO_RESULT_OK) { |
| 141 message->Destroy(); | 142 message->Destroy(); |
| 142 return result; | 143 return result; |
| 143 } | 144 } |
| 144 | 145 |
| 145 // TODO(vtl): No endpoints currently support transferring dispatchers, so we | 146 if (dispatchers) { |
| 146 // can get away with this. What we really need to do is create equivalent | 147 DCHECK(!dispatchers->empty()); |
| 147 // dispatchers here (and close the original dispatchers). | |
| 148 DCHECK(!dispatchers); | |
| 149 | 148 |
| 150 endpoints_[port]->EnqueueMessage(message, NULL); | 149 std::vector<scoped_refptr<Dispatcher> > replacement_dispatchers; |
| 150 for (size_t i = 0; i < dispatchers->size(); i++) { |
| 151 replacement_dispatchers.push_back( |
| 152 (*dispatchers)[i]->CreateEquivalentDispatcherAndCloseNoLock()); |
| 153 } |
| 154 |
| 155 endpoints_[port]->EnqueueMessage(message, &replacement_dispatchers); |
| 156 } else { |
| 157 endpoints_[port]->EnqueueMessage(message, NULL); |
| 158 } |
| 159 |
| 151 return MOJO_RESULT_OK; | 160 return MOJO_RESULT_OK; |
| 152 } | 161 } |
| 153 | 162 |
| 154 void MessagePipe::Attach(unsigned port, | 163 void MessagePipe::Attach(unsigned port, |
| 155 scoped_refptr<Channel> channel, | 164 scoped_refptr<Channel> channel, |
| 156 MessageInTransit::EndpointId local_id) { | 165 MessageInTransit::EndpointId local_id) { |
| 157 DCHECK(port == 0 || port == 1); | 166 DCHECK(port == 0 || port == 1); |
| 158 DCHECK(channel.get()); | 167 DCHECK(channel.get()); |
| 159 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); | 168 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); |
| 160 | 169 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 rv = MOJO_RESULT_UNKNOWN; | 221 rv = MOJO_RESULT_UNKNOWN; |
| 213 break; | 222 break; |
| 214 } | 223 } |
| 215 | 224 |
| 216 message->Destroy(); | 225 message->Destroy(); |
| 217 return rv; | 226 return rv; |
| 218 } | 227 } |
| 219 | 228 |
| 220 } // namespace system | 229 } // namespace system |
| 221 } // namespace mojo | 230 } // namespace mojo |
| OLD | NEW |