diff options
Diffstat (limited to 'chromium/content/common/associated_interface_provider_impl.cc')
-rw-r--r-- | chromium/content/common/associated_interface_provider_impl.cc | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/chromium/content/common/associated_interface_provider_impl.cc b/chromium/content/common/associated_interface_provider_impl.cc index c42ff3f15e0..3154596fba2 100644 --- a/chromium/content/common/associated_interface_provider_impl.cc +++ b/chromium/content/common/associated_interface_provider_impl.cc @@ -3,14 +3,70 @@ // 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 { +class AssociatedInterfaceProviderImpl::LocalProvider + : public mojom::RouteProvider, + mojom::AssociatedInterfaceProvider { + public: + explicit LocalProvider(mojom::AssociatedInterfaceProviderAssociatedPtr* proxy) + : route_provider_binding_(this), + associated_interface_provider_binding_(this) { + route_provider_binding_.Bind(mojo::GetProxy(&route_provider_ptr_)); + route_provider_ptr_->GetRoute( + 0, mojo::GetProxy(proxy, route_provider_ptr_.associated_group())); + } + + ~LocalProvider() override {} + + void SetBinderForName( + const std::string& name, + const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) { + binders_[name] = binder; + } + + 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 { + 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_; + + mojom::RouteProviderPtr route_provider_ptr_; + mojo::Binding<mojom::RouteProvider> route_provider_binding_; + + mojo::AssociatedBinding<mojom::AssociatedInterfaceProvider> + associated_interface_provider_binding_; +}; + AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl( mojom::AssociatedInterfaceProviderAssociatedPtr proxy) : proxy_(std::move(proxy)) { + DCHECK(proxy_.is_bound()); } +AssociatedInterfaceProviderImpl::AssociatedInterfaceProviderImpl() + : local_provider_(new LocalProvider(&proxy_)) {} + AssociatedInterfaceProviderImpl::~AssociatedInterfaceProviderImpl() {} void AssociatedInterfaceProviderImpl::GetInterface( @@ -25,4 +81,11 @@ mojo::AssociatedGroup* AssociatedInterfaceProviderImpl::GetAssociatedGroup() { return proxy_.associated_group(); } +void AssociatedInterfaceProviderImpl::OverrideBinderForTesting( + const std::string& name, + const base::Callback<void(mojo::ScopedInterfaceEndpointHandle)>& binder) { + DCHECK(local_provider_); + local_provider_->SetBinderForName(name, binder); +} + } // namespace content |