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/channel.h" | 5 #include "mojo/system/channel.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 local_id_to_endpoint_map_.find(next_local_id_) != | 111 local_id_to_endpoint_map_.find(next_local_id_) != |
112 local_id_to_endpoint_map_.end()) | 112 local_id_to_endpoint_map_.end()) |
113 next_local_id_++; | 113 next_local_id_++; |
114 | 114 |
115 local_id = next_local_id_; | 115 local_id = next_local_id_; |
116 next_local_id_++; | 116 next_local_id_++; |
117 local_id_to_endpoint_map_[local_id] = endpoint; | 117 local_id_to_endpoint_map_[local_id] = endpoint; |
118 } | 118 } |
119 | 119 |
120 endpoint->AttachToChannel(this, local_id); | 120 endpoint->AttachToChannel(this, local_id); |
121 // This might fail if that port got an |OnPeerClose()| before attaching. | 121 return local_id; |
122 if (endpoint->message_pipe_->Attach(endpoint->port_, endpoint.get())) | |
123 return local_id; | |
124 | |
125 // Note: If it failed, quite possibly the endpoint info was removed from that | |
126 // map (there's a race between us adding it to the map above and calling | |
127 // |Attach()|). And even if an entry exists for |local_id|, we need to check | |
128 // that it's the one we added (and not some other one that was added since). | |
129 { | |
130 base::AutoLock locker(lock_); | |
131 IdToEndpointMap::iterator it = local_id_to_endpoint_map_.find(local_id); | |
132 if (it != local_id_to_endpoint_map_.end() && | |
133 it->second->message_pipe_.get() == endpoint->message_pipe_.get() && | |
134 it->second->port_ == endpoint->port_) { | |
135 DCHECK_EQ(it->second->state_, ChannelEndpoint::STATE_NORMAL); | |
136 // TODO(vtl): FIXME -- This is wrong. We need to specify (to | |
137 // |AttachEndpoint()| who's going to be responsible for calling | |
138 // |RunMessagePipeEndpoint()| ("us", or the remote by sending us a | |
139 // |kSubtypeChannelRunMessagePipeEndpoint|). If the remote is going to | |
140 // run, then we'll get messages to an "invalid" local ID (for running, for | |
141 // removal). | |
142 local_id_to_endpoint_map_.erase(it); | |
143 } | |
144 } | |
145 endpoint->DetachFromChannel(); | |
146 return MessageInTransit::kInvalidEndpointId; | |
147 } | 122 } |
148 | 123 |
149 bool Channel::RunMessagePipeEndpoint(MessageInTransit::EndpointId local_id, | 124 bool Channel::RunMessagePipeEndpoint(MessageInTransit::EndpointId local_id, |
150 MessageInTransit::EndpointId remote_id) { | 125 MessageInTransit::EndpointId remote_id) { |
151 scoped_refptr<ChannelEndpoint> endpoint; | 126 scoped_refptr<ChannelEndpoint> endpoint; |
152 ChannelEndpoint::State state; | 127 ChannelEndpoint::State state; |
153 scoped_refptr<MessagePipe> message_pipe; | 128 scoped_refptr<MessagePipe> message_pipe; |
154 unsigned port; | 129 unsigned port; |
155 { | 130 { |
156 base::AutoLock locker(lock_); | 131 base::AutoLock locker(lock_); |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // TODO(vtl): Is this how we really want to handle this? | 526 // TODO(vtl): Is this how we really want to handle this? |
552 // Sometimes we'll want to propagate the error back to the message pipe | 527 // Sometimes we'll want to propagate the error back to the message pipe |
553 // (endpoint), and notify it that the remote is (effectively) closed. | 528 // (endpoint), and notify it that the remote is (effectively) closed. |
554 // Sometimes we'll want to kill the channel (and notify all the endpoints that | 529 // Sometimes we'll want to kill the channel (and notify all the endpoints that |
555 // their remotes are dead. | 530 // their remotes are dead. |
556 LOG(WARNING) << error_message; | 531 LOG(WARNING) << error_message; |
557 } | 532 } |
558 | 533 |
559 } // namespace system | 534 } // namespace system |
560 } // namespace mojo | 535 } // namespace mojo |
OLD | NEW |