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

Unified Diff: mojo/public/cpp/bindings/associated_interface_ptr.h

Issue 2696233002: Mojo C++ bindings: remove some usage of AssociatedGroup from user code. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/associated_binding.h ('k') | mojo/public/cpp/bindings/lib/multiplex_router.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/associated_interface_ptr.h
diff --git a/mojo/public/cpp/bindings/associated_interface_ptr.h b/mojo/public/cpp/bindings/associated_interface_ptr.h
index 7cef1eb418ce829bace540bcde851954b6f3848d..f30f3d8c4c39e2d30817c0e01399df03ae7d5210 100644
--- a/mojo/public/cpp/bindings/associated_interface_ptr.h
+++ b/mojo/public/cpp/bindings/associated_interface_ptr.h
@@ -66,9 +66,10 @@ class AssociatedInterfacePtr {
// multiple task runners to a single thread for the purposes of task
// scheduling.
//
- // NOTE: Please see the comments of
- // AssociatedGroup.CreateAssociatedInterface() about when you can use this
- // object to make calls.
+ // NOTE: The corresponding AssociatedInterfaceRequest must be sent over
+ // another interface before using this object to make calls. Please see the
+ // comments of MakeRequest(AssociatedInterfacePtr<Interface>*) for more
+ // details.
void Bind(AssociatedInterfacePtrInfo<Interface> info,
scoped_refptr<base::SingleThreadTaskRunner> runner =
base::ThreadTaskRunnerHandle::Get()) {
@@ -197,30 +198,49 @@ class AssociatedInterfacePtr {
DISALLOW_COPY_AND_ASSIGN(AssociatedInterfacePtr);
};
-// Creates an associated interface. The output |ptr| should be used locally
-// while the returned request should be passed through the message pipe endpoint
-// referred to by |associated_group| to setup the corresponding associated
-// interface implementation at the remote side.
+// Creates an associated interface. The returned request is supposed to be sent
+// over another interface (either associated or non-associated).
//
-// NOTE: |ptr| should NOT be used to make calls before the request is sent.
-// Violating that will cause the message pipe to be closed. On the other hand,
-// as soon as the request is sent, |ptr| is usable. There is no need to wait
-// until the request is bound to an implementation at the remote side.
+// NOTE: |ptr| must NOT be used to make calls before the request is sent.
+// Violating that will lead to crash. On the other hand, as soon as the request
+// is sent, |ptr| is usable. There is no need to wait until the request is bound
+// to an implementation at the remote side.
+// TODO(yzshen): Remove the |group| parameter.
template <typename Interface>
AssociatedInterfaceRequest<Interface> MakeRequest(
AssociatedInterfacePtr<Interface>* ptr,
- AssociatedGroup* group,
+ AssociatedGroup* group = nullptr,
scoped_refptr<base::SingleThreadTaskRunner> runner =
base::ThreadTaskRunnerHandle::Get()) {
- AssociatedInterfaceRequest<Interface> request;
AssociatedInterfacePtrInfo<Interface> ptr_info;
- group->CreateAssociatedInterface(AssociatedGroup::WILL_PASS_REQUEST,
- &ptr_info, &request);
-
+ auto request = MakeRequest(&ptr_info);
ptr->Bind(std::move(ptr_info), std::move(runner));
return request;
}
+// Creates an associated interface. One of the two endpoints is supposed to be
+// sent over another interface (either associated or non-associated); while the
+// other is used locally.
+//
+// NOTE: If |ptr_info| is used locally and bound to an AssociatedInterfacePtr,
+// the interface pointer must NOT be used to make calls before the request is
+// sent. Please see NOTE of the previous function for more details.
+template <typename Interface>
+AssociatedInterfaceRequest<Interface> MakeRequest(
+ AssociatedInterfacePtrInfo<Interface>* ptr_info) {
+ ScopedInterfaceEndpointHandle handle0;
+ ScopedInterfaceEndpointHandle handle1;
+ ScopedInterfaceEndpointHandle::CreatePairPendingAssociation(&handle0,
+ &handle1);
+
+ ptr_info->set_handle(std::move(handle0));
+ ptr_info->set_version(0);
+
+ AssociatedInterfaceRequest<Interface> request;
+ request.Bind(std::move(handle1));
+ return request;
+}
+
// Like |GetProxy|, but the interface is never associated with any other
// interface. The returned request can be bound directly to the corresponding
// associated interface implementation, without first passing it through a
« no previous file with comments | « mojo/public/cpp/bindings/associated_binding.h ('k') | mojo/public/cpp/bindings/lib/multiplex_router.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698