Commit 4e3dbc1a authored by Wez's avatar Wez Committed by Commit Bot

[Fuchsia] Update CastRunner to use ComponentContext to find services.

Previously CastRunner would look for Agent-provided services (e.g.
CastChannel) in the service namespace supplied on component launch.

If a ComponentContext is found in the service namespace passed to
StartComponent() then the CastRunner will now use that to connect to
the CastAgent to find Cast-specific services.

This requires temporary work-arounds e.g. to fall-back to looking at
the "additional services" provided in the component's StartupInfo,
until we migrate to the new component-manager APIs.

Bug: 920920, 893229
Change-Id: I43aec5c47bc24a0d2a537de621b20fad3342a5f8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1472333
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: default avatarKevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#638215}
parent 4c871189
...@@ -26,7 +26,7 @@ StartupContext::StartupContext(::fuchsia::sys::StartupInfo startup_info) ...@@ -26,7 +26,7 @@ StartupContext::StartupContext(::fuchsia::sys::StartupInfo startup_info)
} }
} }
// TODO(https://crbug.com/933834): Remove this workaround when we migrate to // TODO(https://crbug.com/933834): Remove these workarounds when we migrate to
// the new component manager. // the new component manager.
if (!incoming_services_ && startup_info_.launch_info.flat_namespace) { if (!incoming_services_ && startup_info_.launch_info.flat_namespace) {
LOG(WARNING) << "Falling back to LaunchInfo namespace"; LOG(WARNING) << "Falling back to LaunchInfo namespace";
...@@ -40,6 +40,28 @@ StartupContext::StartupContext(::fuchsia::sys::StartupInfo startup_info) ...@@ -40,6 +40,28 @@ StartupContext::StartupContext(::fuchsia::sys::StartupInfo startup_info)
} }
} }
} }
if (!incoming_services_ && startup_info_.launch_info.additional_services) {
LOG(WARNING) << "Falling back to additional ServiceList services";
// Construct a ServiceDirectory and publish the additional services into it.
fidl::InterfaceHandle<::fuchsia::io::Directory> incoming_directory;
additional_services_.Bind(
std::move(startup_info_.launch_info.additional_services->provider));
additional_services_directory_ =
std::make_unique<base::fuchsia::ServiceDirectory>(
incoming_directory.NewRequest());
for (auto& name : startup_info_.launch_info.additional_services->names) {
additional_services_directory_->AddServiceUnsafe(
name, base::BindRepeating(
&::fuchsia::sys::ServiceProvider::ConnectToService,
base::Unretained(additional_services_.get()), name));
}
// Publish those services to the caller as |incoming_services_|.
incoming_services_ = std::make_unique<ServiceDirectoryClient>(
fidl::InterfaceHandle<::fuchsia::io::Directory>(
std::move(incoming_directory)));
}
} }
StartupContext::~StartupContext() = default; StartupContext::~StartupContext() = default;
......
...@@ -28,6 +28,7 @@ class BASE_EXPORT StartupContext { ...@@ -28,6 +28,7 @@ class BASE_EXPORT StartupContext {
// Returns the namespace of services published for use by the component. // Returns the namespace of services published for use by the component.
const ServiceDirectoryClient* incoming_services() const { const ServiceDirectoryClient* incoming_services() const {
DCHECK(incoming_services_);
return incoming_services_.get(); return incoming_services_.get();
} }
...@@ -43,6 +44,11 @@ class BASE_EXPORT StartupContext { ...@@ -43,6 +44,11 @@ class BASE_EXPORT StartupContext {
std::unique_ptr<ServiceDirectoryClient> incoming_services_; std::unique_ptr<ServiceDirectoryClient> incoming_services_;
std::unique_ptr<ServiceDirectory> public_services_; std::unique_ptr<ServiceDirectory> public_services_;
// TODO(https://crbug.com/933834): Remove these when we migrate to the new
// component manager APIs.
::fuchsia::sys::ServiceProviderPtr additional_services_;
std::unique_ptr<ServiceDirectory> additional_services_directory_;
DISALLOW_COPY_AND_ASSIGN(StartupContext); DISALLOW_COPY_AND_ASSIGN(StartupContext);
}; };
......
...@@ -9,15 +9,20 @@ ...@@ -9,15 +9,20 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/logging.h"
namespace cr_fuchsia { namespace cr_fuchsia {
FakeComponentContext::FakeComponentContext( FakeComponentContext::FakeComponentContext(
AgentImpl::CreateComponentStateCallback create_component_state_callback, AgentImpl::CreateComponentStateCallback create_component_state_callback,
base::fuchsia::ServiceDirectory* service_directory, base::fuchsia::ServiceDirectory* service_directory,
std::string component_url) base::StringPiece component_url)
: agent_impl_(service_directory, : binding_(service_directory, this),
// Publishing the Agent to |service_directory| is not necessary, but
// also shouldn't do any harm.
agent_impl_(service_directory,
std::move(create_component_state_callback)), std::move(create_component_state_callback)),
component_url_(component_url) {} component_url_(component_url.as_string()) {}
void FakeComponentContext::ConnectToAgent( void FakeComponentContext::ConnectToAgent(
std::string agent_url, std::string agent_url,
...@@ -26,6 +31,10 @@ void FakeComponentContext::ConnectToAgent( ...@@ -26,6 +31,10 @@ void FakeComponentContext::ConnectToAgent(
agent_impl_.Connect(component_url_, std::move(services)); agent_impl_.Connect(component_url_, std::move(services));
} }
void FakeComponentContext::NotImplemented_(const std::string& name) {
NOTIMPLEMENTED() << " API: " << name;
}
FakeComponentContext::~FakeComponentContext() = default; FakeComponentContext::~FakeComponentContext() = default;
} // namespace cr_fuchsia } // namespace cr_fuchsia
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include <string> #include <string>
#include <utility> #include <utility>
#include "base/strings/string_piece.h"
namespace cr_fuchsia { namespace cr_fuchsia {
// Used to test interactions with an Agent in unit-tests for a component. // Used to test interactions with an Agent in unit-tests for a component.
...@@ -26,17 +28,20 @@ class FakeComponentContext ...@@ -26,17 +28,20 @@ class FakeComponentContext
explicit FakeComponentContext( explicit FakeComponentContext(
AgentImpl::CreateComponentStateCallback create_component_state_callback, AgentImpl::CreateComponentStateCallback create_component_state_callback,
base::fuchsia::ServiceDirectory* service_directory, base::fuchsia::ServiceDirectory* service_directory,
std::string component_url); base::StringPiece component_url);
~FakeComponentContext() override; ~FakeComponentContext() override;
// fuchsia::modular::ComponentContext implementation. // fuchsia::modular::ComponentContext_TestBase implementation.
void ConnectToAgent( void 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)
override; override;
void NotImplemented_(const std::string& name) override;
private: private:
base::fuchsia::ScopedServiceBinding<fuchsia::modular::ComponentContext>
binding_;
AgentImpl agent_impl_; AgentImpl agent_impl_;
const std::string component_url_; const std::string component_url_;
......
...@@ -53,6 +53,7 @@ source_set("cast_runner_core") { ...@@ -53,6 +53,7 @@ source_set("cast_runner_core") {
"//base", "//base",
"//fuchsia:web_fidl", "//fuchsia:web_fidl",
"//fuchsia/base", "//fuchsia/base",
"//third_party/fuchsia-sdk/sdk:modular",
"//url", "//url",
] ]
public_deps = [ public_deps = [
......
...@@ -36,7 +36,7 @@ CastChannelBindings::CastChannelBindings( ...@@ -36,7 +36,7 @@ CastChannelBindings::CastChannelBindings(
DCHECK(frame_); DCHECK(frame_);
channel_consumer_.set_error_handler([this](zx_status_t status) mutable { channel_consumer_.set_error_handler([this](zx_status_t status) mutable {
ZX_LOG(ERROR, status) << " Agent disconnected."; ZX_LOG(ERROR, status) << " Agent disconnected";
std::move(on_error_closure_).Run(); std::move(on_error_closure_).Run();
}); });
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
namespace { namespace {
constexpr int kBindingsFailureExitCode = 129; constexpr int kBindingsFailureExitCode = 129;
const char kCastAgentPackageUrl[] =
"fuchsia-pkg://fuchsia.com/cast_agent#meta/cast_agent.cmx";
} // namespace } // namespace
CastComponent::CastComponent( CastComponent::CastComponent(
...@@ -31,11 +33,23 @@ CastComponent::CastComponent( ...@@ -31,11 +33,23 @@ CastComponent::CastComponent(
navigation_observer_binding_(this) { navigation_observer_binding_(this) {
base::AutoReset<bool> constructor_active_reset(&constructor_active_, true); base::AutoReset<bool> constructor_active_reset(&constructor_active_, true);
// Fetch the ComponentContext for this instance.
fuchsia::modular::ComponentContextPtr component_context;
startup_context()->incoming_services()->ConnectToService(
component_context.NewRequest());
// Request to connect to the Cast agent.
component_context->ConnectToAgent(kCastAgentPackageUrl,
agent_services_.NewRequest(),
agent_controller_.NewRequest());
// Bind to the CastChannel service provided by the Agent.
chromium::cast::CastChannelPtr cast_channel_ptr;
agent_services_->ConnectToService(
chromium::cast::CastChannel::Name_,
cast_channel_ptr.NewRequest().TakeChannel());
cast_channel_ = std::make_unique<CastChannelBindings>( cast_channel_ = std::make_unique<CastChannelBindings>(
frame(), &connector_, frame(), &connector_, std::move(cast_channel_ptr),
startup_context()
->incoming_services()
->ConnectToService<chromium::cast::CastChannel>(),
base::BindOnce(&CastComponent::DestroyComponent, base::Unretained(this), base::BindOnce(&CastComponent::DestroyComponent, base::Unretained(this),
kBindingsFailureExitCode, kBindingsFailureExitCode,
fuchsia::sys::TerminationReason::INTERNAL_ERROR)); fuchsia::sys::TerminationReason::INTERNAL_ERROR));
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
#ifndef FUCHSIA_RUNNERS_CAST_CAST_COMPONENT_H_ #ifndef FUCHSIA_RUNNERS_CAST_CAST_COMPONENT_H_
#define FUCHSIA_RUNNERS_CAST_CAST_COMPONENT_H_ #define FUCHSIA_RUNNERS_CAST_CAST_COMPONENT_H_
#include <fuchsia/modular/cpp/fidl.h>
#include <fuchsia/sys/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h> #include <lib/fidl/cpp/binding.h>
#include <memory> #include <memory>
...@@ -43,6 +45,9 @@ class CastComponent : public WebComponent, ...@@ -43,6 +45,9 @@ class CastComponent : public WebComponent,
std::unique_ptr<CastChannelBindings> cast_channel_; std::unique_ptr<CastChannelBindings> cast_channel_;
QueryableDataBindings queryable_data_; QueryableDataBindings queryable_data_;
fuchsia::sys::ServiceProviderPtr agent_services_;
fuchsia::modular::AgentControllerPtr agent_controller_;
fidl::Binding<chromium::web::NavigationEventObserver> fidl::Binding<chromium::web::NavigationEventObserver>
navigation_observer_binding_; navigation_observer_binding_;
......
...@@ -49,7 +49,7 @@ WebComponent::WebComponent( ...@@ -49,7 +49,7 @@ WebComponent::WebComponent(
controller_binding_.Bind(std::move(controller_request)); controller_binding_.Bind(std::move(controller_request));
controller_binding_.set_error_handler([this](zx_status_t status) { controller_binding_.set_error_handler([this](zx_status_t status) {
ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status) ZX_LOG_IF(ERROR, status != ZX_ERR_PEER_CLOSED, status)
<< " ComponentController disconnected."; << " ComponentController disconnected";
// Teardown the component with dummy values, since ComponentController // Teardown the component with dummy values, since ComponentController
// channel isn't there to receive them. // channel isn't there to receive them.
DestroyComponent(0, fuchsia::sys::TerminationReason::EXITED); DestroyComponent(0, fuchsia::sys::TerminationReason::EXITED);
......
...@@ -94,7 +94,6 @@ void WebContentRunner::GetWebComponentForTest( ...@@ -94,7 +94,6 @@ void WebContentRunner::GetWebComponentForTest(
} }
void WebContentRunner::DestroyComponent(WebComponent* component) { void WebContentRunner::DestroyComponent(WebComponent* component) {
LOG(ERROR) << "DestroyComponent " << components_.size();
components_.erase(components_.find(component)); components_.erase(components_.find(component));
if (components_.empty()) if (components_.empty())
......
...@@ -61,6 +61,8 @@ class WebRunnerSmokeTest : public testing::Test { ...@@ -61,6 +61,8 @@ class WebRunnerSmokeTest : public testing::Test {
net::EmbeddedTestServer test_server_; net::EmbeddedTestServer test_server_;
base::RunLoop run_loop_; base::RunLoop run_loop_;
DISALLOW_COPY_AND_ASSIGN(WebRunnerSmokeTest);
}; };
TEST_F(WebRunnerSmokeTest, RequestHtmlAndImage) { TEST_F(WebRunnerSmokeTest, RequestHtmlAndImage) {
......
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