| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" | 5 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 8 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| 11 namespace internal { | |
| 12 | 11 |
| 13 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle() | 12 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle() |
| 14 : ScopedInterfaceEndpointHandle(kInvalidInterfaceId, true, nullptr) {} | 13 : ScopedInterfaceEndpointHandle(internal::kInvalidInterfaceId, true, |
| 14 nullptr) {} |
| 15 | 15 |
| 16 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( | 16 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( |
| 17 InterfaceId id, | 17 internal::InterfaceId id, |
| 18 bool is_local, | 18 bool is_local, |
| 19 scoped_refptr<MultiplexRouter> router) | 19 scoped_refptr<internal::MultiplexRouter> router) |
| 20 : id_(id), is_local_(is_local), router_(std::move(router)) { | 20 : id_(id), is_local_(is_local), router_(std::move(router)) { |
| 21 DCHECK(!IsValidInterfaceId(id) || router_); | 21 DCHECK(!internal::IsValidInterfaceId(id) || router_); |
| 22 } | 22 } |
| 23 | 23 |
| 24 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( | 24 ScopedInterfaceEndpointHandle::ScopedInterfaceEndpointHandle( |
| 25 ScopedInterfaceEndpointHandle&& other) | 25 ScopedInterfaceEndpointHandle&& other) |
| 26 : id_(other.id_), is_local_(other.is_local_) { | 26 : id_(other.id_), is_local_(other.is_local_) { |
| 27 router_.swap(other.router_); | 27 router_.swap(other.router_); |
| 28 other.id_ = kInvalidInterfaceId; | 28 other.id_ = internal::kInvalidInterfaceId; |
| 29 } | 29 } |
| 30 | 30 |
| 31 ScopedInterfaceEndpointHandle::~ScopedInterfaceEndpointHandle() { | 31 ScopedInterfaceEndpointHandle::~ScopedInterfaceEndpointHandle() { |
| 32 reset(); | 32 reset(); |
| 33 } | 33 } |
| 34 | 34 |
| 35 ScopedInterfaceEndpointHandle& ScopedInterfaceEndpointHandle::operator=( | 35 ScopedInterfaceEndpointHandle& ScopedInterfaceEndpointHandle::operator=( |
| 36 ScopedInterfaceEndpointHandle&& other) { | 36 ScopedInterfaceEndpointHandle&& other) { |
| 37 reset(); | 37 reset(); |
| 38 swap(other); | 38 swap(other); |
| 39 | 39 |
| 40 return *this; | 40 return *this; |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ScopedInterfaceEndpointHandle::reset() { | 43 void ScopedInterfaceEndpointHandle::reset() { |
| 44 if (!IsValidInterfaceId(id_)) | 44 if (!internal::IsValidInterfaceId(id_)) |
| 45 return; | 45 return; |
| 46 | 46 |
| 47 router_->CloseEndpointHandle(id_, is_local_); | 47 router_->CloseEndpointHandle(id_, is_local_); |
| 48 | 48 |
| 49 id_ = kInvalidInterfaceId; | 49 id_ = internal::kInvalidInterfaceId; |
| 50 is_local_ = true; | 50 is_local_ = true; |
| 51 router_ = nullptr; | 51 router_ = nullptr; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ScopedInterfaceEndpointHandle::swap(ScopedInterfaceEndpointHandle& other) { | 54 void ScopedInterfaceEndpointHandle::swap(ScopedInterfaceEndpointHandle& other) { |
| 55 using std::swap; | 55 using std::swap; |
| 56 swap(other.id_, id_); | 56 swap(other.id_, id_); |
| 57 swap(other.is_local_, is_local_); | 57 swap(other.is_local_, is_local_); |
| 58 swap(other.router_, router_); | 58 swap(other.router_, router_); |
| 59 } | 59 } |
| 60 | 60 |
| 61 InterfaceId ScopedInterfaceEndpointHandle::release() { | 61 internal::InterfaceId ScopedInterfaceEndpointHandle::release() { |
| 62 InterfaceId result = id_; | 62 internal::InterfaceId result = id_; |
| 63 | 63 |
| 64 id_ = kInvalidInterfaceId; | 64 id_ = internal::kInvalidInterfaceId; |
| 65 is_local_ = true; | 65 is_local_ = true; |
| 66 router_ = nullptr; | 66 router_ = nullptr; |
| 67 | 67 |
| 68 return result; | 68 return result; |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace internal | |
| 72 } // namespace mojo | 71 } // namespace mojo |
| OLD | NEW |