Index: content/common/associated_interface_provider_impl.cc |
diff --git a/content/common/associated_interface_provider_impl.cc b/content/common/associated_interface_provider_impl.cc |
index c42ff3f15e090f5ca7a33a7ddeb66f68118a0a29..9db820c45eb05432989b296bda8369e78cc51bd8 100644 |
--- a/content/common/associated_interface_provider_impl.cc |
+++ b/content/common/associated_interface_provider_impl.cc |
@@ -3,12 +3,72 @@ |
// found in the LICENSE file. |
#include "content/common/associated_interface_provider_impl.h" |
+#include "mojo/public/cpp/bindings/associated_binding.h" |
+#include "mojo/public/cpp/bindings/binding.h" |
namespace content { |
+namespace { |
+ |
+class LocalProvider : public mojom::RouteProvider, |
+ mojom::AssociatedInterfaceProvider { |
+ public: |
+ explicit LocalProvider(mojom::RouteProviderRequest request) |
+ : route_provider_binding_(this, std::move(request)), |
+ associated_interface_provider_binding_(this) {} |
+ ~LocalProvider() override {} |
+ |
+ void SetBinderForName( |
+ const std::string& name, |
+ const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) { |
+ binders_[name] = binder; |
+ } |
+ |
+ void ClearBinders() { binders_.clear(); } |
+ |
+ private: |
+ // mojom::RouteProvider: |
+ void GetRoute( |
+ int32_t routing_id, |
+ mojom::AssociatedInterfaceProviderAssociatedRequest request) override { |
+ DCHECK(request.is_pending()); |
+ associated_interface_provider_binding_.Bind(std::move(request)); |
+ } |
+ |
+ // mojom::AssociatedInterfaceProvider: |
+ void GetAssociatedInterface( |
+ const std::string& name, |
+ mojom::AssociatedInterfaceAssociatedRequest request) override { |
+ // Local binders can be registered via TestApi. |
+ auto it = binders_.find(name); |
+ if (it != binders_.end()) |
+ it->second.Run(request.PassHandle()); |
+ } |
+ |
+ using BinderMap = |
+ std::map<std::string, |
+ base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>>; |
+ BinderMap binders_; |
+ |
+ mojo::Binding<mojom::RouteProvider> route_provider_binding_; |
+ |
+ mojo::AssociatedBinding<mojom::AssociatedInterfaceProvider> |
+ associated_interface_provider_binding_; |
+}; |
+ |
+} // namespace |
+ |
AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl( |
mojom::AssociatedInterfaceProviderAssociatedPtr proxy) |
: proxy_(std::move(proxy)) { |
+ DCHECK(proxy_.is_bound()); |
+} |
+ |
+AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl() { |
+ mojom::RouteProviderPtr route_provider_ptr; |
+ local_provider_.reset(new LocalProvider(mojo::GetProxy(&route_provider_ptr))); |
+ route_provider_ptr->GetRoute( |
+ 0, mojo::GetProxy(&proxy_, route_provider_ptr.associated_group())); |
} |
AssociatedInterfaceProviderImpl::~AssociatedInterfaceProviderImpl() {} |
@@ -25,4 +85,16 @@ mojo::AssociatedGroup* AssociatedInterfaceProviderImpl::GetAssociatedGroup() { |
return proxy_.associated_group(); |
} |
+void AssociatedInterfaceProviderImpl::SetBinderForName( |
+ const std::string& name, |
+ const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) { |
+ DCHECK(local_provider_); |
+ local_provider_->SetBinderForName(name, binder); |
+} |
+ |
+void AssociatedInterfaceProviderImpl::ClearBinders() { |
+ DCHECK(local_provider_); |
+ local_provider_->ClearBinders(); |
+} |
+ |
} // namespace content |