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

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

Issue 2646853003: Mojo C++ bindings: Simplify associated interface API. (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
Index: mojo/public/cpp/bindings/associated_group.h
diff --git a/mojo/public/cpp/bindings/associated_group.h b/mojo/public/cpp/bindings/associated_group.h
index b1c692acd2393cb4052cf33747863122078e28dc..21d6fcbf2dde4452ce1c90ce8898b42dd0dbca3a 100644
--- a/mojo/public/cpp/bindings/associated_group.h
+++ b/mojo/public/cpp/bindings/associated_group.h
@@ -5,8 +5,7 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_
#define MOJO_PUBLIC_CPP_BINDINGS_ASSOCIATED_GROUP_H_
-#include <utility>
-
+#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "mojo/public/cpp/bindings/associated_interface_ptr_info.h"
#include "mojo/public/cpp/bindings/associated_interface_request.h"
@@ -18,22 +17,37 @@ namespace mojo {
class AssociatedGroupController;
// AssociatedGroup refers to all the interface endpoints running at one end of a
-// message pipe. It is used to create associated interfaces for that message
-// pipe.
+// message pipe.
// It is thread safe and cheap to make copies.
class MOJO_CPP_BINDINGS_EXPORT AssociatedGroup {
public:
- // Configuration used by CreateAssociatedInterface(). Please see the comments
- // of that method for more details.
- enum AssociatedInterfaceConfig { WILL_PASS_PTR, WILL_PASS_REQUEST };
-
AssociatedGroup();
+
+ explicit AssociatedGroup(scoped_refptr<AssociatedGroupController> controller);
+
+ explicit AssociatedGroup(const ScopedInterfaceEndpointHandle& handle);
+
AssociatedGroup(const AssociatedGroup& other);
~AssociatedGroup();
AssociatedGroup& operator=(const AssociatedGroup& other);
+ // The return value of this getter if this object is initialized with a
+ // ScopedInterfaceEndpointHandle:
+ // - If the handle is invalid, the return value will always be null.
+ // - If the handle is valid and non-pending, the return value will be
+ // non-null and remain unchanged even if the handle is later reset.
+ // - If the handle is pending asssociation, the return value will initially
+ // be null, change to non-null when/if the handle is associated, and
+ // remain unchanged ever since.
+ AssociatedGroupController* GetController();
+
+ // TODO(yzshen): Remove the following public method. It is not needed anymore.
+ // Configuration used by CreateAssociatedInterface(). Please see the comments
+ // of that method for more details.
+ enum AssociatedInterfaceConfig { WILL_PASS_PTR, WILL_PASS_REQUEST };
+
// |config| indicates whether |ptr_info| or |request| will be sent to the
// remote side of the message pipe.
//
@@ -45,44 +59,30 @@ class MOJO_CPP_BINDINGS_EXPORT AssociatedGroup {
// no need to wait until |request| is bound to an implementation at the remote
// side.
template <typename T>
- void CreateAssociatedInterface(
- AssociatedInterfaceConfig config,
- AssociatedInterfacePtrInfo<T>* ptr_info,
- AssociatedInterfaceRequest<T>* request) {
- ScopedInterfaceEndpointHandle local;
- ScopedInterfaceEndpointHandle remote;
- CreateEndpointHandlePair(&local, &remote);
-
- if (!local.is_valid() || !remote.is_valid()) {
- *ptr_info = AssociatedInterfacePtrInfo<T>();
- *request = AssociatedInterfaceRequest<T>();
- return;
- }
+ void CreateAssociatedInterface(AssociatedInterfaceConfig config,
+ AssociatedInterfacePtrInfo<T>* ptr_info,
+ AssociatedInterfaceRequest<T>* request) {
+ ScopedInterfaceEndpointHandle handle0;
+ ScopedInterfaceEndpointHandle handle1;
+ ScopedInterfaceEndpointHandle::CreatePairPendingAssociation(&handle0,
+ &handle1);
- if (config == WILL_PASS_PTR) {
- ptr_info->set_handle(std::move(remote));
+ ptr_info->set_handle(std::move(handle0));
+ request->Bind(std::move(handle1));
+ if (config == WILL_PASS_PTR) {
// The implementation is local, therefore set the version according to
// the interface definition that this code is built against.
ptr_info->set_version(T::Version_);
- request->Bind(std::move(local));
} else {
- ptr_info->set_handle(std::move(local));
-
// The implementation is remote, we don't know about its actual version
// yet.
ptr_info->set_version(0u);
- request->Bind(std::move(remote));
}
}
private:
- friend class AssociatedGroupController;
-
- void CreateEndpointHandlePair(
- ScopedInterfaceEndpointHandle* local_endpoint,
- ScopedInterfaceEndpointHandle* remote_endpoint);
-
+ base::Callback<AssociatedGroupController*()> controller_getter_;
scoped_refptr<AssociatedGroupController> controller_;
};
« no previous file with comments | « mojo/public/cpp/bindings/associated_binding.h ('k') | mojo/public/cpp/bindings/associated_group_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698