blob: 2a8415e8705301301d173808a2e0db18b21e6071 [file] [log] [blame]
Reilly Grantd175c5e62017-08-30 19:26:581// Copyright 2017 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_COMMON_POSSIBLY_ASSOCIATED_INTERFACE_PTR_INFO_H_
6#define CONTENT_COMMON_POSSIBLY_ASSOCIATED_INTERFACE_PTR_INFO_H_
7
8#include "base/macros.h"
9#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
10#include "mojo/public/cpp/bindings/interface_ptr_info.h"
11
12namespace content {
13
14// PossiblyAssociatedInterfacePtrInfo<T> contains mojo::InterfacePtrInfo<T> or
15// mojo::AssociatedInterfacePtrInfo<T>, but not both. Mojo-related functions in
16// mojo::InterfacePtrInfo<T> and mojo::AssociatedInterfacePtrInfo<T> are not
17// accessible, but a user can Bind this object into a
18// PossiblyAssociatedInterfacePtr.
19template <typename T>
20class PossiblyAssociatedInterfacePtrInfo final {
21 public:
22 PossiblyAssociatedInterfacePtrInfo() {}
23 PossiblyAssociatedInterfacePtrInfo(std::nullptr_t) {}
24 PossiblyAssociatedInterfacePtrInfo(
25 mojo::InterfacePtrInfo<T> independent_ptr_info)
26 : independent_ptr_info_(std::move(independent_ptr_info)) {}
27 PossiblyAssociatedInterfacePtrInfo(
28 mojo::AssociatedInterfacePtrInfo<T> associated_ptr_info)
29 : associated_ptr_info_(std::move(associated_ptr_info)) {}
30
31 PossiblyAssociatedInterfacePtrInfo(
32 PossiblyAssociatedInterfacePtrInfo&& other) = default;
33 ~PossiblyAssociatedInterfacePtrInfo() {}
34
35 PossiblyAssociatedInterfacePtrInfo& operator=(
36 PossiblyAssociatedInterfacePtrInfo&& other) = default;
37
38 mojo::InterfacePtrInfo<T> TakeIndependentPtrInfo() {
39 return std::move(independent_ptr_info_);
40 }
41
42 mojo::AssociatedInterfacePtrInfo<T> TakeAssociatedPtrInfo() {
43 return std::move(associated_ptr_info_);
44 }
45
46 explicit operator bool() const {
47 return independent_ptr_info_.is_valid() || associated_ptr_info_.is_valid();
48 }
49
50 private:
51 mojo::InterfacePtrInfo<T> independent_ptr_info_;
52 mojo::AssociatedInterfacePtrInfo<T> associated_ptr_info_;
53
54 DISALLOW_COPY_AND_ASSIGN(PossiblyAssociatedInterfacePtrInfo);
55};
56
57} // namespace content
58
59#endif // CONTENT_COMMON_POSSIBLY_ASSOCIATED_INTERFACE_PTR_INFO_H_