| 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> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "mojo/edk/system/channel_endpoint.h" | 10 #include "mojo/edk/system/channel_endpoint.h" |
| 9 #include "mojo/edk/system/message_in_transit.h" | 11 #include "mojo/edk/system/message_in_transit.h" |
| 10 | 12 |
| 11 namespace mojo { | 13 namespace mojo { |
| 12 namespace system { | 14 namespace system { |
| 13 | 15 |
| 14 EndpointRelayer::EndpointRelayer() { | 16 EndpointRelayer::EndpointRelayer() { |
| 15 } | 17 } |
| 16 | 18 |
| 17 // static | 19 // static |
| 18 unsigned EndpointRelayer::GetPeerPort(unsigned port) { | 20 unsigned EndpointRelayer::GetPeerPort(unsigned port) { |
| 19 DCHECK(port == 0 || port == 1); | 21 DCHECK(port == 0 || port == 1); |
| 20 return port ^ 1; | 22 return port ^ 1; |
| 21 } | 23 } |
| 22 | 24 |
| 23 void EndpointRelayer::Init(ChannelEndpoint* endpoint0, | 25 void EndpointRelayer::Init(ChannelEndpoint* endpoint0, |
| 24 ChannelEndpoint* endpoint1) { | 26 ChannelEndpoint* endpoint1) { |
| 25 DCHECK(endpoint0); | 27 DCHECK(endpoint0); |
| 26 DCHECK(endpoint1); | 28 DCHECK(endpoint1); |
| 27 DCHECK(!endpoints_[0]); | 29 DCHECK(!endpoints_[0]); |
| 28 DCHECK(!endpoints_[1]); | 30 DCHECK(!endpoints_[1]); |
| 29 endpoints_[0] = endpoint0; | 31 endpoints_[0] = endpoint0; |
| 30 endpoints_[1] = endpoint1; | 32 endpoints_[1] = endpoint1; |
| 31 } | 33 } |
| 32 | 34 |
| 33 void EndpointRelayer::SetFilter(scoped_ptr<Filter> filter) { | 35 void EndpointRelayer::SetFilter(std::unique_ptr<Filter> filter) { |
| 34 MutexLocker locker(&mutex_); | 36 MutexLocker locker(&mutex_); |
| 35 filter_ = filter.Pass(); | 37 filter_ = std::move(filter); |
| 36 } | 38 } |
| 37 | 39 |
| 38 bool EndpointRelayer::OnReadMessage(unsigned port, MessageInTransit* message) { | 40 bool EndpointRelayer::OnReadMessage(unsigned port, MessageInTransit* message) { |
| 39 DCHECK(message); | 41 DCHECK(message); |
| 40 | 42 |
| 41 MutexLocker locker(&mutex_); | 43 MutexLocker locker(&mutex_); |
| 42 | 44 |
| 43 // If we're no longer the client, then reject the message. | 45 // If we're no longer the client, then reject the message. |
| 44 if (!endpoints_[port]) | 46 if (!endpoints_[port]) |
| 45 return false; | 47 return false; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 | 77 |
| 76 EndpointRelayer::~EndpointRelayer() { | 78 EndpointRelayer::~EndpointRelayer() { |
| 77 DCHECK(!endpoints_[0]); | 79 DCHECK(!endpoints_[0]); |
| 78 DCHECK(!endpoints_[1]); | 80 DCHECK(!endpoints_[1]); |
| 79 } | 81 } |
| 80 | 82 |
| 81 } // namespace system | 83 } // namespace system |
| 82 } // namespace mojo | 84 } // namespace mojo |
| OLD | NEW |