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_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> // For |std::swap()|. | 10 #include <algorithm> // For |std::swap()|. |
11 #include <memory> | 11 #include <memory> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/callback_forward.h" | |
16 #include "base/macros.h" | 15 #include "base/macros.h" |
17 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
18 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
19 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
20 #include "mojo/public/cpp/bindings/associated_group.h" | 19 #include "mojo/public/cpp/bindings/associated_group.h" |
21 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" | 20 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" |
| 21 #include "mojo/public/cpp/bindings/callback.h" |
22 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" | 22 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" |
23 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" | 23 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" |
24 #include "mojo/public/cpp/bindings/lib/interface_id.h" | 24 #include "mojo/public/cpp/bindings/lib/interface_id.h" |
25 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 25 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
26 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 26 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
27 #include "mojo/public/cpp/system/message_pipe.h" | 27 #include "mojo/public/cpp/system/message_pipe.h" |
28 | 28 |
29 namespace mojo { | 29 namespace mojo { |
30 namespace internal { | 30 namespace internal { |
31 | 31 |
(...skipping 12 matching lines...) Expand all Loading... |
44 return proxy_.get(); | 44 return proxy_.get(); |
45 } | 45 } |
46 | 46 |
47 uint32_t version() const { return version_; } | 47 uint32_t version() const { return version_; } |
48 | 48 |
49 uint32_t interface_id() const { | 49 uint32_t interface_id() const { |
50 DCHECK(is_bound()); | 50 DCHECK(is_bound()); |
51 return endpoint_client_->interface_id(); | 51 return endpoint_client_->interface_id(); |
52 } | 52 } |
53 | 53 |
54 void QueryVersion(const base::Callback<void(uint32_t)>& callback) { | 54 void QueryVersion(const Callback<void(uint32_t)>& callback) { |
55 // Do a static cast in case the interface contains methods with the same | 55 // Do a static cast in case the interface contains methods with the same |
56 // name. It is safe to capture |this| because the callback won't be run | 56 // name. It is safe to capture |this| because the callback won't be run |
57 // after this object goes away. | 57 // after this object goes away. |
58 static_cast<ControlMessageProxy*>(proxy_.get()) | 58 static_cast<ControlMessageProxy*>(proxy_.get()) |
59 ->QueryVersion(base::Bind(&AssociatedInterfacePtrState::OnQueryVersion, | 59 ->QueryVersion(base::Bind(&AssociatedInterfacePtrState::OnQueryVersion, |
60 base::Unretained(this), callback)); | 60 base::Unretained(this), callback)); |
61 } | 61 } |
62 | 62 |
63 void RequireVersion(uint32_t version) { | 63 void RequireVersion(uint32_t version) { |
64 if (version <= version_) | 64 if (version <= version_) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 proxy_.reset(); | 101 proxy_.reset(); |
102 return AssociatedInterfacePtrInfo<Interface>(std::move(handle), version_); | 102 return AssociatedInterfacePtrInfo<Interface>(std::move(handle), version_); |
103 } | 103 } |
104 | 104 |
105 bool is_bound() const { return !!endpoint_client_; } | 105 bool is_bound() const { return !!endpoint_client_; } |
106 | 106 |
107 bool encountered_error() const { | 107 bool encountered_error() const { |
108 return endpoint_client_ ? endpoint_client_->encountered_error() : false; | 108 return endpoint_client_ ? endpoint_client_->encountered_error() : false; |
109 } | 109 } |
110 | 110 |
111 void set_connection_error_handler(const base::Closure& error_handler) { | 111 void set_connection_error_handler(const Closure& error_handler) { |
112 DCHECK(endpoint_client_); | 112 DCHECK(endpoint_client_); |
113 endpoint_client_->set_connection_error_handler(error_handler); | 113 endpoint_client_->set_connection_error_handler(error_handler); |
114 } | 114 } |
115 | 115 |
116 // Returns true if bound and awaiting a response to a message. | 116 // Returns true if bound and awaiting a response to a message. |
117 bool has_pending_callbacks() const { | 117 bool has_pending_callbacks() const { |
118 return endpoint_client_ && endpoint_client_->has_pending_responders(); | 118 return endpoint_client_ && endpoint_client_->has_pending_responders(); |
119 } | 119 } |
120 | 120 |
121 AssociatedGroup* associated_group() { | 121 AssociatedGroup* associated_group() { |
122 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; | 122 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; |
123 } | 123 } |
124 | 124 |
125 private: | 125 private: |
126 using Proxy = typename Interface::Proxy_; | 126 using Proxy = typename Interface::Proxy_; |
127 | 127 |
128 void OnQueryVersion(const base::Callback<void(uint32_t)>& callback, | 128 void OnQueryVersion(const Callback<void(uint32_t)>& callback, |
129 uint32_t version) { | 129 uint32_t version) { |
130 version_ = version; | 130 version_ = version; |
131 callback.Run(version); | 131 callback.Run(version); |
132 } | 132 } |
133 | 133 |
134 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; | 134 std::unique_ptr<InterfaceEndpointClient> endpoint_client_; |
135 std::unique_ptr<Proxy> proxy_; | 135 std::unique_ptr<Proxy> proxy_; |
136 | 136 |
137 uint32_t version_; | 137 uint32_t version_; |
138 | 138 |
139 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState); | 139 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState); |
140 }; | 140 }; |
141 | 141 |
142 } // namespace internal | 142 } // namespace internal |
143 } // namespace mojo | 143 } // namespace mojo |
144 | 144 |
145 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ | 145 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ |
OLD | NEW |