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

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

Issue 1991463002: Mojo: Expose untyped associated endpoints through public API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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_GROUP_H_ 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_
7 7
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
11 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h" 11 #include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
12 #include "mojo/public/cpp/bindings/associated_interface_request.h" 12 #include "mojo/public/cpp/bindings/associated_interface_request.h"
13 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" 13 #include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 16
17 namespace internal { 17 namespace internal {
18 class MultiplexRouter; 18 class MultiplexRouter;
19 } 19 }
20 20
21 // AssociatedGroup refers to all the interface endpoints running at one end of a 21 // AssociatedGroup refers to all the interface endpoints running at one end of a
22 // message pipe. It is used to create associated interfaces for that message 22 // message pipe. It is used to create associated interfaces for that message
23 // pipe. 23 // pipe.
(...skipping 19 matching lines...) Expand all
43 // restriction: the pointer should NOT be used to make calls before |request| 43 // restriction: the pointer should NOT be used to make calls before |request|
44 // is sent. Violating that will cause the message pipe to be closed. On the 44 // is sent. Violating that will cause the message pipe to be closed. On the
45 // other hand, as soon as |request| is sent, the pointer is usable. There is 45 // other hand, as soon as |request| is sent, the pointer is usable. There is
46 // no need to wait until |request| is bound to an implementation at the remote 46 // no need to wait until |request| is bound to an implementation at the remote
47 // side. 47 // side.
48 template <typename T> 48 template <typename T>
49 void CreateAssociatedInterface( 49 void CreateAssociatedInterface(
50 AssociatedInterfaceConfig config, 50 AssociatedInterfaceConfig config,
51 AssociatedInterfacePtrInfo<T>* ptr_info, 51 AssociatedInterfacePtrInfo<T>* ptr_info,
52 AssociatedInterfaceRequest<T>* request) { 52 AssociatedInterfaceRequest<T>* request) {
53 internal::ScopedInterfaceEndpointHandle local; 53 ScopedInterfaceEndpointHandle local;
54 internal::ScopedInterfaceEndpointHandle remote; 54 ScopedInterfaceEndpointHandle remote;
55 CreateEndpointHandlePair(&local, &remote); 55 CreateEndpointHandlePair(&local, &remote);
56 56
57 if (!local.is_valid() || !remote.is_valid()) { 57 if (!local.is_valid() || !remote.is_valid()) {
58 *ptr_info = AssociatedInterfacePtrInfo<T>(); 58 *ptr_info = AssociatedInterfacePtrInfo<T>();
59 *request = AssociatedInterfaceRequest<T>(); 59 *request = AssociatedInterfaceRequest<T>();
60 return; 60 return;
61 } 61 }
62 62
63 if (config == WILL_PASS_PTR) { 63 if (config == WILL_PASS_PTR) {
64 internal::AssociatedInterfacePtrInfoHelper::SetHandle(ptr_info, 64 ptr_info->set_handle(std::move(remote));
65 std::move(remote)); 65
66 // The implementation is local, therefore set the version according to 66 // The implementation is local, therefore set the version according to
67 // the interface definition that this code is built against. 67 // the interface definition that this code is built against.
68 ptr_info->set_version(T::Version_); 68 ptr_info->set_version(T::Version_);
69 internal::AssociatedInterfaceRequestHelper::SetHandle(request, 69 request->Bind(std::move(local));
70 std::move(local));
71 } else { 70 } else {
72 internal::AssociatedInterfacePtrInfoHelper::SetHandle(ptr_info, 71 ptr_info->set_handle(std::move(local));
73 std::move(local)); 72
74 // The implementation is remote, we don't know about its actual version 73 // The implementation is remote, we don't know about its actual version
75 // yet. 74 // yet.
76 ptr_info->set_version(0u); 75 ptr_info->set_version(0u);
77 internal::AssociatedInterfaceRequestHelper::SetHandle(request, 76 request->Bind(std::move(remote));
78 std::move(remote));
79 } 77 }
80 } 78 }
81 79
82 private: 80 private:
83 friend class internal::MultiplexRouter; 81 friend class internal::MultiplexRouter;
84 82
85 void CreateEndpointHandlePair( 83 void CreateEndpointHandlePair(
86 internal::ScopedInterfaceEndpointHandle* local_endpoint, 84 ScopedInterfaceEndpointHandle* local_endpoint,
87 internal::ScopedInterfaceEndpointHandle* remote_endpoint); 85 ScopedInterfaceEndpointHandle* remote_endpoint);
88 86
89 scoped_refptr<internal::MultiplexRouter> router_; 87 scoped_refptr<internal::MultiplexRouter> router_;
90 }; 88 };
91 89
92 } // namespace mojo 90 } // namespace mojo
93 91
94 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_ 92 #endif // MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/associated_binding.h ('k') | mojo/public/cpp/bindings/associated_interface_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698