| 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/message_pipe.h" | 9 #include "mojo/edk/system/message_pipe.h" |
| 10 #include "mojo/edk/system/transport_data.h" | 10 #include "mojo/edk/system/transport_data.h" |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 DCHECK(local_id_.is_valid()); | 58 DCHECK(local_id_.is_valid()); |
| 59 // TODO(vtl): Once we combine "run" into "attach", |remote_id_| should valid | 59 // TODO(vtl): Once we combine "run" into "attach", |remote_id_| should valid |
| 60 // here as well. | 60 // here as well. |
| 61 channel_->DetachEndpoint(this, local_id_, remote_id_); | 61 channel_->DetachEndpoint(this, local_id_, remote_id_); |
| 62 channel_ = nullptr; | 62 channel_ = nullptr; |
| 63 local_id_ = ChannelEndpointId(); | 63 local_id_ = ChannelEndpointId(); |
| 64 remote_id_ = ChannelEndpointId(); | 64 remote_id_ = ChannelEndpointId(); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ChannelEndpoint::AttachToChannel(Channel* channel, |
| 69 ChannelEndpointId local_id) { |
| 70 DCHECK(channel); |
| 71 DCHECK(local_id.is_valid()); |
| 72 |
| 73 base::AutoLock locker(lock_); |
| 74 DCHECK(!channel_); |
| 75 DCHECK(!local_id_.is_valid()); |
| 76 channel_ = channel; |
| 77 local_id_ = local_id; |
| 78 } |
| 79 |
| 80 void ChannelEndpoint::Run(ChannelEndpointId remote_id) { |
| 81 DCHECK(remote_id.is_valid()); |
| 82 |
| 83 base::AutoLock locker(lock_); |
| 84 if (!channel_) |
| 85 return; |
| 86 |
| 87 DCHECK(!remote_id_.is_valid()); |
| 88 remote_id_ = remote_id; |
| 89 |
| 90 while (!paused_message_queue_.IsEmpty()) { |
| 91 LOG_IF(WARNING, !WriteMessageNoLock(paused_message_queue_.GetMessage())) |
| 92 << "Failed to write enqueue message to channel"; |
| 93 } |
| 94 } |
| 95 |
| 68 void ChannelEndpoint::AttachAndRun(Channel* channel, | 96 void ChannelEndpoint::AttachAndRun(Channel* channel, |
| 69 ChannelEndpointId local_id, | 97 ChannelEndpointId local_id, |
| 70 ChannelEndpointId remote_id) { | 98 ChannelEndpointId remote_id) { |
| 71 DCHECK(channel); | 99 DCHECK(channel); |
| 72 DCHECK(local_id.is_valid()); | 100 DCHECK(local_id.is_valid()); |
| 73 DCHECK(remote_id.is_valid()); | 101 DCHECK(remote_id.is_valid()); |
| 74 | 102 |
| 75 base::AutoLock locker(lock_); | 103 base::AutoLock locker(lock_); |
| 76 DCHECK(!channel_); | 104 DCHECK(!channel_); |
| 77 DCHECK(!local_id_.is_valid()); | 105 DCHECK(!local_id_.is_valid()); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 DCHECK(remote_id_.is_valid()); | 196 DCHECK(remote_id_.is_valid()); |
| 169 | 197 |
| 170 message->SerializeAndCloseDispatchers(channel_); | 198 message->SerializeAndCloseDispatchers(channel_); |
| 171 message->set_source_id(local_id_); | 199 message->set_source_id(local_id_); |
| 172 message->set_destination_id(remote_id_); | 200 message->set_destination_id(remote_id_); |
| 173 return channel_->WriteMessage(message.Pass()); | 201 return channel_->WriteMessage(message.Pass()); |
| 174 } | 202 } |
| 175 | 203 |
| 176 } // namespace system | 204 } // namespace system |
| 177 } // namespace mojo | 205 } // namespace mojo |
| OLD | NEW |