| 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/edk/system/channel.h" | 5 #include "mojo/edk/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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 raw_channel_->Shutdown(); | 65 raw_channel_->Shutdown(); |
| 66 is_running_ = false; | 66 is_running_ = false; |
| 67 | 67 |
| 68 // We need to deal with it outside the lock. | 68 // We need to deal with it outside the lock. |
| 69 std::swap(to_destroy, local_id_to_endpoint_map_); | 69 std::swap(to_destroy, local_id_to_endpoint_map_); |
| 70 } | 70 } |
| 71 | 71 |
| 72 size_t num_live = 0; | 72 size_t num_live = 0; |
| 73 size_t num_zombies = 0; | 73 size_t num_zombies = 0; |
| 74 for (IdToEndpointMap::iterator it = to_destroy.begin(); | 74 for (IdToEndpointMap::iterator it = to_destroy.begin(); |
| 75 it != to_destroy.end(); | 75 it != to_destroy.end(); ++it) { |
| 76 ++it) { | |
| 77 if (it->second.get()) { | 76 if (it->second.get()) { |
| 78 num_live++; | 77 num_live++; |
| 79 it->second->OnDisconnect(); | 78 it->second->OnDisconnect(); |
| 80 it->second->DetachFromChannel(); | 79 it->second->DetachFromChannel(); |
| 81 } else { | 80 } else { |
| 82 num_zombies++; | 81 num_zombies++; |
| 83 } | 82 } |
| 84 } | 83 } |
| 85 DVLOG_IF(2, num_live || num_zombies) << "Shut down Channel with " << num_live | 84 DVLOG_IF(2, num_live || num_zombies) << "Shut down Channel with " << num_live |
| 86 << " live endpoints and " << num_zombies | 85 << " live endpoints and " << num_zombies |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 | 123 |
| 125 // TODO(vtl): We also need to check for collisions of remote IDs here. | 124 // TODO(vtl): We also need to check for collisions of remote IDs here. |
| 126 remote_id = remote_id_generator_.GetNext(); | 125 remote_id = remote_id_generator_.GetNext(); |
| 127 } | 126 } |
| 128 | 127 |
| 129 local_id_to_endpoint_map_[local_id] = endpoint; | 128 local_id_to_endpoint_map_[local_id] = endpoint; |
| 130 } | 129 } |
| 131 | 130 |
| 132 if (!is_bootstrap) { | 131 if (!is_bootstrap) { |
| 133 if (!SendControlMessage( | 132 if (!SendControlMessage( |
| 134 MessageInTransit::kSubtypeChannelAttachAndRunEndpoint, | 133 MessageInTransit::kSubtypeChannelAttachAndRunEndpoint, local_id, |
| 135 local_id, | |
| 136 remote_id)) { | 134 remote_id)) { |
| 137 HandleLocalError(base::StringPrintf( | 135 HandleLocalError(base::StringPrintf( |
| 138 "Failed to send message to run remote message pipe endpoint (local " | 136 "Failed to send message to run remote message pipe endpoint (local " |
| 139 "ID %u, remote ID %u)", | 137 "ID %u, remote ID %u)", |
| 140 static_cast<unsigned>(local_id.value()), | 138 static_cast<unsigned>(local_id.value()), |
| 141 static_cast<unsigned>(remote_id.value()))); | 139 static_cast<unsigned>(remote_id.value()))); |
| 142 // TODO(vtl): Should we continue on to |AttachAndRun()|? | 140 // TODO(vtl): Should we continue on to |AttachAndRun()|? |
| 143 } | 141 } |
| 144 } | 142 } |
| 145 | 143 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 if (it == local_id_to_endpoint_map_.end() || it->second.get() != endpoint) | 187 if (it == local_id_to_endpoint_map_.end() || it->second.get() != endpoint) |
| 190 return; | 188 return; |
| 191 | 189 |
| 192 DCHECK(it->second.get()); | 190 DCHECK(it->second.get()); |
| 193 it->second = nullptr; | 191 it->second = nullptr; |
| 194 | 192 |
| 195 // Send a remove message outside the lock. | 193 // Send a remove message outside the lock. |
| 196 } | 194 } |
| 197 | 195 |
| 198 if (!SendControlMessage( | 196 if (!SendControlMessage( |
| 199 MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpoint, | 197 MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpoint, local_id, |
| 200 local_id, | |
| 201 remote_id)) { | 198 remote_id)) { |
| 202 HandleLocalError(base::StringPrintf( | 199 HandleLocalError(base::StringPrintf( |
| 203 "Failed to send message to remove remote message pipe endpoint (local " | 200 "Failed to send message to remove remote message pipe endpoint (local " |
| 204 "ID %u, remote ID %u)", | 201 "ID %u, remote ID %u)", |
| 205 static_cast<unsigned>(local_id.value()), | 202 static_cast<unsigned>(local_id.value()), |
| 206 static_cast<unsigned>(remote_id.value()))); | 203 static_cast<unsigned>(remote_id.value()))); |
| 207 } | 204 } |
| 208 } | 205 } |
| 209 | 206 |
| 210 scoped_refptr<MessagePipe> Channel::PassIncomingMessagePipe( | 207 scoped_refptr<MessagePipe> Channel::PassIncomingMessagePipe( |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 | 460 |
| 464 endpoint = it->second; | 461 endpoint = it->second; |
| 465 local_id_to_endpoint_map_.erase(it); | 462 local_id_to_endpoint_map_.erase(it); |
| 466 // Detach and send the remove ack message outside the lock. | 463 // Detach and send the remove ack message outside the lock. |
| 467 } | 464 } |
| 468 | 465 |
| 469 endpoint->DetachFromChannel(); | 466 endpoint->DetachFromChannel(); |
| 470 | 467 |
| 471 if (!SendControlMessage( | 468 if (!SendControlMessage( |
| 472 MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpointAck, | 469 MessageInTransit::kSubtypeChannelRemoveMessagePipeEndpointAck, |
| 473 local_id, | 470 local_id, remote_id)) { |
| 474 remote_id)) { | |
| 475 HandleLocalError(base::StringPrintf( | 471 HandleLocalError(base::StringPrintf( |
| 476 "Failed to send message to remove remote message pipe endpoint ack " | 472 "Failed to send message to remove remote message pipe endpoint ack " |
| 477 "(local ID %u, remote ID %u)", | 473 "(local ID %u, remote ID %u)", |
| 478 static_cast<unsigned>(local_id.value()), | 474 static_cast<unsigned>(local_id.value()), |
| 479 static_cast<unsigned>(remote_id.value()))); | 475 static_cast<unsigned>(remote_id.value()))); |
| 480 } | 476 } |
| 481 | 477 |
| 482 endpoint->OnDisconnect(); | 478 endpoint->OnDisconnect(); |
| 483 return true; | 479 return true; |
| 484 } | 480 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 // TODO(vtl): Is this how we really want to handle this? | 521 // TODO(vtl): Is this how we really want to handle this? |
| 526 // Sometimes we'll want to propagate the error back to the message pipe | 522 // Sometimes we'll want to propagate the error back to the message pipe |
| 527 // (endpoint), and notify it that the remote is (effectively) closed. | 523 // (endpoint), and notify it that the remote is (effectively) closed. |
| 528 // Sometimes we'll want to kill the channel (and notify all the endpoints that | 524 // Sometimes we'll want to kill the channel (and notify all the endpoints that |
| 529 // their remotes are dead. | 525 // their remotes are dead. |
| 530 LOG(WARNING) << error_message; | 526 LOG(WARNING) << error_message; |
| 531 } | 527 } |
| 532 | 528 |
| 533 } // namespace system | 529 } // namespace system |
| 534 } // namespace mojo | 530 } // namespace mojo |
| OLD | NEW |