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

Side by Side Diff: mojo/public/cpp/bindings/lib/associated_interface_ptr_state.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/interface_ptr.h ('k') | mojo/public/cpp/bindings/lib/binding_state.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_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 <string>
12 #include <utility> 13 #include <utility>
13 14
14 #include "base/bind.h" 15 #include "base/bind.h"
15 #include "base/callback_forward.h" 16 #include "base/callback_forward.h"
16 #include "base/macros.h" 17 #include "base/macros.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
19 #include "base/single_thread_task_runner.h" 20 #include "base/single_thread_task_runner.h"
20 #include "mojo/public/cpp/bindings/associated_group.h" 21 #include "mojo/public/cpp/bindings/associated_group.h"
21 #include "mojo/public/cpp/bindings/associated_group_controller.h" 22 #include "mojo/public/cpp/bindings/associated_group_controller.h"
22 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 23 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
24 #include "mojo/public/cpp/bindings/connection_error_callback.h"
23 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" 25 #include "mojo/public/cpp/bindings/interface_endpoint_client.h"
24 #include "mojo/public/cpp/bindings/interface_id.h" 26 #include "mojo/public/cpp/bindings/interface_id.h"
25 #include "mojo/public/cpp/bindings/lib/control_message_handler.h" 27 #include "mojo/public/cpp/bindings/lib/control_message_handler.h"
26 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h" 28 #include "mojo/public/cpp/bindings/lib/control_message_proxy.h"
27 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h" 29 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
28 #include "mojo/public/cpp/system/message_pipe.h" 30 #include "mojo/public/cpp/system/message_pipe.h"
29 31
30 namespace mojo { 32 namespace mojo {
31 namespace internal { 33 namespace internal {
32 34
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return; 67 return;
66 68
67 version_ = version; 69 version_ = version;
68 endpoint_client_->control_message_proxy()->RequireVersion(version); 70 endpoint_client_->control_message_proxy()->RequireVersion(version);
69 } 71 }
70 72
71 void FlushForTesting() { 73 void FlushForTesting() {
72 endpoint_client_->control_message_proxy()->FlushForTesting(); 74 endpoint_client_->control_message_proxy()->FlushForTesting();
73 } 75 }
74 76
77 void SendDisconnectReason(uint32_t custom_reason,
78 const std::string& description) {
79 endpoint_client_->control_message_proxy()->SendDisconnectReason(
80 custom_reason, description);
81 }
82
75 void Swap(AssociatedInterfacePtrState* other) { 83 void Swap(AssociatedInterfacePtrState* other) {
76 using std::swap; 84 using std::swap;
77 swap(other->endpoint_client_, endpoint_client_); 85 swap(other->endpoint_client_, endpoint_client_);
78 swap(other->proxy_, proxy_); 86 swap(other->proxy_, proxy_);
79 swap(other->version_, version_); 87 swap(other->version_, version_);
80 } 88 }
81 89
82 void Bind(AssociatedInterfacePtrInfo<Interface> info, 90 void Bind(AssociatedInterfacePtrInfo<Interface> info,
83 scoped_refptr<base::SingleThreadTaskRunner> runner) { 91 scoped_refptr<base::SingleThreadTaskRunner> runner) {
84 DCHECK(!endpoint_client_); 92 DCHECK(!endpoint_client_);
(...skipping 26 matching lines...) Expand all
111 119
112 bool encountered_error() const { 120 bool encountered_error() const {
113 return endpoint_client_ ? endpoint_client_->encountered_error() : false; 121 return endpoint_client_ ? endpoint_client_->encountered_error() : false;
114 } 122 }
115 123
116 void set_connection_error_handler(const base::Closure& error_handler) { 124 void set_connection_error_handler(const base::Closure& error_handler) {
117 DCHECK(endpoint_client_); 125 DCHECK(endpoint_client_);
118 endpoint_client_->set_connection_error_handler(error_handler); 126 endpoint_client_->set_connection_error_handler(error_handler);
119 } 127 }
120 128
129 void set_connection_error_with_reason_handler(
130 const ConnectionErrorWithReasonCallback& error_handler) {
131 DCHECK(endpoint_client_);
132 endpoint_client_->set_connection_error_with_reason_handler(error_handler);
133 }
134
121 // Returns true if bound and awaiting a response to a message. 135 // Returns true if bound and awaiting a response to a message.
122 bool has_pending_callbacks() const { 136 bool has_pending_callbacks() const {
123 return endpoint_client_ && endpoint_client_->has_pending_responders(); 137 return endpoint_client_ && endpoint_client_->has_pending_responders();
124 } 138 }
125 139
126 AssociatedGroup* associated_group() { 140 AssociatedGroup* associated_group() {
127 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; 141 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr;
128 } 142 }
129 143
130 private: 144 private:
(...skipping 10 matching lines...) Expand all
141 155
142 uint32_t version_; 156 uint32_t version_;
143 157
144 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState); 158 DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtrState);
145 }; 159 };
146 160
147 } // namespace internal 161 } // namespace internal
148 } // namespace mojo 162 } // namespace mojo
149 163
150 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_ 164 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_ASSOCIATED_INTERFACE_PTR_STATE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/interface_ptr.h ('k') | mojo/public/cpp/bindings/lib/binding_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698