| 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_dispatcher.h" | 5 #include "mojo/system/message_pipe_dispatcher.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/system/channel.h" | 8 #include "mojo/system/channel.h" |
| 9 #include "mojo/system/constants.h" | 9 #include "mojo/system/constants.h" |
| 10 #include "mojo/system/local_message_pipe_endpoint.h" | 10 #include "mojo/system/local_message_pipe_endpoint.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 if (size != sizeof(SerializedMessagePipeDispatcher)) { | 66 if (size != sizeof(SerializedMessagePipeDispatcher)) { |
| 67 LOG(ERROR) << "Invalid serialized message pipe dispatcher"; | 67 LOG(ERROR) << "Invalid serialized message pipe dispatcher"; |
| 68 return scoped_refptr<MessagePipeDispatcher>(); | 68 return scoped_refptr<MessagePipeDispatcher>(); |
| 69 } | 69 } |
| 70 | 70 |
| 71 std::pair<scoped_refptr<MessagePipeDispatcher>, scoped_refptr<MessagePipe> > | 71 std::pair<scoped_refptr<MessagePipeDispatcher>, scoped_refptr<MessagePipe> > |
| 72 remote_message_pipe = CreateRemoteMessagePipe(); | 72 remote_message_pipe = CreateRemoteMessagePipe(); |
| 73 | 73 |
| 74 MessageInTransit::EndpointId remote_id = | 74 MessageInTransit::EndpointId remote_id = |
| 75 static_cast<const SerializedMessagePipeDispatcher*>(source)->endpoint_id; | 75 static_cast<const SerializedMessagePipeDispatcher*>(source)->endpoint_id; |
| 76 if (remote_id == MessageInTransit::kInvalidEndpointId) { |
| 77 // This means that the other end was closed, and there were no messages |
| 78 // enqueued for us. |
| 79 // TODO(vtl): This is wrong. We should produce a "dead" message pipe |
| 80 // dispatcher. |
| 81 NOTIMPLEMENTED(); |
| 82 return scoped_refptr<MessagePipeDispatcher>(); |
| 83 } |
| 76 MessageInTransit::EndpointId local_id = | 84 MessageInTransit::EndpointId local_id = |
| 77 channel->AttachMessagePipeEndpoint(remote_message_pipe.second, 1); | 85 channel->AttachMessagePipeEndpoint(remote_message_pipe.second, 1); |
| 86 if (local_id == MessageInTransit::kInvalidEndpointId) { |
| 87 LOG(ERROR) << "Failed to deserialize message pipe dispatcher (failed to " |
| 88 "attach; remote ID = " << remote_id << ")"; |
| 89 return scoped_refptr<MessagePipeDispatcher>(); |
| 90 } |
| 78 DVLOG(2) << "Deserializing message pipe dispatcher (remote ID = " | 91 DVLOG(2) << "Deserializing message pipe dispatcher (remote ID = " |
| 79 << remote_id << ", new local ID = " << local_id << ")"; | 92 << remote_id << ", new local ID = " << local_id << ")"; |
| 80 | 93 |
| 81 if (!channel->RunMessagePipeEndpoint(local_id, remote_id)) { | 94 if (!channel->RunMessagePipeEndpoint(local_id, remote_id)) { |
| 82 // In general, this shouldn't fail, since we generated |local_id| locally. | 95 // In general, this shouldn't fail, since we generated |local_id| locally. |
| 83 NOTREACHED(); | 96 NOTREACHED(); |
| 84 return scoped_refptr<MessagePipeDispatcher>(); | 97 return scoped_refptr<MessagePipeDispatcher>(); |
| 85 } | 98 } |
| 86 | 99 |
| 87 // TODO(vtl): FIXME -- Need some error handling here. | 100 // TODO(vtl): FIXME -- Need some error handling here. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 size_t* actual_size, | 205 size_t* actual_size, |
| 193 std::vector<embedder::PlatformHandle>* platform_handles) { | 206 std::vector<embedder::PlatformHandle>* platform_handles) { |
| 194 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 207 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. |
| 195 | 208 |
| 196 // Convert the local endpoint to a proxy endpoint (moving the message queue). | 209 // Convert the local endpoint to a proxy endpoint (moving the message queue). |
| 197 message_pipe_->ConvertLocalToProxy(port_); | 210 message_pipe_->ConvertLocalToProxy(port_); |
| 198 | 211 |
| 199 // Attach the new proxy endpoint to the channel. | 212 // Attach the new proxy endpoint to the channel. |
| 200 MessageInTransit::EndpointId endpoint_id = | 213 MessageInTransit::EndpointId endpoint_id = |
| 201 channel->AttachMessagePipeEndpoint(message_pipe_, port_); | 214 channel->AttachMessagePipeEndpoint(message_pipe_, port_); |
| 202 DCHECK_NE(endpoint_id, MessageInTransit::kInvalidEndpointId); | 215 // Note: It's okay to get an endpoint ID of |kInvalidEndpointId|. (It's |
| 203 | 216 // possible that the other endpoint -- the one that we're not sending -- was |
| 217 // closed in the intervening time.) In that case, we need to deserialize a |
| 218 // "dead" message pipe dispatcher on the other end. (Note that this is |
| 219 // different from just producing |MOJO_HANDLE_INVALID|.) |
| 204 DVLOG(2) << "Serializing message pipe dispatcher (local ID = " << endpoint_id | 220 DVLOG(2) << "Serializing message pipe dispatcher (local ID = " << endpoint_id |
| 205 << ")"; | 221 << ")"; |
| 206 | 222 |
| 207 // We now have a local ID. Before we can run the proxy endpoint, we need to | 223 // We now have a local ID. Before we can run the proxy endpoint, we need to |
| 208 // get an ack back from the other side with the remote ID. | 224 // get an ack back from the other side with the remote ID. |
| 209 static_cast<SerializedMessagePipeDispatcher*>(destination)->endpoint_id = | 225 static_cast<SerializedMessagePipeDispatcher*>(destination)->endpoint_id = |
| 210 endpoint_id; | 226 endpoint_id; |
| 211 | 227 |
| 212 message_pipe_ = NULL; | 228 message_pipe_ = NULL; |
| 213 port_ = kInvalidPort; | 229 port_ = kInvalidPort; |
| 214 | 230 |
| 215 *actual_size = sizeof(SerializedMessagePipeDispatcher); | 231 *actual_size = sizeof(SerializedMessagePipeDispatcher); |
| 216 return true; | 232 return true; |
| 217 } | 233 } |
| 218 | 234 |
| 219 // MessagePipeDispatcherTransport ---------------------------------------------- | 235 // MessagePipeDispatcherTransport ---------------------------------------------- |
| 220 | 236 |
| 221 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( | 237 MessagePipeDispatcherTransport::MessagePipeDispatcherTransport( |
| 222 DispatcherTransport transport) : DispatcherTransport(transport) { | 238 DispatcherTransport transport) : DispatcherTransport(transport) { |
| 223 DCHECK_EQ(message_pipe_dispatcher()->GetType(), Dispatcher::kTypeMessagePipe); | 239 DCHECK_EQ(message_pipe_dispatcher()->GetType(), Dispatcher::kTypeMessagePipe); |
| 224 } | 240 } |
| 225 | 241 |
| 226 } // namespace system | 242 } // namespace system |
| 227 } // namespace mojo | 243 } // namespace mojo |
| OLD | NEW |