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/proxy_message_pipe_endpoint.h" | 5 #include "mojo/system/proxy_message_pipe_endpoint.h" |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "mojo/system/channel.h" | 10 #include "mojo/system/channel.h" |
| 11 #include "mojo/system/channel_endpoint.h" |
11 #include "mojo/system/local_message_pipe_endpoint.h" | 12 #include "mojo/system/local_message_pipe_endpoint.h" |
12 #include "mojo/system/message_pipe_dispatcher.h" | 13 #include "mojo/system/message_pipe_dispatcher.h" |
13 | 14 |
14 namespace mojo { | 15 namespace mojo { |
15 namespace system { | 16 namespace system { |
16 | 17 |
17 ProxyMessagePipeEndpoint::ProxyMessagePipeEndpoint() | 18 ProxyMessagePipeEndpoint::ProxyMessagePipeEndpoint() |
18 : local_id_(MessageInTransit::kInvalidEndpointId), | 19 : local_id_(MessageInTransit::kInvalidEndpointId), |
19 remote_id_(MessageInTransit::kInvalidEndpointId), | 20 remote_id_(MessageInTransit::kInvalidEndpointId), |
20 is_peer_open_(true) { | 21 is_peer_open_(true) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 75 |
75 message->set_source_id(local_id_); | 76 message->set_source_id(local_id_); |
76 message->set_destination_id(remote_id_); | 77 message->set_destination_id(remote_id_); |
77 if (!channel_->WriteMessage(message.Pass())) | 78 if (!channel_->WriteMessage(message.Pass())) |
78 LOG(WARNING) << "Failed to write message to channel"; | 79 LOG(WARNING) << "Failed to write message to channel"; |
79 } else { | 80 } else { |
80 paused_message_queue_.AddMessage(message.Pass()); | 81 paused_message_queue_.AddMessage(message.Pass()); |
81 } | 82 } |
82 } | 83 } |
83 | 84 |
84 void ProxyMessagePipeEndpoint::Attach(scoped_refptr<Channel> channel, | 85 void ProxyMessagePipeEndpoint::Attach(ChannelEndpoint* channel_endpoint, |
| 86 Channel* channel, |
85 MessageInTransit::EndpointId local_id) { | 87 MessageInTransit::EndpointId local_id) { |
86 DCHECK(channel.get()); | 88 DCHECK(channel_endpoint); |
| 89 DCHECK(channel); |
87 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); | 90 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); |
88 | 91 |
89 DCHECK(!is_attached()); | 92 DCHECK(!is_attached()); |
90 | 93 |
91 AssertConsistentState(); | 94 AssertConsistentState(); |
| 95 channel_endpoint_ = channel_endpoint; |
92 channel_ = channel; | 96 channel_ = channel; |
93 local_id_ = local_id; | 97 local_id_ = local_id; |
94 AssertConsistentState(); | 98 AssertConsistentState(); |
95 } | 99 } |
96 | 100 |
97 bool ProxyMessagePipeEndpoint::Run(MessageInTransit::EndpointId remote_id) { | 101 bool ProxyMessagePipeEndpoint::Run(MessageInTransit::EndpointId remote_id) { |
98 // Assertions about arguments: | 102 // Assertions about arguments: |
99 DCHECK_NE(remote_id, MessageInTransit::kInvalidEndpointId); | 103 DCHECK_NE(remote_id, MessageInTransit::kInvalidEndpointId); |
100 | 104 |
101 // Assertions about current state: | 105 // Assertions about current state: |
(...skipping 18 matching lines...) Expand all Loading... |
120 void ProxyMessagePipeEndpoint::OnRemove() { | 124 void ProxyMessagePipeEndpoint::OnRemove() { |
121 Detach(); | 125 Detach(); |
122 } | 126 } |
123 | 127 |
124 void ProxyMessagePipeEndpoint::Detach() { | 128 void ProxyMessagePipeEndpoint::Detach() { |
125 DCHECK(is_attached()); | 129 DCHECK(is_attached()); |
126 | 130 |
127 AssertConsistentState(); | 131 AssertConsistentState(); |
128 channel_->DetachMessagePipeEndpoint(local_id_, remote_id_); | 132 channel_->DetachMessagePipeEndpoint(local_id_, remote_id_); |
129 channel_ = NULL; | 133 channel_ = NULL; |
| 134 // TODO(vtl): Inform |channel_endpoint_| that we were detached. |
| 135 channel_endpoint_ = NULL; |
130 local_id_ = MessageInTransit::kInvalidEndpointId; | 136 local_id_ = MessageInTransit::kInvalidEndpointId; |
131 remote_id_ = MessageInTransit::kInvalidEndpointId; | 137 remote_id_ = MessageInTransit::kInvalidEndpointId; |
132 paused_message_queue_.Clear(); | 138 paused_message_queue_.Clear(); |
133 AssertConsistentState(); | 139 AssertConsistentState(); |
134 } | 140 } |
135 | 141 |
136 #ifndef NDEBUG | 142 #ifndef NDEBUG |
137 void ProxyMessagePipeEndpoint::AssertConsistentState() const { | 143 void ProxyMessagePipeEndpoint::AssertConsistentState() const { |
138 if (is_attached()) { | 144 if (is_attached()) { |
139 DCHECK_NE(local_id_, MessageInTransit::kInvalidEndpointId); | 145 DCHECK_NE(local_id_, MessageInTransit::kInvalidEndpointId); |
140 } else { // Not attached. | 146 } else { // Not attached. |
141 DCHECK_EQ(local_id_, MessageInTransit::kInvalidEndpointId); | 147 DCHECK_EQ(local_id_, MessageInTransit::kInvalidEndpointId); |
142 DCHECK_EQ(remote_id_, MessageInTransit::kInvalidEndpointId); | 148 DCHECK_EQ(remote_id_, MessageInTransit::kInvalidEndpointId); |
143 } | 149 } |
144 } | 150 } |
145 #endif | 151 #endif |
146 | 152 |
147 } // namespace system | 153 } // namespace system |
148 } // namespace mojo | 154 } // namespace mojo |
OLD | NEW |