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

Side by Side Diff: mojo/public/cpp/bindings/associated_interface_ptr.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
« no previous file with comments | « mojo/public/cpp/bindings/associated_binding.h ('k') | mojo/public/cpp/bindings/binding.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_INTERFACE_PTR_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9
10 #include <string>
9 #include <utility> 11 #include <utility>
10 12
11 #include "base/callback.h" 13 #include "base/callback.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
13 #include "base/macros.h" 15 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
15 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
16 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/thread_task_runner_handle.h"
17 #include "mojo/public/cpp/bindings/associated_group.h" 19 #include "mojo/public/cpp/bindings/associated_group.h"
18 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 20 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
19 #include "mojo/public/cpp/bindings/associated_interface_request.h" 21 #include "mojo/public/cpp/bindings/associated_interface_request.h"
22 #include "mojo/public/cpp/bindings/connection_error_callback.h"
20 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h" 23 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h"
21 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 24 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
22 #include "mojo/public/cpp/system/message_pipe.h" 25 #include "mojo/public/cpp/system/message_pipe.h"
23 26
24 namespace mojo { 27 namespace mojo {
25 28
26 // Represents the client side of an associated interface. It is similar to 29 // Represents the client side of an associated interface. It is similar to
27 // InterfacePtr, except that it doesn't own a message pipe handle. 30 // InterfacePtr, except that it doesn't own a message pipe handle.
28 template <typename Interface> 31 template <typename Interface>
29 class AssociatedInterfacePtr { 32 class AssociatedInterfacePtr {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // stimulus. 118 // stimulus.
116 void FlushForTesting() { internal_state_.FlushForTesting(); } 119 void FlushForTesting() { internal_state_.FlushForTesting(); }
117 120
118 // Closes the associated interface (if any) and returns the pointer to the 121 // Closes the associated interface (if any) and returns the pointer to the
119 // unbound state. 122 // unbound state.
120 void reset() { 123 void reset() {
121 State doomed; 124 State doomed;
122 internal_state_.Swap(&doomed); 125 internal_state_.Swap(&doomed);
123 } 126 }
124 127
128 // Similar to the method above, but also specifies a disconnect reason.
129 void ResetWithReason(uint32_t custom_reason, const std::string& description) {
130 if (internal_state_.is_bound())
131 internal_state_.SendDisconnectReason(custom_reason, description);
132 reset();
133 }
134
125 // Indicates whether an error has been encountered. If true, method calls made 135 // Indicates whether an error has been encountered. If true, method calls made
126 // on this interface will be dropped (and may already have been dropped). 136 // on this interface will be dropped (and may already have been dropped).
127 bool encountered_error() const { return internal_state_.encountered_error(); } 137 bool encountered_error() const { return internal_state_.encountered_error(); }
128 138
129 // Registers a handler to receive error notifications. 139 // Registers a handler to receive error notifications.
130 // 140 //
131 // This method may only be called after the AssociatedInterfacePtr has been 141 // This method may only be called after the AssociatedInterfacePtr has been
132 // bound. 142 // bound.
133 void set_connection_error_handler(const base::Closure& error_handler) { 143 void set_connection_error_handler(const base::Closure& error_handler) {
134 internal_state_.set_connection_error_handler(error_handler); 144 internal_state_.set_connection_error_handler(error_handler);
135 } 145 }
136 146
147 void set_connection_error_with_reason_handler(
148 const ConnectionErrorWithReasonCallback& error_handler) {
149 internal_state_.set_connection_error_with_reason_handler(error_handler);
150 }
151
137 // Unbinds and returns the associated interface pointer information which 152 // Unbinds and returns the associated interface pointer information which
138 // could be used to setup an AssociatedInterfacePtr again. This method may be 153 // could be used to setup an AssociatedInterfacePtr again. This method may be
139 // used to move the proxy to a different thread. 154 // used to move the proxy to a different thread.
140 // 155 //
141 // It is an error to call PassInterface() while there are pending responses. 156 // It is an error to call PassInterface() while there are pending responses.
142 // TODO: fix this restriction, it's not always obvious when there is a 157 // TODO: fix this restriction, it's not always obvious when there is a
143 // pending response. 158 // pending response.
144 AssociatedInterfacePtrInfo<Interface> PassInterface() { 159 AssociatedInterfacePtrInfo<Interface> PassInterface() {
145 DCHECK(!internal_state_.has_pending_callbacks()); 160 DCHECK(!internal_state_.has_pending_callbacks());
146 State state; 161 State state;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 scoped_refptr<internal::MultiplexRouter> router = 233 scoped_refptr<internal::MultiplexRouter> router =
219 new internal::MultiplexRouter(false, std::move(pipe.handle0), 234 new internal::MultiplexRouter(false, std::move(pipe.handle0),
220 base::ThreadTaskRunnerHandle::Get()); 235 base::ThreadTaskRunnerHandle::Get());
221 std::unique_ptr<AssociatedGroup> group = router->CreateAssociatedGroup(); 236 std::unique_ptr<AssociatedGroup> group = router->CreateAssociatedGroup();
222 GetProxy(proxy, group.get()); 237 GetProxy(proxy, group.get());
223 } 238 }
224 239
225 } // namespace mojo 240 } // namespace mojo
226 241
227 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ 242 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/associated_binding.h ('k') | mojo/public/cpp/bindings/binding.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698