Commit 071092e3 authored by Connor Lange's avatar Connor Lange Committed by Commit Bot

[Fuchsia] Update cast_runner to handle multiple agents.

Update cast_runner to delay connections for bindings and rewrite rules
until after the AppConfig is returned. This AppConfig will now contain
the agent_url, which will be used to contact the correct agent for
bindings, etc.

Bug: b/141573972
Test: cast_runner_integration_tests, Launch application

Change-Id: Ida6966fba6039fc2f9ea9d7c136711d13a0a5a2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895401Reviewed-by: default avatarWez <wez@chromium.org>
Commit-Queue: Connor Lange <connorl@chromium.org>
Auto-Submit: Connor Lange <connorl@chromium.org>
Cr-Commit-Position: refs/heads/master@{#722625}
parent 5e294641
...@@ -20,17 +20,30 @@ FakeComponentContext::FakeComponentContext( ...@@ -20,17 +20,30 @@ FakeComponentContext::FakeComponentContext(
sys::OutgoingDirectory* outgoing_directory, sys::OutgoingDirectory* outgoing_directory,
base::StringPiece component_url) base::StringPiece component_url)
: binding_(outgoing_directory, this), : binding_(outgoing_directory, this),
// Publishing the Agent to |outgoing_directory| is not necessary, but component_url_(component_url.as_string()),
// also shouldn't do any harm. outgoing_directory_(outgoing_directory),
agent_impl_(outgoing_directory, default_agent_impl_(outgoing_directory,
std::move(create_component_state_callback)), std::move(create_component_state_callback)) {}
component_url_(component_url.as_string()) {}
void FakeComponentContext::RegisterCreateComponentStateCallback(
base::StringPiece agent_url,
AgentImpl::CreateComponentStateCallback create_component_state_callback) {
agent_impl_map_.insert(std::make_pair(
agent_url,
std::make_unique<AgentImpl>(outgoing_directory_,
std::move(create_component_state_callback))));
}
void FakeComponentContext::ConnectToAgent( void FakeComponentContext::ConnectToAgent(
std::string agent_url, std::string agent_url,
fidl::InterfaceRequest<::fuchsia::sys::ServiceProvider> services, fidl::InterfaceRequest<::fuchsia::sys::ServiceProvider> services,
fidl::InterfaceRequest<fuchsia::modular::AgentController> controller) { fidl::InterfaceRequest<fuchsia::modular::AgentController> controller) {
agent_impl_.Connect(component_url_, std::move(services)); auto it = agent_impl_map_.find(agent_url);
if (it == agent_impl_map_.end()) {
default_agent_impl_.Connect(component_url_, std::move(services));
} else {
it->second->Connect(component_url_, std::move(services));
}
} }
void FakeComponentContext::ConnectToAgentService( void FakeComponentContext::ConnectToAgentService(
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <fuchsia/base/agent_impl.h> #include <fuchsia/base/agent_impl.h>
#include <fuchsia/modular/cpp/fidl_test_base.h> #include <fuchsia/modular/cpp/fidl_test_base.h>
#include <map>
#include <memory> #include <memory>
#include <string> #include <string>
#include <utility> #include <utility>
...@@ -31,6 +32,10 @@ class FakeComponentContext ...@@ -31,6 +32,10 @@ class FakeComponentContext
base::StringPiece component_url); base::StringPiece component_url);
~FakeComponentContext() override; ~FakeComponentContext() override;
void RegisterCreateComponentStateCallback(
base::StringPiece agent_url,
AgentImpl::CreateComponentStateCallback callback);
// fuchsia::modular::ComponentContext_TestBase implementation. // fuchsia::modular::ComponentContext_TestBase implementation.
void ConnectToAgent( void ConnectToAgent(
std::string agent_url, std::string agent_url,
...@@ -44,10 +49,13 @@ class FakeComponentContext ...@@ -44,10 +49,13 @@ class FakeComponentContext
private: private:
base::fuchsia::ScopedServiceBinding<fuchsia::modular::ComponentContext> base::fuchsia::ScopedServiceBinding<fuchsia::modular::ComponentContext>
binding_; binding_;
AgentImpl agent_impl_;
const std::string component_url_; const std::string component_url_;
sys::OutgoingDirectory* const outgoing_directory_;
fuchsia::sys::ServiceProviderPtr agent_services_; fuchsia::sys::ServiceProviderPtr agent_services_;
std::map<base::StringPiece, std::unique_ptr<AgentImpl>> agent_impl_map_;
AgentImpl default_agent_impl_;
DISALLOW_COPY_AND_ASSIGN(FakeComponentContext); DISALLOW_COPY_AND_ASSIGN(FakeComponentContext);
}; };
......
...@@ -101,38 +101,9 @@ void CastRunner::StartComponent( ...@@ -101,38 +101,9 @@ void CastRunner::StartComponent(
pending_component->startup_context->component_context()->svc().get()); pending_component->startup_context->component_context()->svc().get());
pending_component->controller_request = std::move(controller_request); pending_component->controller_request = std::move(controller_request);
// Get binding details from the Agent. // Request the configuration for this application from the app_config_manager.
fidl::InterfaceHandle<chromium::cast::ApiBindings> api_bindings_client; // This will return the configuration for the application, as well as the
pending_component->agent_manager->ConnectToAgentService( // agent that should handle this application.
kAgentComponentUrl, api_bindings_client.NewRequest());
pending_component->api_bindings_client = std::make_unique<ApiBindingsClient>(
std::move(api_bindings_client),
base::BindOnce(&CastRunner::MaybeStartComponent, base::Unretained(this),
base::Unretained(pending_component.get())),
base::BindOnce(&CastRunner::CancelComponentLaunch, base::Unretained(this),
base::Unretained(pending_component.get())));
// Get UrlRequestRewriteRulesProvider from the Agent.
fidl::InterfaceHandle<chromium::cast::UrlRequestRewriteRulesProvider>
url_request_rules_provider;
pending_component->agent_manager->ConnectToAgentService(
kAgentComponentUrl, url_request_rules_provider.NewRequest());
pending_component->rewrite_rules_provider = url_request_rules_provider.Bind();
pending_component->rewrite_rules_provider.set_error_handler(
[this, pending_component = pending_component.get()](zx_status_t status) {
ZX_LOG(ERROR, status) << "UrlRequestRewriteRulesProvider disconnected.";
CancelComponentLaunch(pending_component);
});
pending_component->rewrite_rules_provider->GetUrlRequestRewriteRules(
[this, pending_component = pending_component.get()](
std::vector<fuchsia::web::UrlRequestRewriteRule> rewrite_rules) {
pending_component->rewrite_rules =
base::Optional<std::vector<fuchsia::web::UrlRequestRewriteRule>>(
std::move(rewrite_rules));
MaybeStartComponent(pending_component);
});
// Request the configuration for the specified application.
pending_component->agent_manager->ConnectToAgentService( pending_component->agent_manager->ConnectToAgentService(
kAgentComponentUrl, pending_component->app_config_manager.NewRequest()); kAgentComponentUrl, pending_component->app_config_manager.NewRequest());
pending_component->app_config_manager.set_error_handler( pending_component->app_config_manager.set_error_handler(
...@@ -199,9 +170,43 @@ void CastRunner::GetConfigCallback( ...@@ -199,9 +170,43 @@ void CastRunner::GetConfigCallback(
return; return;
} }
if (!app_config.has_agent_url()) {
pending_components_.erase(it);
DLOG(WARNING) << "No agent has been associated with this app.";
return;
}
pending_component->app_config = std::move(app_config); pending_component->app_config = std::move(app_config);
// Request binding details from the Agent.
fidl::InterfaceHandle<chromium::cast::ApiBindings> api_bindings_client;
pending_component->agent_manager->ConnectToAgentService(
pending_component->app_config.agent_url(),
api_bindings_client.NewRequest());
pending_component->api_bindings_client = std::make_unique<ApiBindingsClient>(
std::move(api_bindings_client),
base::BindOnce(&CastRunner::MaybeStartComponent, base::Unretained(this),
base::Unretained(pending_component)),
base::BindOnce(&CastRunner::CancelComponentLaunch, base::Unretained(this),
base::Unretained(pending_component)));
// Request UrlRequestRewriteRulesProvider from the Agent.
pending_component->agent_manager->ConnectToAgentService(
kAgentComponentUrl,
pending_component->rewrite_rules_provider.NewRequest());
pending_component->rewrite_rules_provider.set_error_handler(
[this, pending_component = pending_component](zx_status_t status) {
ZX_LOG(ERROR, status) << "UrlRequestRewriteRulesProvider disconnected.";
CancelComponentLaunch(pending_component);
});
pending_component->rewrite_rules_provider->GetUrlRequestRewriteRules(
[this, pending_component = pending_component](
std::vector<fuchsia::web::UrlRequestRewriteRule> rewrite_rules) {
pending_component->rewrite_rules =
base::Optional<std::vector<fuchsia::web::UrlRequestRewriteRule>>(
std::move(rewrite_rules));
MaybeStartComponent(pending_component); MaybeStartComponent(pending_component);
});
} }
void CastRunner::MaybeStartComponent( void CastRunner::MaybeStartComponent(
......
...@@ -9,6 +9,11 @@ ...@@ -9,6 +9,11 @@
#include "base/logging.h" #include "base/logging.h"
namespace {
const char kAgentComponentUrl[] =
"fuchsia-pkg://fuchsia.com/cast_agent#meta/cast_agent.cmx";
} // namespace
FakeApplicationConfigManager::FakeApplicationConfigManager() = default; FakeApplicationConfigManager::FakeApplicationConfigManager() = default;
FakeApplicationConfigManager::~FakeApplicationConfigManager() = default; FakeApplicationConfigManager::~FakeApplicationConfigManager() = default;
...@@ -28,11 +33,20 @@ void FakeApplicationConfigManager::GetConfig(std::string id, ...@@ -28,11 +33,20 @@ void FakeApplicationConfigManager::GetConfig(std::string id,
void FakeApplicationConfigManager::AddAppMapping(const std::string& id, void FakeApplicationConfigManager::AddAppMapping(const std::string& id,
const GURL& url, const GURL& url,
bool enable_remote_debugging) { bool enable_remote_debugging) {
AddAppMappingWithAgent(id, url, enable_remote_debugging, kAgentComponentUrl);
}
void FakeApplicationConfigManager::AddAppMappingWithAgent(
const std::string& id,
const GURL& url,
bool enable_remote_debugging,
const std::string& agent_url) {
chromium::cast::ApplicationConfig app_config; chromium::cast::ApplicationConfig app_config;
app_config.set_id(id); app_config.set_id(id);
app_config.set_display_name("Dummy test app"); app_config.set_display_name("Dummy test app");
app_config.set_web_url(url.spec()); app_config.set_web_url(url.spec());
app_config.set_enable_remote_debugging(enable_remote_debugging); app_config.set_enable_remote_debugging(enable_remote_debugging);
app_config.set_agent_url(agent_url);
id_to_config_[id] = std::move(app_config); id_to_config_[id] = std::move(app_config);
} }
...@@ -44,6 +58,7 @@ void FakeApplicationConfigManager::AddAppMappingWithContentDirectories( ...@@ -44,6 +58,7 @@ void FakeApplicationConfigManager::AddAppMappingWithContentDirectories(
app_config.set_id(id); app_config.set_id(id);
app_config.set_display_name("Dummy test app"); app_config.set_display_name("Dummy test app");
app_config.set_web_url(url.spec()); app_config.set_web_url(url.spec());
app_config.set_agent_url(kAgentComponentUrl);
if (!directories.empty()) { if (!directories.empty()) {
app_config.set_content_directories_for_isolated_application( app_config.set_content_directories_for_isolated_application(
std::move(directories)); std::move(directories));
......
...@@ -27,6 +27,13 @@ class FakeApplicationConfigManager ...@@ -27,6 +27,13 @@ class FakeApplicationConfigManager
const GURL& url, const GURL& url,
bool enable_remote_debugging); bool enable_remote_debugging);
// Associates a Cast application |id| with a url and an agent that handles
// its bindings, to be served from the EmbeddedTestServer.
void AddAppMappingWithAgent(const std::string& id,
const GURL& url,
bool enable_remote_debugging,
const std::string& agent_url);
// Associates a Cast application |id| with a url and a set of content // Associates a Cast application |id| with a url and a set of content
// directories, to be served from the EmbeddedTestServer. // directories, to be served from the EmbeddedTestServer.
void AddAppMappingWithContentDirectories( void AddAppMappingWithContentDirectories(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment