Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: mojo/public/cpp/bindings/binding.h

Issue 2318793002: Mojo C++ bindings: support disconnect with a reason. (Closed)
Patch Set: . Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_BINDING_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
7 7
8 #include <string>
8 #include <utility> 9 #include <utility>
9 10
10 #include "base/callback_forward.h" 11 #include "base/callback_forward.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/single_thread_task_runner.h" 14 #include "base/single_thread_task_runner.h"
14 #include "base/threading/thread_task_runner_handle.h" 15 #include "base/threading/thread_task_runner_handle.h"
16 #include "mojo/public/cpp/bindings/connection_error_callback.h"
15 #include "mojo/public/cpp/bindings/interface_ptr.h" 17 #include "mojo/public/cpp/bindings/interface_ptr.h"
16 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 18 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
17 #include "mojo/public/cpp/bindings/interface_request.h" 19 #include "mojo/public/cpp/bindings/interface_request.h"
18 #include "mojo/public/cpp/bindings/lib/binding_state.h" 20 #include "mojo/public/cpp/bindings/lib/binding_state.h"
19 #include "mojo/public/cpp/system/core.h" 21 #include "mojo/public/cpp/system/core.h"
20 22
21 namespace mojo { 23 namespace mojo {
22 24
23 class AssociatedGroup; 25 class AssociatedGroup;
24 class MessageReceiver; 26 class MessageReceiver;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 bool WaitForIncomingMethodCall( 193 bool WaitForIncomingMethodCall(
192 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { 194 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) {
193 CHECK(!HasAssociatedInterfaces()); 195 CHECK(!HasAssociatedInterfaces());
194 return internal_state_.WaitForIncomingMethodCall(deadline); 196 return internal_state_.WaitForIncomingMethodCall(deadline);
195 } 197 }
196 198
197 // Closes the message pipe that was previously bound. Put this object into a 199 // Closes the message pipe that was previously bound. Put this object into a
198 // state where it can be rebound to a new pipe. 200 // state where it can be rebound to a new pipe.
199 void Close() { internal_state_.Close(); } 201 void Close() { internal_state_.Close(); }
200 202
203 // Similar to the method above, but also specifies a disconnect reason.
204 void CloseWithReason(uint32_t custom_reason, const std::string& description) {
205 internal_state_.CloseWithReason(custom_reason, description);
206 }
207
201 // Unbinds the underlying pipe from this binding and returns it so it can be 208 // Unbinds the underlying pipe from this binding and returns it so it can be
202 // used in another context, such as on another thread or with a different 209 // used in another context, such as on another thread or with a different
203 // implementation. Put this object into a state where it can be rebound to a 210 // implementation. Put this object into a state where it can be rebound to a
204 // new pipe. 211 // new pipe.
205 // 212 //
206 // This method may only be called if the object has been bound to a message 213 // This method may only be called if the object has been bound to a message
207 // pipe and there are no associated interfaces running. 214 // pipe and there are no associated interfaces running.
208 // 215 //
209 // TODO(yzshen): For now, users need to make sure there is no one holding 216 // TODO(yzshen): For now, users need to make sure there is no one holding
210 // on to associated interface endpoint handles at both sides of the 217 // on to associated interface endpoint handles at both sides of the
211 // message pipe in order to call this method. We need a way to forcefully 218 // message pipe in order to call this method. We need a way to forcefully
212 // invalidate associated interface endpoint handles. 219 // invalidate associated interface endpoint handles.
213 InterfaceRequest<Interface> Unbind() { 220 InterfaceRequest<Interface> Unbind() {
214 CHECK(!HasAssociatedInterfaces()); 221 CHECK(!HasAssociatedInterfaces());
215 return internal_state_.Unbind(); 222 return internal_state_.Unbind();
216 } 223 }
217 224
218 // Sets an error handler that will be called if a connection error occurs on 225 // Sets an error handler that will be called if a connection error occurs on
219 // the bound message pipe. 226 // the bound message pipe.
220 // 227 //
221 // This method may only be called after this Binding has been bound to a 228 // This method may only be called after this Binding has been bound to a
222 // message pipe. The error handler will be reset when this Binding is unbound 229 // message pipe. The error handler will be reset when this Binding is unbound
223 // or closed. 230 // or closed.
224 void set_connection_error_handler(const base::Closure& error_handler) { 231 void set_connection_error_handler(const base::Closure& error_handler) {
225 DCHECK(is_bound()); 232 DCHECK(is_bound());
226 internal_state_.set_connection_error_handler(error_handler); 233 internal_state_.set_connection_error_handler(error_handler);
227 } 234 }
228 235
236 void set_connection_error_with_reason_handler(
237 const ConnectionErrorWithReasonCallback& error_handler) {
238 DCHECK(is_bound());
239 internal_state_.set_connection_error_with_reason_handler(error_handler);
240 }
241
229 // Returns the interface implementation that was previously specified. Caller 242 // Returns the interface implementation that was previously specified. Caller
230 // does not take ownership. 243 // does not take ownership.
231 Interface* impl() { return internal_state_.impl(); } 244 Interface* impl() { return internal_state_.impl(); }
232 245
233 // Indicates whether the binding has been completed (i.e., whether a message 246 // Indicates whether the binding has been completed (i.e., whether a message
234 // pipe has been bound to the implementation). 247 // pipe has been bound to the implementation).
235 bool is_bound() const { return internal_state_.is_bound(); } 248 bool is_bound() const { return internal_state_.is_bound(); }
236 249
237 // Returns the value of the handle currently bound to this Binding which can 250 // Returns the value of the handle currently bound to this Binding which can
238 // be used to make explicit Wait/WaitMany calls. Requires that the Binding be 251 // be used to make explicit Wait/WaitMany calls. Requires that the Binding be
(...skipping 21 matching lines...) Expand all
260 private: 273 private:
261 internal::BindingState<Interface, Interface::PassesAssociatedKinds_> 274 internal::BindingState<Interface, Interface::PassesAssociatedKinds_>
262 internal_state_; 275 internal_state_;
263 276
264 DISALLOW_COPY_AND_ASSIGN(Binding); 277 DISALLOW_COPY_AND_ASSIGN(Binding);
265 }; 278 };
266 279
267 } // namespace mojo 280 } // namespace mojo
268 281
269 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_ 282 #endif // MOJO_PUBLIC_CPP_BINDINGS_BINDING_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/associated_interface_ptr.h ('k') | mojo/public/cpp/bindings/binding_set.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698