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 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ |
7 | 7 |
| 8 #include <utility> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" | 11 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" |
10 | 12 |
11 namespace mojo { | 13 namespace mojo { |
12 | 14 |
13 namespace internal { | 15 namespace internal { |
14 class AssociatedInterfacePtrInfoHelper; | 16 class AssociatedInterfacePtrInfoHelper; |
15 } | 17 } |
16 | 18 |
17 // AssociatedInterfacePtrInfo stores necessary information to construct an | 19 // AssociatedInterfacePtrInfo stores necessary information to construct an |
18 // associated interface pointer. It is similar to InterfacePtrInfo except that | 20 // associated interface pointer. It is similar to InterfacePtrInfo except that |
19 // it doesn't own a message pipe handle. | 21 // it doesn't own a message pipe handle. |
20 template <typename Interface> | 22 template <typename Interface> |
21 class AssociatedInterfacePtrInfo { | 23 class AssociatedInterfacePtrInfo { |
22 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtrInfo); | 24 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(AssociatedInterfacePtrInfo); |
23 | 25 |
24 public: | 26 public: |
25 AssociatedInterfacePtrInfo() : version_(0u) {} | 27 AssociatedInterfacePtrInfo() : version_(0u) {} |
26 | 28 |
27 AssociatedInterfacePtrInfo(AssociatedInterfacePtrInfo&& other) | 29 AssociatedInterfacePtrInfo(AssociatedInterfacePtrInfo&& other) |
28 : handle_(other.handle_.Pass()), version_(other.version_) { | 30 : handle_(std::move(other.handle_)), version_(other.version_) { |
29 other.version_ = 0u; | 31 other.version_ = 0u; |
30 } | 32 } |
31 | 33 |
32 ~AssociatedInterfacePtrInfo() {} | 34 ~AssociatedInterfacePtrInfo() {} |
33 | 35 |
34 AssociatedInterfacePtrInfo& operator=(AssociatedInterfacePtrInfo&& other) { | 36 AssociatedInterfacePtrInfo& operator=(AssociatedInterfacePtrInfo&& other) { |
35 if (this != &other) { | 37 if (this != &other) { |
36 handle_ = other.handle_.Pass(); | 38 handle_ = std::move(other.handle_); |
37 version_ = other.version_; | 39 version_ = other.version_; |
38 other.version_ = 0u; | 40 other.version_ = 0u; |
39 } | 41 } |
40 | 42 |
41 return *this; | 43 return *this; |
42 } | 44 } |
43 | 45 |
44 bool is_valid() const { return handle_.is_valid(); } | 46 bool is_valid() const { return handle_.is_valid(); } |
45 | 47 |
46 uint32_t version() const { return version_; } | 48 uint32_t version() const { return version_; } |
47 void set_version(uint32_t version) { version_ = version; } | 49 void set_version(uint32_t version) { version_ = version; } |
48 | 50 |
49 private: | 51 private: |
50 friend class internal::AssociatedInterfacePtrInfoHelper; | 52 friend class internal::AssociatedInterfacePtrInfoHelper; |
51 | 53 |
52 internal::ScopedInterfaceEndpointHandle handle_; | 54 internal::ScopedInterfaceEndpointHandle handle_; |
53 uint32_t version_; | 55 uint32_t version_; |
54 }; | 56 }; |
55 | 57 |
56 namespace internal { | 58 namespace internal { |
57 | 59 |
58 // With this helper, AssociatedInterfacePtrInfo doesn't have to expose any | 60 // With this helper, AssociatedInterfacePtrInfo doesn't have to expose any |
59 // operations related to ScopedInterfaceEndpointHandle, which is an internal | 61 // operations related to ScopedInterfaceEndpointHandle, which is an internal |
60 // class. | 62 // class. |
61 class AssociatedInterfacePtrInfoHelper { | 63 class AssociatedInterfacePtrInfoHelper { |
62 public: | 64 public: |
63 template <typename Interface> | 65 template <typename Interface> |
64 static ScopedInterfaceEndpointHandle PassHandle( | 66 static ScopedInterfaceEndpointHandle PassHandle( |
65 AssociatedInterfacePtrInfo<Interface>* info) { | 67 AssociatedInterfacePtrInfo<Interface>* info) { |
66 return info->handle_.Pass(); | 68 return std::move(info->handle_); |
67 } | 69 } |
68 | 70 |
69 template <typename Interface> | 71 template <typename Interface> |
70 static const ScopedInterfaceEndpointHandle& GetHandle( | 72 static const ScopedInterfaceEndpointHandle& GetHandle( |
71 AssociatedInterfacePtrInfo<Interface>* info) { | 73 AssociatedInterfacePtrInfo<Interface>* info) { |
72 return info->handle_; | 74 return info->handle_; |
73 } | 75 } |
74 | 76 |
75 template <typename Interface> | 77 template <typename Interface> |
76 static void SetHandle(AssociatedInterfacePtrInfo<Interface>* info, | 78 static void SetHandle(AssociatedInterfacePtrInfo<Interface>* info, |
77 ScopedInterfaceEndpointHandle handle) { | 79 ScopedInterfaceEndpointHandle handle) { |
78 info->handle_ = handle.Pass(); | 80 info->handle_ = std::move(handle); |
79 } | 81 } |
80 }; | 82 }; |
81 | 83 |
82 } // namespace internal | 84 } // namespace internal |
83 } // namespace mojo | 85 } // namespace mojo |
84 | 86 |
85 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ | 87 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_INFO_H_ |
OLD | NEW |