| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/channel_endpoint.h" | 5 #include "mojo/edk/system/channel_endpoint.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/edk/system/channel.h" | 8 #include "mojo/edk/system/channel.h" |
| 9 #include "mojo/edk/system/channel_endpoint_client.h" | 9 #include "mojo/edk/system/channel_endpoint_client.h" |
| 10 #include "mojo/edk/system/transport_data.h" | |
| 11 | 10 |
| 12 namespace mojo { | 11 namespace mojo { |
| 13 namespace system { | 12 namespace system { |
| 14 | 13 |
| 15 ChannelEndpoint::ChannelEndpoint(ChannelEndpointClient* client, | 14 ChannelEndpoint::ChannelEndpoint(ChannelEndpointClient* client, |
| 16 unsigned client_port, | 15 unsigned client_port, |
| 17 MessageInTransitQueue* message_queue) | 16 MessageInTransitQueue* message_queue) |
| 18 : client_(client), client_port_(client_port), channel_(nullptr) { | 17 : client_(client), client_port_(client_port), channel_(nullptr) { |
| 19 DCHECK(client_.get() || message_queue); | 18 DCHECK(client_.get() || message_queue); |
| 20 | 19 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 77 } |
| 79 | 78 |
| 80 if (!client_.get()) { | 79 if (!client_.get()) { |
| 81 channel_->DetachEndpoint(this, local_id_, remote_id_); | 80 channel_->DetachEndpoint(this, local_id_, remote_id_); |
| 82 channel_ = nullptr; | 81 channel_ = nullptr; |
| 83 local_id_ = ChannelEndpointId(); | 82 local_id_ = ChannelEndpointId(); |
| 84 remote_id_ = ChannelEndpointId(); | 83 remote_id_ = ChannelEndpointId(); |
| 85 } | 84 } |
| 86 } | 85 } |
| 87 | 86 |
| 88 bool ChannelEndpoint::OnReadMessage( | 87 bool ChannelEndpoint::OnReadMessage(scoped_ptr<MessageInTransit> message) { |
| 89 const MessageInTransit::View& message_view, | |
| 90 embedder::ScopedPlatformHandleVectorPtr platform_handles) { | |
| 91 scoped_ptr<MessageInTransit> message(new MessageInTransit(message_view)); | |
| 92 scoped_refptr<ChannelEndpointClient> client; | 88 scoped_refptr<ChannelEndpointClient> client; |
| 93 unsigned client_port; | 89 unsigned client_port; |
| 94 { | 90 { |
| 95 base::AutoLock locker(lock_); | 91 base::AutoLock locker(lock_); |
| 96 DCHECK(channel_); | 92 DCHECK(channel_); |
| 97 if (!client_.get()) { | 93 if (!client_.get()) { |
| 98 // This isn't a failure per se. (It just means that, e.g., the other end | 94 // This isn't a failure per se. (It just means that, e.g., the other end |
| 99 // of the message point closed first.) | 95 // of the message point closed first.) |
| 100 return true; | 96 return true; |
| 101 } | 97 } |
| 102 | 98 |
| 103 if (message_view.transport_data_buffer_size() > 0) { | |
| 104 DCHECK(message_view.transport_data_buffer()); | |
| 105 message->SetDispatchers(TransportData::DeserializeDispatchers( | |
| 106 message_view.transport_data_buffer(), | |
| 107 message_view.transport_data_buffer_size(), platform_handles.Pass(), | |
| 108 channel_)); | |
| 109 } | |
| 110 | |
| 111 // Take a ref, and call |OnReadMessage()| outside the lock. | 99 // Take a ref, and call |OnReadMessage()| outside the lock. |
| 112 client = client_; | 100 client = client_; |
| 113 client_port = client_port_; | 101 client_port = client_port_; |
| 114 } | 102 } |
| 115 | 103 |
| 116 return client->OnReadMessage(client_port, message.Pass()); | 104 return client->OnReadMessage(client_port, message.Pass()); |
| 117 } | 105 } |
| 118 | 106 |
| 119 void ChannelEndpoint::DetachFromChannel() { | 107 void ChannelEndpoint::DetachFromChannel() { |
| 120 scoped_refptr<ChannelEndpointClient> client; | 108 scoped_refptr<ChannelEndpointClient> client; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 DCHECK(remote_id_.is_valid()); | 149 DCHECK(remote_id_.is_valid()); |
| 162 | 150 |
| 163 message->SerializeAndCloseDispatchers(channel_); | 151 message->SerializeAndCloseDispatchers(channel_); |
| 164 message->set_source_id(local_id_); | 152 message->set_source_id(local_id_); |
| 165 message->set_destination_id(remote_id_); | 153 message->set_destination_id(remote_id_); |
| 166 return channel_->WriteMessage(message.Pass()); | 154 return channel_->WriteMessage(message.Pass()); |
| 167 } | 155 } |
| 168 | 156 |
| 169 } // namespace system | 157 } // namespace system |
| 170 } // namespace mojo | 158 } // namespace mojo |
| OLD | NEW |