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