Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: mojo/system/channel.cc

Issue 591573002: Mojo: Remove Channel::AttachMessagePipeEndpoint(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/system/channel.h ('k') | mojo/system/channel_endpoint.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 // directly to this function, which wouldn't be sufficient for safety. 98 // directly to this function, which wouldn't be sufficient for safety.
99 MessageInTransit::EndpointId Channel::AttachEndpoint( 99 MessageInTransit::EndpointId Channel::AttachEndpoint(
100 scoped_refptr<ChannelEndpoint> endpoint) { 100 scoped_refptr<ChannelEndpoint> endpoint) {
101 DCHECK(endpoint.get()); 101 DCHECK(endpoint.get());
102 102
103 MessageInTransit::EndpointId local_id; 103 MessageInTransit::EndpointId local_id;
104 { 104 {
105 base::AutoLock locker(lock_); 105 base::AutoLock locker(lock_);
106 106
107 DLOG_IF(WARNING, is_shutting_down_) 107 DLOG_IF(WARNING, is_shutting_down_)
108 << "AttachMessagePipeEndpoint() while shutting down"; 108 << "AttachEndpoint() while shutting down";
109 109
110 while (next_local_id_ == MessageInTransit::kInvalidEndpointId || 110 while (next_local_id_ == MessageInTransit::kInvalidEndpointId ||
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 // This might fail if that port got an |OnPeerClose()| before attaching.
122 if (endpoint->message_pipe_->Attach(endpoint->port_, endpoint.get())) 122 if (endpoint->message_pipe_->Attach(endpoint->port_, endpoint.get()))
123 return local_id; 123 return local_id;
124 124
125 // Note: If it failed, quite possibly the endpoint info was removed from that 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 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 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). 128 // that it's the one we added (and not some other one that was added since).
129 { 129 {
130 base::AutoLock locker(lock_); 130 base::AutoLock locker(lock_);
131 IdToEndpointMap::iterator it = local_id_to_endpoint_map_.find(local_id); 131 IdToEndpointMap::iterator it = local_id_to_endpoint_map_.find(local_id);
132 if (it != local_id_to_endpoint_map_.end() && 132 if (it != local_id_to_endpoint_map_.end() &&
133 it->second->message_pipe_.get() == endpoint->message_pipe_.get() && 133 it->second->message_pipe_.get() == endpoint->message_pipe_.get() &&
134 it->second->port_ == endpoint->port_) { 134 it->second->port_ == endpoint->port_) {
135 DCHECK_EQ(it->second->state_, ChannelEndpoint::STATE_NORMAL); 135 DCHECK_EQ(it->second->state_, ChannelEndpoint::STATE_NORMAL);
136 // TODO(vtl): FIXME -- This is wrong. We need to specify (to 136 // TODO(vtl): FIXME -- This is wrong. We need to specify (to
137 // |AttachMessagePipeEndpoint()| who's going to be responsible for calling 137 // |AttachEndpoint()| who's going to be responsible for calling
138 // |RunMessagePipeEndpoint()| ("us", or the remote by sending us a 138 // |RunMessagePipeEndpoint()| ("us", or the remote by sending us a
139 // |kSubtypeChannelRunMessagePipeEndpoint|). If the remote is going to 139 // |kSubtypeChannelRunMessagePipeEndpoint|). If the remote is going to
140 // run, then we'll get messages to an "invalid" local ID (for running, for 140 // run, then we'll get messages to an "invalid" local ID (for running, for
141 // removal). 141 // removal).
142 local_id_to_endpoint_map_.erase(it); 142 local_id_to_endpoint_map_.erase(it);
143 } 143 }
144 } 144 }
145 endpoint->DetachFromChannel(); 145 endpoint->DetachFromChannel();
146 return MessageInTransit::kInvalidEndpointId; 146 return MessageInTransit::kInvalidEndpointId;
147 } 147 }
148 148
149 MessageInTransit::EndpointId Channel::AttachMessagePipeEndpoint(
150 scoped_refptr<MessagePipe> message_pipe,
151 unsigned port) {
152 DCHECK(message_pipe.get());
153 DCHECK(port == 0 || port == 1);
154
155 return AttachEndpoint(
156 make_scoped_refptr(new ChannelEndpoint(message_pipe.get(), port)));
157 }
158
159 bool Channel::RunMessagePipeEndpoint(MessageInTransit::EndpointId local_id, 149 bool Channel::RunMessagePipeEndpoint(MessageInTransit::EndpointId local_id,
160 MessageInTransit::EndpointId remote_id) { 150 MessageInTransit::EndpointId remote_id) {
161 scoped_refptr<ChannelEndpoint> endpoint; 151 scoped_refptr<ChannelEndpoint> endpoint;
162 ChannelEndpoint::State state; 152 ChannelEndpoint::State state;
163 scoped_refptr<MessagePipe> message_pipe; 153 scoped_refptr<MessagePipe> message_pipe;
164 unsigned port; 154 unsigned port;
165 { 155 {
166 base::AutoLock locker(lock_); 156 base::AutoLock locker(lock_);
167 157
168 DLOG_IF(WARNING, is_shutting_down_) 158 DLOG_IF(WARNING, is_shutting_down_)
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 // TODO(vtl): Is this how we really want to handle this? 551 // TODO(vtl): Is this how we really want to handle this?
562 // Sometimes we'll want to propagate the error back to the message pipe 552 // Sometimes we'll want to propagate the error back to the message pipe
563 // (endpoint), and notify it that the remote is (effectively) closed. 553 // (endpoint), and notify it that the remote is (effectively) closed.
564 // Sometimes we'll want to kill the channel (and notify all the endpoints that 554 // Sometimes we'll want to kill the channel (and notify all the endpoints that
565 // their remotes are dead. 555 // their remotes are dead.
566 LOG(WARNING) << error_message; 556 LOG(WARNING) << error_message;
567 } 557 }
568 558
569 } // namespace system 559 } // namespace system
570 } // namespace mojo 560 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/system/channel.h ('k') | mojo/system/channel_endpoint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698