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/system/channel_endpoint.h" | 5 #include "mojo/system/channel_endpoint.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/message_pipe.h" | 9 #include "mojo/system/message_pipe.h" |
10 | 10 |
11 namespace mojo { | 11 namespace mojo { |
12 namespace system { | 12 namespace system { |
13 | 13 |
14 ChannelEndpoint::ChannelEndpoint(MessagePipe* message_pipe, | 14 ChannelEndpoint::ChannelEndpoint(MessagePipe* message_pipe, unsigned port) |
15 unsigned port, | |
16 Channel* channel, | |
17 MessageInTransit::EndpointId local_id) | |
18 : state_(STATE_NORMAL), | 15 : state_(STATE_NORMAL), |
19 message_pipe_(message_pipe), | 16 message_pipe_(message_pipe), |
20 port_(port), | 17 port_(port), |
21 channel_(channel), | 18 channel_(), |
22 local_id_(local_id) { | 19 local_id_(MessageInTransit::kInvalidEndpointId), |
| 20 remote_id_(MessageInTransit::kInvalidEndpointId) { |
23 DCHECK(message_pipe_.get()); | 21 DCHECK(message_pipe_.get()); |
24 DCHECK(port_ == 0 || port_ == 1); | 22 DCHECK(port_ == 0 || port_ == 1); |
| 23 } |
| 24 |
| 25 void ChannelEndpoint::AttachToChannel(Channel* channel, |
| 26 MessageInTransit::EndpointId local_id) { |
| 27 DCHECK(channel); |
| 28 DCHECK_NE(local_id, MessageInTransit::kInvalidEndpointId); |
| 29 |
| 30 base::AutoLock locker(lock_); |
| 31 DCHECK(!channel_); |
| 32 DCHECK_EQ(local_id_, MessageInTransit::kInvalidEndpointId); |
| 33 channel_ = channel; |
| 34 local_id_ = local_id; |
| 35 } |
| 36 |
| 37 void ChannelEndpoint::Run(MessageInTransit::EndpointId remote_id) { |
| 38 DCHECK_NE(remote_id, MessageInTransit::kInvalidEndpointId); |
| 39 |
| 40 base::AutoLock locker(lock_); |
25 DCHECK(channel_); | 41 DCHECK(channel_); |
26 DCHECK_NE(local_id_, MessageInTransit::kInvalidEndpointId); | 42 DCHECK_EQ(remote_id_, MessageInTransit::kInvalidEndpointId); |
| 43 remote_id_ = remote_id; |
27 } | 44 } |
28 | 45 |
29 void ChannelEndpoint::DetachFromChannel() { | 46 void ChannelEndpoint::DetachFromChannel() { |
30 base::AutoLock locker(lock_); | 47 base::AutoLock locker(lock_); |
31 DCHECK(channel_); | 48 DCHECK(channel_); |
| 49 DCHECK_NE(local_id_, MessageInTransit::kInvalidEndpointId); |
| 50 // TODO(vtl): Once we combine "run" into "attach", |remote_id_| should valid |
| 51 // here as well. |
32 channel_ = NULL; | 52 channel_ = NULL; |
| 53 local_id_ = MessageInTransit::kInvalidEndpointId; |
| 54 remote_id_ = MessageInTransit::kInvalidEndpointId; |
33 } | 55 } |
34 | 56 |
35 ChannelEndpoint::~ChannelEndpoint() { | 57 ChannelEndpoint::~ChannelEndpoint() { |
36 DCHECK(!channel_); | 58 DCHECK(!channel_); |
| 59 DCHECK_EQ(local_id_, MessageInTransit::kInvalidEndpointId); |
| 60 DCHECK_EQ(remote_id_, MessageInTransit::kInvalidEndpointId); |
37 } | 61 } |
38 | 62 |
39 } // namespace system | 63 } // namespace system |
40 } // namespace mojo | 64 } // namespace mojo |
OLD | NEW |