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_BINDING_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/callback.h" | |
13 #include "base/macros.h" | 12 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
15 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
16 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
18 #include "mojo/public/cpp/bindings/associated_group.h" | 17 #include "mojo/public/cpp/bindings/associated_group.h" |
19 #include "mojo/public/cpp/bindings/associated_interface_request.h" | 18 #include "mojo/public/cpp/bindings/associated_interface_request.h" |
| 19 #include "mojo/public/cpp/bindings/callback.h" |
20 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" | 20 #include "mojo/public/cpp/bindings/lib/interface_endpoint_client.h" |
21 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 21 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" | 22 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" |
23 | 23 |
24 namespace mojo { | 24 namespace mojo { |
25 | 25 |
26 // Represents the implementation side of an associated interface. It is similar | 26 // Represents the implementation side of an associated interface. It is similar |
27 // to Binding, except that it doesn't own a message pipe handle. | 27 // to Binding, except that it doesn't own a message pipe handle. |
28 // | 28 // |
29 // When you bind this class to a request, optionally you can specify a | 29 // When you bind this class to a request, optionally you can specify a |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 connection_error_handler_.Reset(); | 130 connection_error_handler_.Reset(); |
131 | 131 |
132 return request; | 132 return request; |
133 } | 133 } |
134 | 134 |
135 // Sets an error handler that will be called if a connection error occurs. | 135 // Sets an error handler that will be called if a connection error occurs. |
136 // | 136 // |
137 // This method may only be called after this AssociatedBinding has been bound | 137 // This method may only be called after this AssociatedBinding has been bound |
138 // to a message pipe. The error handler will be reset when this | 138 // to a message pipe. The error handler will be reset when this |
139 // AssociatedBinding is unbound or closed. | 139 // AssociatedBinding is unbound or closed. |
140 void set_connection_error_handler(const base::Closure& error_handler) { | 140 void set_connection_error_handler(const Closure& error_handler) { |
141 DCHECK(is_bound()); | 141 DCHECK(is_bound()); |
142 connection_error_handler_ = error_handler; | 142 connection_error_handler_ = error_handler; |
143 } | 143 } |
144 | 144 |
145 // Returns the interface implementation that was previously specified. | 145 // Returns the interface implementation that was previously specified. |
146 Interface* impl() { return impl_; } | 146 Interface* impl() { return impl_; } |
147 | 147 |
148 // Indicates whether the associated binding has been completed. | 148 // Indicates whether the associated binding has been completed. |
149 bool is_bound() const { return !!endpoint_client_; } | 149 bool is_bound() const { return !!endpoint_client_; } |
150 | 150 |
151 // Returns the associated group that this object belongs to. Returns null if | 151 // Returns the associated group that this object belongs to. Returns null if |
152 // the object is not bound. | 152 // the object is not bound. |
153 AssociatedGroup* associated_group() { | 153 AssociatedGroup* associated_group() { |
154 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; | 154 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; |
155 } | 155 } |
156 | 156 |
157 private: | 157 private: |
158 void RunConnectionErrorHandler() { | 158 void RunConnectionErrorHandler() { |
159 if (!connection_error_handler_.is_null()) | 159 if (!connection_error_handler_.is_null()) |
160 connection_error_handler_.Run(); | 160 connection_error_handler_.Run(); |
161 } | 161 } |
162 | 162 |
163 std::unique_ptr<internal::InterfaceEndpointClient> endpoint_client_; | 163 std::unique_ptr<internal::InterfaceEndpointClient> endpoint_client_; |
164 | 164 |
165 typename Interface::Stub_ stub_; | 165 typename Interface::Stub_ stub_; |
166 Interface* impl_; | 166 Interface* impl_; |
167 base::Closure connection_error_handler_; | 167 Closure connection_error_handler_; |
168 | 168 |
169 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); | 169 DISALLOW_COPY_AND_ASSIGN(AssociatedBinding); |
170 }; | 170 }; |
171 | 171 |
172 } // namespace mojo | 172 } // namespace mojo |
173 | 173 |
174 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ | 174 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_BINDING_H_ |
OLD | NEW |