Commit 55419f7e authored by Fabrice de Gans-Riberi's avatar Fabrice de Gans-Riberi Committed by Commit Bot

[CastRunner] Use a parameters structure for CastComponent construction.

* Simplify CastComponent constructor to take a single structure.
* Spin-off from https://crrev.com/c/1770434

Bug: 976975
Change-Id: Icb42418bfa60e1b6f34bd3f29f1f1c29d754cf07
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1778915
Commit-Queue: Fabrice de Gans-Riberi <fdegans@chromium.org>
Reviewed-by: default avatarWez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692201}
parent e919a379
......@@ -38,21 +38,22 @@ TouchInputPolicy TouchInputPolicyFromApplicationConfig(
} // namespace
CastComponent::CastComponent(
CastRunner* runner,
chromium::cast::ApplicationConfig application_config,
std::unique_ptr<ApiBindingsClient> api_bindings_client,
std::unique_ptr<base::fuchsia::StartupContext> context,
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
controller_request,
std::unique_ptr<cr_fuchsia::AgentManager> agent_manager)
: WebComponent(runner, std::move(context), std::move(controller_request)),
agent_manager_(std::move(agent_manager)),
application_config_(std::move(application_config)),
CastComponent::CastComponentParams::CastComponentParams() = default;
CastComponent::CastComponentParams::CastComponentParams(CastComponentParams&&) =
default;
CastComponent::CastComponentParams::~CastComponentParams() = default;
CastComponent::CastComponent(CastRunner* runner,
CastComponent::CastComponentParams params)
: WebComponent(runner,
std::move(params.startup_context),
std::move(params.controller_request)),
agent_manager_(std::move(params.agent_manager)),
application_config_(std::move(params.app_config)),
touch_input_policy_(
TouchInputPolicyFromApplicationConfig(application_config_)),
connector_(frame()),
api_bindings_client_(std::move(api_bindings_client)),
api_bindings_client_(std::move(params.api_bindings_client)),
navigation_listener_binding_(this) {
base::AutoReset<bool> constructor_active_reset(&constructor_active_, true);
......
......@@ -9,6 +9,8 @@
#include <memory>
#include "base/fuchsia/service_directory.h"
#include "base/fuchsia/startup_context.h"
#include "base/optional.h"
#include "fuchsia/base/agent_manager.h"
#include "fuchsia/runners/cast/api_bindings_client.h"
#include "fuchsia/runners/cast/application_controller_impl.h"
......@@ -22,13 +24,23 @@ class CastRunner;
class CastComponent : public WebComponent,
public fuchsia::web::NavigationEventListener {
public:
CastComponent(CastRunner* runner,
chromium::cast::ApplicationConfig application_config,
std::unique_ptr<ApiBindingsClient> bindings_manager,
std::unique_ptr<base::fuchsia::StartupContext> startup_context,
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
controller_request,
std::unique_ptr<cr_fuchsia::AgentManager> agent_manager);
struct CastComponentParams {
CastComponentParams();
CastComponentParams(CastComponentParams&&);
~CastComponentParams();
chromium::cast::ApplicationConfigManagerPtr app_config_manager;
std::unique_ptr<base::fuchsia::StartupContext> startup_context;
std::unique_ptr<cr_fuchsia::AgentManager> agent_manager;
std::unique_ptr<ApiBindingsClient> api_bindings_client;
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
controller_request;
chromium::cast::ApplicationConfig app_config;
fuchsia::web::AdditionalHeadersProviderPtr headers_provider;
base::Optional<std::vector<fuchsia::net::http::Header>> headers;
};
CastComponent(CastRunner* runner, CastComponentParams params);
~CastComponent() override;
private:
......
......@@ -10,10 +10,7 @@
#include <utility>
#include "base/fuchsia/fuchsia_logging.h"
#include "base/fuchsia/startup_context.h"
#include "base/logging.h"
#include "fuchsia/base/agent_manager.h"
#include "fuchsia/runners/cast/cast_component.h"
#include "url/gurl.h"
CastRunner::CastRunner(sys::OutgoingDirectory* outgoing_directory,
......@@ -22,17 +19,6 @@ CastRunner::CastRunner(sys::OutgoingDirectory* outgoing_directory,
CastRunner::~CastRunner() = default;
struct CastRunner::PendingComponent {
chromium::cast::ApplicationConfigManagerPtr app_config_manager;
std::unique_ptr<base::fuchsia::StartupContext> startup_context;
std::unique_ptr<cr_fuchsia::AgentManager> agent_manager;
std::unique_ptr<ApiBindingsClient> bindings_manager;
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller_request;
chromium::cast::ApplicationConfig app_config;
fuchsia::web::AdditionalHeadersProviderPtr headers_provider;
base::Optional<std::vector<fuchsia::net::http::Header>> headers;
};
void CastRunner::StartComponent(
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
......@@ -54,7 +40,8 @@ void CastRunner::StartComponent(
// The application configuration asynchronously via the per-component
// ApplicationConfigManager, the pointer to that service must be kept live
// until the request completes, or CastRunner is deleted.
auto pending_component = std::make_unique<PendingComponent>();
auto pending_component =
std::make_unique<CastComponent::CastComponentParams>();
pending_component->startup_context =
std::make_unique<base::fuchsia::StartupContext>(std::move(startup_info));
pending_component->agent_manager = std::make_unique<cr_fuchsia::AgentManager>(
......@@ -75,7 +62,7 @@ void CastRunner::StartComponent(
fidl::InterfaceHandle<chromium::cast::ApiBindings> api_bindings_client;
pending_component->agent_manager->ConnectToAgentService(
kAgentComponentUrl, api_bindings_client.NewRequest());
pending_component->bindings_manager = std::make_unique<ApiBindingsClient>(
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())));
......@@ -116,12 +103,8 @@ const char CastRunner::kAgentComponentUrl[] =
"fuchsia-pkg://fuchsia.com/cast_agent#meta/cast_agent.cmx";
void CastRunner::GetConfigCallback(
PendingComponent* pending_component,
CastComponent::CastComponentParams* pending_component,
chromium::cast::ApplicationConfig app_config) {
// Ideally the PendingComponent would be move()d out of |pending_components_|
// here, but that requires extract(), which isn't available until C++17.
// Instead find |pending_component| and move() the individual fields out
// before erase()ing it.
auto it = pending_components_.find(pending_component);
DCHECK(it != pending_components_.end());
......@@ -137,25 +120,23 @@ void CastRunner::GetConfigCallback(
MaybeStartComponent(pending_component);
}
void CastRunner::MaybeStartComponent(PendingComponent* pending_component) {
void CastRunner::MaybeStartComponent(
CastComponent::CastComponentParams* pending_component) {
if (pending_component->app_config.IsEmpty())
return;
if (!pending_component->bindings_manager->HasBindings())
if (!pending_component->api_bindings_client->HasBindings())
return;
if (!pending_component->headers.has_value())
return;
// Create a component based on the returned configuration, and pass it the
// fields stashed in PendingComponent.
GURL cast_app_url(pending_component->app_config.web_url());
auto component = std::make_unique<CastComponent>(
this, std::move(pending_component->app_config),
std::move(pending_component->bindings_manager),
std::move(pending_component->startup_context),
std::move(pending_component->controller_request),
std::move(pending_component->agent_manager));
// |pending_component|.
std::vector<fuchsia::net::http::Header> additional_headers =
pending_component->headers.value();
GURL cast_app_url(pending_component->app_config.web_url());
auto component =
std::make_unique<CastComponent>(this, std::move(*pending_component));
pending_components_.erase(pending_component);
component->LoadUrl(std::move(cast_app_url), std::move(additional_headers));
......
......@@ -14,6 +14,7 @@
#include "base/containers/unique_ptr_adapters.h"
#include "base/macros.h"
#include "fuchsia/fidl/chromium/cast/cpp/fidl.h"
#include "fuchsia/runners/cast/cast_component.h"
#include "fuchsia/runners/common/web_content_runner.h"
// sys::Runner which instantiates Cast activities specified via cast/casts URIs.
......@@ -34,19 +35,20 @@ class CastRunner : public WebContentRunner {
static const char kAgentComponentUrl[];
private:
struct PendingComponent;
void GetConfigCallback(PendingComponent* pending_component,
void GetConfigCallback(CastComponent::CastComponentParams* pending_component,
chromium::cast::ApplicationConfig app_config);
void GetBindingsCallback(PendingComponent* pending_component,
std::vector<chromium::cast::ApiBinding> bindings);
void GetBindingsCallback(
CastComponent::CastComponentParams* pending_component,
std::vector<chromium::cast::ApiBinding> bindings);
// Starts a component once all configuration data is available.
void MaybeStartComponent(PendingComponent* pending_component);
void MaybeStartComponent(
CastComponent::CastComponentParams* pending_component);
// Holds StartComponent() requests while the ApplicationConfig is being
// fetched from the ApplicationConfigManager.
base::flat_set<std::unique_ptr<PendingComponent>, base::UniquePtrComparator>
base::flat_set<std::unique_ptr<CastComponent::CastComponentParams>,
base::UniquePtrComparator>
pending_components_;
DISALLOW_COPY_AND_ASSIGN(CastRunner);
......
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