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

Side by Side Diff: mojo/public/cpp/bindings/lib/binding_state.h

Issue 2062333002: mojo::Callback -> base::Callback (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 6 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 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_BINDING_STATE_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_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/logging.h" 12 #include "base/logging.h"
12 #include "base/macros.h" 13 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "mojo/public/cpp/bindings/associated_group.h" 17 #include "mojo/public/cpp/bindings/associated_group.h"
17 #include "mojo/public/cpp/bindings/callback.h" 18 #include "mojo/public/cpp/bindings/callback.h"
18 #include "mojo/public/cpp/bindings/interface_ptr.h" 19 #include "mojo/public/cpp/bindings/interface_ptr.h"
19 #include "mojo/public/cpp/bindings/interface_ptr_info.h" 20 #include "mojo/public/cpp/bindings/interface_ptr_info.h"
20 #include "mojo/public/cpp/bindings/interface_request.h" 21 #include "mojo/public/cpp/bindings/interface_request.h"
(...skipping 30 matching lines...) Expand all
51 DCHECK(!router_); 52 DCHECK(!router_);
52 internal::FilterChain filters; 53 internal::FilterChain filters;
53 filters.Append<internal::MessageHeaderValidator>(Interface::Name_); 54 filters.Append<internal::MessageHeaderValidator>(Interface::Name_);
54 filters.Append<typename Interface::RequestValidator_>(); 55 filters.Append<typename Interface::RequestValidator_>();
55 56
56 router_ = 57 router_ =
57 new internal::Router(std::move(handle), std::move(filters), 58 new internal::Router(std::move(handle), std::move(filters),
58 Interface::HasSyncMethods_, std::move(runner)); 59 Interface::HasSyncMethods_, std::move(runner));
59 router_->set_incoming_receiver(&stub_); 60 router_->set_incoming_receiver(&stub_);
60 router_->set_connection_error_handler( 61 router_->set_connection_error_handler(
61 [this]() { connection_error_handler_.Run(); }); 62 base::Bind(&BindingState::RunConnectionErrorHandler,
63 base::Unretained(this)));
62 } 64 }
63 65
64 bool HasAssociatedInterfaces() const { return false; } 66 bool HasAssociatedInterfaces() const { return false; }
65 67
66 void PauseIncomingMethodCallProcessing() { 68 void PauseIncomingMethodCallProcessing() {
67 DCHECK(router_); 69 DCHECK(router_);
68 router_->PauseIncomingMethodCallProcessing(); 70 router_->PauseIncomingMethodCallProcessing();
69 } 71 }
70 void ResumeIncomingMethodCallProcessing() { 72 void ResumeIncomingMethodCallProcessing() {
71 DCHECK(router_); 73 DCHECK(router_);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 void EnableTestingMode() { 114 void EnableTestingMode() {
113 DCHECK(is_bound()); 115 DCHECK(is_bound());
114 router_->EnableTestingMode(); 116 router_->EnableTestingMode();
115 } 117 }
116 118
117 private: 119 private:
118 void DestroyRouter() { 120 void DestroyRouter() {
119 router_->set_connection_error_handler(Closure()); 121 router_->set_connection_error_handler(Closure());
120 delete router_; 122 delete router_;
121 router_ = nullptr; 123 router_ = nullptr;
122 connection_error_handler_.reset(); 124 connection_error_handler_.Reset();
125 }
126
127 void RunConnectionErrorHandler() {
128 if (!connection_error_handler_.is_null())
129 connection_error_handler_.Run();
123 } 130 }
124 131
125 internal::Router* router_ = nullptr; 132 internal::Router* router_ = nullptr;
126 typename Interface::Stub_ stub_; 133 typename Interface::Stub_ stub_;
127 Interface* impl_; 134 Interface* impl_;
128 Closure connection_error_handler_; 135 Closure connection_error_handler_;
129 136
130 DISALLOW_COPY_AND_ASSIGN(BindingState); 137 DISALLOW_COPY_AND_ASSIGN(BindingState);
131 }; 138 };
132 139
(...skipping 15 matching lines...) Expand all
148 router_ = new internal::MultiplexRouter(false, std::move(handle), runner); 155 router_ = new internal::MultiplexRouter(false, std::move(handle), runner);
149 router_->SetMasterInterfaceName(Interface::Name_); 156 router_->SetMasterInterfaceName(Interface::Name_);
150 stub_.serialization_context()->router = router_; 157 stub_.serialization_context()->router = router_;
151 158
152 endpoint_client_.reset(new internal::InterfaceEndpointClient( 159 endpoint_client_.reset(new internal::InterfaceEndpointClient(
153 router_->CreateLocalEndpointHandle(internal::kMasterInterfaceId), 160 router_->CreateLocalEndpointHandle(internal::kMasterInterfaceId),
154 &stub_, base::WrapUnique(new typename Interface::RequestValidator_()), 161 &stub_, base::WrapUnique(new typename Interface::RequestValidator_()),
155 Interface::HasSyncMethods_, std::move(runner))); 162 Interface::HasSyncMethods_, std::move(runner)));
156 163
157 endpoint_client_->set_connection_error_handler( 164 endpoint_client_->set_connection_error_handler(
158 [this]() { connection_error_handler_.Run(); }); 165 base::Bind(&BindingState::RunConnectionErrorHandler,
166 base::Unretained(this)));
159 } 167 }
160 168
161 bool HasAssociatedInterfaces() const { 169 bool HasAssociatedInterfaces() const {
162 return router_ ? router_->HasAssociatedEndpoints() : false; 170 return router_ ? router_->HasAssociatedEndpoints() : false;
163 } 171 }
164 172
165 void PauseIncomingMethodCallProcessing() { 173 void PauseIncomingMethodCallProcessing() {
166 DCHECK(router_); 174 DCHECK(router_);
167 router_->PauseIncomingMethodCallProcessing(); 175 router_->PauseIncomingMethodCallProcessing();
168 } 176 }
169 void ResumeIncomingMethodCallProcessing() { 177 void ResumeIncomingMethodCallProcessing() {
170 DCHECK(router_); 178 DCHECK(router_);
171 router_->ResumeIncomingMethodCallProcessing(); 179 router_->ResumeIncomingMethodCallProcessing();
172 } 180 }
173 181
174 bool WaitForIncomingMethodCall( 182 bool WaitForIncomingMethodCall(
175 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) { 183 MojoDeadline deadline = MOJO_DEADLINE_INDEFINITE) {
176 DCHECK(router_); 184 DCHECK(router_);
177 return router_->WaitForIncomingMessage(deadline); 185 return router_->WaitForIncomingMessage(deadline);
178 } 186 }
179 187
180 void Close() { 188 void Close() {
181 if (!router_) 189 if (!router_)
182 return; 190 return;
183 191
184 endpoint_client_.reset(); 192 endpoint_client_.reset();
185 router_->CloseMessagePipe(); 193 router_->CloseMessagePipe();
186 router_ = nullptr; 194 router_ = nullptr;
187 connection_error_handler_.reset(); 195 connection_error_handler_.Reset();
188 } 196 }
189 197
190 InterfaceRequest<Interface> Unbind() { 198 InterfaceRequest<Interface> Unbind() {
191 endpoint_client_.reset(); 199 endpoint_client_.reset();
192 InterfaceRequest<Interface> request = 200 InterfaceRequest<Interface> request =
193 MakeRequest<Interface>(router_->PassMessagePipe()); 201 MakeRequest<Interface>(router_->PassMessagePipe());
194 router_ = nullptr; 202 router_ = nullptr;
195 connection_error_handler_.reset(); 203 connection_error_handler_.Reset();
196 return request; 204 return request;
197 } 205 }
198 206
199 void set_connection_error_handler(const Closure& error_handler) { 207 void set_connection_error_handler(const Closure& error_handler) {
200 DCHECK(is_bound()); 208 DCHECK(is_bound());
201 connection_error_handler_ = error_handler; 209 connection_error_handler_ = error_handler;
202 } 210 }
203 211
204 Interface* impl() { return impl_; } 212 Interface* impl() { return impl_; }
205 213
206 bool is_bound() const { return !!router_; } 214 bool is_bound() const { return !!router_; }
207 215
208 MessagePipeHandle handle() const { 216 MessagePipeHandle handle() const {
209 DCHECK(is_bound()); 217 DCHECK(is_bound());
210 return router_->handle(); 218 return router_->handle();
211 } 219 }
212 220
213 AssociatedGroup* associated_group() { 221 AssociatedGroup* associated_group() {
214 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr; 222 return endpoint_client_ ? endpoint_client_->associated_group() : nullptr;
215 } 223 }
216 224
217 void EnableTestingMode() { 225 void EnableTestingMode() {
218 DCHECK(is_bound()); 226 DCHECK(is_bound());
219 router_->EnableTestingMode(); 227 router_->EnableTestingMode();
220 } 228 }
221 229
222 private: 230 private:
231 void RunConnectionErrorHandler() {
232 if (!connection_error_handler_.is_null())
233 connection_error_handler_.Run();
234 }
235
223 scoped_refptr<internal::MultiplexRouter> router_; 236 scoped_refptr<internal::MultiplexRouter> router_;
224 std::unique_ptr<internal::InterfaceEndpointClient> endpoint_client_; 237 std::unique_ptr<internal::InterfaceEndpointClient> endpoint_client_;
225 238
226 typename Interface::Stub_ stub_; 239 typename Interface::Stub_ stub_;
227 Interface* impl_; 240 Interface* impl_;
228 Closure connection_error_handler_; 241 Closure connection_error_handler_;
229 242
230 DISALLOW_COPY_AND_ASSIGN(BindingState); 243 DISALLOW_COPY_AND_ASSIGN(BindingState);
231 }; 244 };
232 245
233 } // namesapce internal 246 } // namesapce internal
234 } // namespace mojo 247 } // namespace mojo
235 248
236 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_ 249 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_BINDING_STATE_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h ('k') | mojo/public/cpp/bindings/lib/callback_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698