From 2e74a6ba2050f8041ffb39c5bfdbcd8069f77c04 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Tue, 6 Jun 2017 16:05:00 -0700 Subject: [PATCH] Add support for PA_SERVICE_REQUEST (#3746) This patch adds support for the new way of exposing services from applications. --- content_handler/BUILD.gn | 1 + .../application_controller_impl.cc | 31 ++++++++++--------- content_handler/application_controller_impl.h | 10 ++---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/content_handler/BUILD.gn b/content_handler/BUILD.gn index 942ae1f026aa6..222ca6700f293 100644 --- a/content_handler/BUILD.gn +++ b/content_handler/BUILD.gn @@ -42,6 +42,7 @@ template("flutter_content_handler") { deps = [ "//application/lib/app", + "//application/lib/svc", "//apps/icu_data/lib", "//apps/mozart/lib/flutter/sdk_ext", "//apps/mozart/lib/skia:vmo", diff --git a/content_handler/application_controller_impl.cc b/content_handler/application_controller_impl.cc index 8b31f4f329328..57fdf064be66e 100644 --- a/content_handler/application_controller_impl.cc +++ b/content_handler/application_controller_impl.cc @@ -38,15 +38,29 @@ ApplicationControllerImpl::ApplicationControllerImpl( // startup handles. if (startup_info->launch_info->services) { - service_provider_bindings_.AddBinding( - this, std::move(startup_info->launch_info->services)); + service_provider_bridge_.AddBinding( + std::move(startup_info->launch_info->services)); } + if (startup_info->launch_info->service_request.is_valid()) { + service_provider_bridge_.ServeDirectory( + std::move(startup_info->launch_info->service_request)); + } + + service_provider_bridge_.AddService( + [this](fidl::InterfaceRequest request) { + view_provider_bindings_.AddBinding(this, std::move(request)); + }); + + app::ServiceProviderPtr service_provider; + auto request = service_provider.NewRequest(); + service_provider_bridge_.set_backend(std::move(service_provider)); + url_ = startup_info->launch_info->url; runtime_holder_.reset(new RuntimeHolder()); runtime_holder_->Init( app::ApplicationContext::CreateFrom(std::move(startup_info)), - fidl::GetProxy(&dart_service_provider_), std::move(bundle)); + std::move(request), std::move(bundle)); } ApplicationControllerImpl::~ApplicationControllerImpl() = default; @@ -61,17 +75,6 @@ void ApplicationControllerImpl::Detach() { binding_.set_connection_error_handler(ftl::Closure()); } -void ApplicationControllerImpl::ConnectToService( - const fidl::String& service_name, - mx::channel channel) { - if (service_name == mozart::ViewProvider::Name_) { - view_provider_bindings_.AddBinding( - this, fidl::InterfaceRequest(std::move(channel))); - } else { - dart_service_provider_->ConnectToService(service_name, std::move(channel)); - } -} - void ApplicationControllerImpl::CreateView( fidl::InterfaceRequest view_owner_request, fidl::InterfaceRequest services) { diff --git a/content_handler/application_controller_impl.h b/content_handler/application_controller_impl.h index ddcc3634ac1c0..16a6e9cff1830 100644 --- a/content_handler/application_controller_impl.h +++ b/content_handler/application_controller_impl.h @@ -7,6 +7,7 @@ #include +#include "application/lib/svc/service_provider_bridge.h" #include "application/services/application_controller.fidl.h" #include "application/services/application_runner.fidl.h" #include "application/services/service_provider.fidl.h" @@ -22,7 +23,6 @@ class App; class RuntimeHolder; class ApplicationControllerImpl : public app::ApplicationController, - public app::ServiceProvider, public mozart::ViewProvider { public: ApplicationControllerImpl( @@ -38,11 +38,6 @@ class ApplicationControllerImpl : public app::ApplicationController, void Kill() override; void Detach() override; - // |app::ServiceProvider| implementation - - void ConnectToService(const fidl::String& service_name, - mx::channel channel) override; - // |mozart::ViewProvider| implementation void CreateView( @@ -58,8 +53,7 @@ class ApplicationControllerImpl : public app::ApplicationController, App* app_; fidl::Binding binding_; - fidl::BindingSet service_provider_bindings_; - app::ServiceProviderPtr dart_service_provider_; + app::ServiceProviderBridge service_provider_bridge_; fidl::BindingSet view_provider_bindings_;