| 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 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 next_local_id_++; | 112 next_local_id_++; |
| 113 | 113 |
| 114 local_id = next_local_id_; | 114 local_id = next_local_id_; |
| 115 next_local_id_++; | 115 next_local_id_++; |
| 116 endpoint = new ChannelEndpoint(message_pipe.get(), port); | 116 endpoint = new ChannelEndpoint(message_pipe.get(), port); |
| 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 (message_pipe->Attach(port, endpoint.get(), this, local_id)) | 122 if (message_pipe->Attach(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() && |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 if (state != ChannelEndpoint::STATE_NORMAL) { | 173 if (state != ChannelEndpoint::STATE_NORMAL) { |
| 174 DVLOG(2) << "Ignoring run message pipe endpoint for zombie endpoint " | 174 DVLOG(2) << "Ignoring run message pipe endpoint for zombie endpoint " |
| 175 "(local ID " << local_id << ", remote ID " << remote_id << ")"; | 175 "(local ID " << local_id << ", remote ID " << remote_id << ")"; |
| 176 return true; | 176 return true; |
| 177 } | 177 } |
| 178 | 178 |
| 179 // TODO(vtl): FIXME -- We need to handle the case that message pipe is already | 179 // TODO(vtl): FIXME -- We need to handle the case that message pipe is already |
| 180 // running when we're here due to |kSubtypeChannelRunMessagePipeEndpoint|). | 180 // running when we're here due to |kSubtypeChannelRunMessagePipeEndpoint|). |
| 181 endpoint->Run(remote_id); | 181 endpoint->Run(remote_id); |
| 182 // TODO(vtl): Get rid of this. | 182 // TODO(vtl): Get rid of this. |
| 183 message_pipe->Run(port, remote_id); | 183 message_pipe->Run(port); |
| 184 return true; | 184 return true; |
| 185 } | 185 } |
| 186 | 186 |
| 187 void Channel::RunRemoteMessagePipeEndpoint( | 187 void Channel::RunRemoteMessagePipeEndpoint( |
| 188 MessageInTransit::EndpointId local_id, | 188 MessageInTransit::EndpointId local_id, |
| 189 MessageInTransit::EndpointId remote_id) { | 189 MessageInTransit::EndpointId remote_id) { |
| 190 #if DCHECK_IS_ON | 190 #if DCHECK_IS_ON |
| 191 { | 191 { |
| 192 base::AutoLock locker(lock_); | 192 base::AutoLock locker(lock_); |
| 193 DCHECK(local_id_to_endpoint_map_.find(local_id) != | 193 DCHECK(local_id_to_endpoint_map_.find(local_id) != |
| (...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 // TODO(vtl): Is this how we really want to handle this? | 551 // 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 | 552 // Sometimes we'll want to propagate the error back to the message pipe |
| 553 // (endpoint), and notify it that the remote is (effectively) closed. | 553 // (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 | 554 // Sometimes we'll want to kill the channel (and notify all the endpoints that |
| 555 // their remotes are dead. | 555 // their remotes are dead. |
| 556 LOG(WARNING) << error_message; | 556 LOG(WARNING) << error_message; |
| 557 } | 557 } |
| 558 | 558 |
| 559 } // namespace system | 559 } // namespace system |
| 560 } // namespace mojo | 560 } // namespace mojo |
| OLD | NEW |