| 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_INTERFACE_PTR_INFO_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "mojo/public/cpp/system/message_pipe.h" | 12 #include "mojo/public/cpp/system/message_pipe.h" |
| 13 | 13 |
| 14 namespace mojo { | 14 namespace mojo { |
| 15 | 15 |
| 16 // InterfacePtrInfo stores necessary information to communicate with a remote | 16 // InterfacePtrInfo stores necessary information to communicate with a remote |
| 17 // interface implementation, which could be used to construct an InterfacePtr. | 17 // interface implementation, which could be used to construct an InterfacePtr. |
| 18 template <typename Interface> | 18 class InterfacePtrInfoBase { |
| 19 class InterfacePtrInfo { | |
| 20 public: | 19 public: |
| 21 InterfacePtrInfo() : version_(0u) {} | 20 InterfacePtrInfoBase(); |
| 22 | 21 |
| 23 InterfacePtrInfo(ScopedMessagePipeHandle handle, uint32_t version) | 22 InterfacePtrInfoBase(ScopedMessagePipeHandle handle, uint32_t version); |
| 24 : handle_(std::move(handle)), version_(version) {} | |
| 25 | 23 |
| 26 InterfacePtrInfo(InterfacePtrInfo&& other) | 24 InterfacePtrInfoBase(InterfacePtrInfoBase&& other); |
| 27 : handle_(std::move(other.handle_)), version_(other.version_) { | |
| 28 other.version_ = 0u; | |
| 29 } | |
| 30 | 25 |
| 31 ~InterfacePtrInfo() {} | 26 ~InterfacePtrInfoBase(); |
| 32 | 27 |
| 33 InterfacePtrInfo& operator=(InterfacePtrInfo&& other) { | 28 InterfacePtrInfoBase& operator=(InterfacePtrInfoBase&& other); |
| 34 if (this != &other) { | |
| 35 handle_ = std::move(other.handle_); | |
| 36 version_ = other.version_; | |
| 37 other.version_ = 0u; | |
| 38 } | |
| 39 | |
| 40 return *this; | |
| 41 } | |
| 42 | 29 |
| 43 bool is_valid() const { return handle_.is_valid(); } | 30 bool is_valid() const { return handle_.is_valid(); } |
| 44 | 31 |
| 45 ScopedMessagePipeHandle PassHandle() { return std::move(handle_); } | 32 ScopedMessagePipeHandle PassHandle() { return std::move(handle_); } |
| 46 const ScopedMessagePipeHandle& handle() const { return handle_; } | 33 const ScopedMessagePipeHandle& handle() const { return handle_; } |
| 47 void set_handle(ScopedMessagePipeHandle handle) { | 34 void set_handle(ScopedMessagePipeHandle handle) { |
| 48 handle_ = std::move(handle); | 35 handle_ = std::move(handle); |
| 49 } | 36 } |
| 50 | 37 |
| 51 uint32_t version() const { return version_; } | 38 uint32_t version() const { return version_; } |
| 52 void set_version(uint32_t version) { version_ = version; } | 39 void set_version(uint32_t version) { version_ = version; } |
| 53 | 40 |
| 54 private: | 41 private: |
| 55 ScopedMessagePipeHandle handle_; | 42 ScopedMessagePipeHandle handle_; |
| 56 uint32_t version_; | 43 uint32_t version_; |
| 57 | 44 |
| 58 DISALLOW_COPY_AND_ASSIGN(InterfacePtrInfo); | 45 DISALLOW_COPY_AND_ASSIGN(InterfacePtrInfoBase); |
| 46 }; |
| 47 |
| 48 template <typename Interface> |
| 49 class InterfacePtrInfo : public InterfacePtrInfoBase { |
| 50 using InterfacePtrInfoBase::InterfacePtrInfoBase; |
| 59 }; | 51 }; |
| 60 | 52 |
| 61 } // namespace mojo | 53 } // namespace mojo |
| 62 | 54 |
| 63 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_ | 55 #endif // MOJO_PUBLIC_CPP_BINDINGS_INTERFACE_PTR_INFO_H_ |
| OLD | NEW |