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

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

Issue 2608163003: Change single-interface mojo bindings to use SequencedTaskRunner. (Closed)
Patch Set: Created 3 years, 10 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_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 9
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
17 #include "base/single_thread_task_runner.h" 17 #include "base/sequenced_task_runner.h"
18 #include "base/threading/thread_task_runner_handle.h" 18 #include "base/threading/sequenced_task_runner_handle.h"
19 #include "mojo/public/cpp/bindings/associated_group.h" 19 #include "mojo/public/cpp/bindings/associated_group.h"
20 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 20 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
21 #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" 22 #include "mojo/public/cpp/bindings/connection_error_callback.h"
23 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h" 23 #include "mojo/public/cpp/bindings/lib/associated_interface_ptr_state.h"
24 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" 24 #include "mojo/public/cpp/bindings/lib/multiplex_router.h"
25 #include "mojo/public/cpp/system/message_pipe.h" 25 #include "mojo/public/cpp/system/message_pipe.h"
26 26
27 namespace mojo { 27 namespace mojo {
28 28
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 // 60 //
61 // |runner| must belong to the same thread. It will be used to dispatch all 61 // |runner| must belong to the same thread. It will be used to dispatch all
62 // callbacks and connection error notification. It is useful when you attach 62 // callbacks and connection error notification. It is useful when you attach
63 // multiple task runners to a single thread for the purposes of task 63 // multiple task runners to a single thread for the purposes of task
64 // scheduling. 64 // scheduling.
65 // 65 //
66 // NOTE: Please see the comments of 66 // NOTE: Please see the comments of
67 // AssociatedGroup.CreateAssociatedInterface() about when you can use this 67 // AssociatedGroup.CreateAssociatedInterface() about when you can use this
68 // object to make calls. 68 // object to make calls.
69 void Bind(AssociatedInterfacePtrInfo<Interface> info, 69 void Bind(AssociatedInterfacePtrInfo<Interface> info,
70 scoped_refptr<base::SingleThreadTaskRunner> runner = 70 scoped_refptr<base::SequencedTaskRunner> runner =
71 base::ThreadTaskRunnerHandle::Get()) { 71 base::SequencedTaskRunnerHandle::Get()) {
72 reset(); 72 reset();
73 73
74 bool is_local = info.handle().is_local(); 74 bool is_local = info.handle().is_local();
75 75
76 DCHECK(is_local) << "The AssociatedInterfacePtrInfo is supposed to be used " 76 DCHECK(is_local) << "The AssociatedInterfacePtrInfo is supposed to be used "
77 "at the other side of the message pipe."; 77 "at the other side of the message pipe.";
78 78
79 if (info.is_valid() && is_local) 79 if (info.is_valid() && is_local)
80 internal_state_.Bind(std::move(info), std::move(runner)); 80 internal_state_.Bind(std::move(info), std::move(runner));
81 } 81 }
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 // interface implementation at the remote side. 208 // interface implementation at the remote side.
209 // 209 //
210 // NOTE: |ptr| should NOT be used to make calls before the request is sent. 210 // NOTE: |ptr| should NOT be used to make calls before the request is sent.
211 // Violating that will cause the message pipe to be closed. On the other hand, 211 // Violating that will cause the message pipe to be closed. On the other hand,
212 // as soon as the request is sent, |ptr| is usable. There is no need to wait 212 // as soon as the request is sent, |ptr| is usable. There is no need to wait
213 // until the request is bound to an implementation at the remote side. 213 // until the request is bound to an implementation at the remote side.
214 template <typename Interface> 214 template <typename Interface>
215 AssociatedInterfaceRequest<Interface> MakeRequest( 215 AssociatedInterfaceRequest<Interface> MakeRequest(
216 AssociatedInterfacePtr<Interface>* ptr, 216 AssociatedInterfacePtr<Interface>* ptr,
217 AssociatedGroup* group, 217 AssociatedGroup* group,
218 scoped_refptr<base::SingleThreadTaskRunner> runner = 218 scoped_refptr<base::SequencedTaskRunner> runner =
219 base::ThreadTaskRunnerHandle::Get()) { 219 base::SequencedTaskRunnerHandle::Get()) {
220 AssociatedInterfaceRequest<Interface> request; 220 AssociatedInterfaceRequest<Interface> request;
221 AssociatedInterfacePtrInfo<Interface> ptr_info; 221 AssociatedInterfacePtrInfo<Interface> ptr_info;
222 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST, 222 group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST,
223 &ptr_info, &request); 223 &ptr_info, &request);
224 224
225 ptr->Bind(std::move(ptr_info), std::move(runner)); 225 ptr->Bind(std::move(ptr_info), std::move(runner));
226 return request; 226 return request;
227 } 227 }
228 228
229 // Creates an associated interface proxy in its own AssociatedGroup. 229 // Creates an associated interface proxy in its own AssociatedGroup.
230 template <typename Interface> 230 template <typename Interface>
231 AssociatedInterfaceRequest<Interface> MakeRequestForTesting( 231 AssociatedInterfaceRequest<Interface> MakeRequestForTesting(
232 AssociatedInterfacePtr<Interface>* ptr, 232 AssociatedInterfacePtr<Interface>* ptr,
233 scoped_refptr<base::SingleThreadTaskRunner> runner = 233 scoped_refptr<base::SequencedTaskRunner> runner =
234 base::ThreadTaskRunnerHandle::Get()) { 234 base::SequencedTaskRunnerHandle::Get()) {
235 MessagePipe pipe; 235 MessagePipe pipe;
236 using internal::MultiplexRouter; 236 using internal::MultiplexRouter;
237 scoped_refptr<MultiplexRouter> router0 = new MultiplexRouter( 237 scoped_refptr<MultiplexRouter> router0 = new MultiplexRouter(
238 std::move(pipe.handle0), MultiplexRouter::MULTI_INTERFACE, true, runner); 238 std::move(pipe.handle0), MultiplexRouter::MULTI_INTERFACE, true, runner);
239 scoped_refptr<MultiplexRouter> router1 = new MultiplexRouter( 239 scoped_refptr<MultiplexRouter> router1 = new MultiplexRouter(
240 std::move(pipe.handle1), MultiplexRouter::MULTI_INTERFACE, false, runner); 240 std::move(pipe.handle1), MultiplexRouter::MULTI_INTERFACE, false, runner);
241 241
242 AssociatedInterfacePtrInfo<Interface> ptr_info; 242 AssociatedInterfacePtrInfo<Interface> ptr_info;
243 AssociatedInterfaceRequest<Interface> request; 243 AssociatedInterfaceRequest<Interface> request;
244 router1->CreateAssociatedGroup()->CreateAssociatedInterface( 244 router1->CreateAssociatedGroup()->CreateAssociatedInterface(
(...skipping 20 matching lines...) Expand all
265 // * In testing, where the returned request is bound to e.g. a mock and there 265 // * In testing, where the returned request is bound to e.g. a mock and there
266 // are no other interfaces involved. 266 // are no other interfaces involved.
267 // 267 //
268 // * When discarding messages sent on an interface, which can be done by 268 // * When discarding messages sent on an interface, which can be done by
269 // discarding the returned request. 269 // discarding the returned request.
270 template <typename Interface> 270 template <typename Interface>
271 AssociatedInterfaceRequest<Interface> GetIsolatedProxy( 271 AssociatedInterfaceRequest<Interface> GetIsolatedProxy(
272 AssociatedInterfacePtr<Interface>* ptr) { 272 AssociatedInterfacePtr<Interface>* ptr) {
273 MessagePipe pipe; 273 MessagePipe pipe;
274 scoped_refptr<internal::MultiplexRouter> router0 = 274 scoped_refptr<internal::MultiplexRouter> router0 =
275 new internal::MultiplexRouter(std::move(pipe.handle0), 275 new internal::MultiplexRouter(
276 internal::MultiplexRouter::MULTI_INTERFACE, 276 std::move(pipe.handle0), internal::MultiplexRouter::MULTI_INTERFACE,
277 false, base::ThreadTaskRunnerHandle::Get()); 277 false, base::SequencedTaskRunnerHandle::Get());
278 scoped_refptr<internal::MultiplexRouter> router1 = 278 scoped_refptr<internal::MultiplexRouter> router1 =
279 new internal::MultiplexRouter(std::move(pipe.handle1), 279 new internal::MultiplexRouter(
280 internal::MultiplexRouter::MULTI_INTERFACE, 280 std::move(pipe.handle1), internal::MultiplexRouter::MULTI_INTERFACE,
281 true, base::ThreadTaskRunnerHandle::Get()); 281 true, base::SequencedTaskRunnerHandle::Get());
282 282
283 ScopedInterfaceEndpointHandle endpoint0, endpoint1; 283 ScopedInterfaceEndpointHandle endpoint0, endpoint1;
284 router0->CreateEndpointHandlePair(&endpoint0, &endpoint1); 284 router0->CreateEndpointHandlePair(&endpoint0, &endpoint1);
285 endpoint1 = router1->CreateLocalEndpointHandle(endpoint1.release()); 285 endpoint1 = router1->CreateLocalEndpointHandle(endpoint1.release());
286 286
287 ptr->Bind(AssociatedInterfacePtrInfo<Interface>(std::move(endpoint0), 287 ptr->Bind(AssociatedInterfacePtrInfo<Interface>(std::move(endpoint0),
288 Interface::Version_)); 288 Interface::Version_));
289 289
290 AssociatedInterfaceRequest<Interface> request; 290 AssociatedInterfaceRequest<Interface> request;
291 request.Bind(std::move(endpoint1)); 291 request.Bind(std::move(endpoint1));
292 return request; 292 return request;
293 } 293 }
294 294
295 } // namespace mojo 295 } // namespace mojo
296 296
297 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_ 297 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_INTERFACE_PTR_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/associated_group_controller.h ('k') | mojo/public/cpp/bindings/associated_interface_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698