| 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/edk/system/endpoint_relayer.h" | 5 #include "mojo/edk/system/endpoint_relayer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "mojo/edk/system/channel_endpoint.h" | 10 #include "mojo/edk/system/channel_endpoint.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 | 48 |
| 49 unsigned peer_port = GetPeerPort(port); | 49 unsigned peer_port = GetPeerPort(port); |
| 50 | 50 |
| 51 if (filter_ && message->type() == MessageInTransit::Type::ENDPOINT_CLIENT) { | 51 if (filter_ && message->type() == MessageInTransit::Type::ENDPOINT_CLIENT) { |
| 52 if (filter_->OnReadMessage(endpoints_[port].get(), | 52 if (filter_->OnReadMessage(endpoints_[port].get(), |
| 53 endpoints_[peer_port].get(), message)) | 53 endpoints_[peer_port].get(), message)) |
| 54 return true; | 54 return true; |
| 55 } | 55 } |
| 56 | 56 |
| 57 // Otherwise, consume it even if the peer port is closed. | 57 // Otherwise, consume it even if the peer port is closed. |
| 58 if (endpoints_[peer_port]) | 58 if (endpoints_[peer_port]) { |
| 59 endpoints_[peer_port]->EnqueueMessage(make_scoped_ptr(message)); | 59 endpoints_[peer_port]->EnqueueMessage( |
| 60 std::unique_ptr<MessageInTransit>(message)); |
| 61 } |
| 60 return true; | 62 return true; |
| 61 } | 63 } |
| 62 | 64 |
| 63 void EndpointRelayer::OnDetachFromChannel(unsigned port) { | 65 void EndpointRelayer::OnDetachFromChannel(unsigned port) { |
| 64 MutexLocker locker(&mutex_); | 66 MutexLocker locker(&mutex_); |
| 65 | 67 |
| 66 if (endpoints_[port]) { | 68 if (endpoints_[port]) { |
| 67 endpoints_[port]->DetachFromClient(); | 69 endpoints_[port]->DetachFromClient(); |
| 68 endpoints_[port] = nullptr; | 70 endpoints_[port] = nullptr; |
| 69 } | 71 } |
| 70 | 72 |
| 71 unsigned peer_port = GetPeerPort(port); | 73 unsigned peer_port = GetPeerPort(port); |
| 72 if (endpoints_[peer_port]) { | 74 if (endpoints_[peer_port]) { |
| 73 endpoints_[peer_port]->DetachFromClient(); | 75 endpoints_[peer_port]->DetachFromClient(); |
| 74 endpoints_[peer_port] = nullptr; | 76 endpoints_[peer_port] = nullptr; |
| 75 } | 77 } |
| 76 } | 78 } |
| 77 | 79 |
| 78 EndpointRelayer::~EndpointRelayer() { | 80 EndpointRelayer::~EndpointRelayer() { |
| 79 DCHECK(!endpoints_[0]); | 81 DCHECK(!endpoints_[0]); |
| 80 DCHECK(!endpoints_[1]); | 82 DCHECK(!endpoints_[1]); |
| 81 } | 83 } |
| 82 | 84 |
| 83 } // namespace system | 85 } // namespace system |
| 84 } // namespace mojo | 86 } // namespace mojo |
| OLD | NEW |