Skip to content

Commit

Permalink
[Fuchsia] Migrate call-sites to ServiceDirectoryClient.
Browse files Browse the repository at this point in the history
Migrate callsites from ComponentContext/zx::channel to strongly-typed
APIs and ServiceDirectoryClient.

Bug: 920920
Change-Id: I8fe642112562e3e75ad7230d55415d05e35b6cf8
Reviewed-on: https://chromium-review.googlesource.com/c/1450587
Commit-Queue: Wez <wez@chromium.org>
Reviewed-by: Sergey Ulanov <sergeyu@chromium.org>
Reviewed-by: Kevin Marshall <kmarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#629793}
  • Loading branch information
Wez authored and Commit Bot committed Feb 7, 2019
1 parent f8cdeac commit b10b9bb
Show file tree
Hide file tree
Showing 23 changed files with 89 additions and 96 deletions.
2 changes: 1 addition & 1 deletion base/fuchsia/filtered_service_directory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ FilteredServiceDirectory::~FilteredServiceDirectory() {
}

void FilteredServiceDirectory::AddService(const char* service_name) {
outgoing_directory_->AddService(
outgoing_directory_->AddServiceUnsafe(
service_name,
base::BindRepeating(&FilteredServiceDirectory::HandleRequest,
base::Unretained(this), service_name));
Expand Down
2 changes: 1 addition & 1 deletion base/fuchsia/filtered_service_directory_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FilteredServiceDirectoryTest : public ServiceDirectoryTestBase {
filtered_service_directory_ = std::make_unique<FilteredServiceDirectory>(
public_service_directory_client_.get());
filtered_client_ = std::make_unique<ServiceDirectoryClient>(
filtered_service_directory_->ConnectClient().TakeChannel());
filtered_service_directory_->ConnectClient());
}

protected:
Expand Down
2 changes: 1 addition & 1 deletion base/fuchsia/service_directory_test_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include <lib/zx/channel.h>
#include <memory>

#include "base/fuchsia/component_context.h"
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/fuchsia/test_interface_impl.h"
#include "base/fuchsia/testfidl/cpp/fidl.h"
#include "base/message_loop/message_loop.h"
Expand Down
1 change: 0 additions & 1 deletion fuchsia/http/http_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <fuchsia/net/oldhttp/cpp/fidl.h>
#include <lib/fidl/cpp/binding.h>

#include "base/fuchsia/component_context.h"
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory.h"
#include "base/run_loop.h"
Expand Down
40 changes: 18 additions & 22 deletions fuchsia/runners/cast/cast_runner_integration_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@ class CastRunnerIntegrationTest : public testing::Test,
CastRunnerIntegrationTest()
: run_timeout_(TestTimeouts::action_timeout()),
cast_channel_binding_(this) {
// Create a new test ServiceDirectory, and a test ComponentContext
// connected to it, for the test to use to drive the CastRunner.
zx::channel service_directory_request, service_directory_client;
zx_status_t status = zx::channel::create(0, &service_directory_client,
&service_directory_request);
ZX_CHECK(status == ZX_OK, status) << "zx_channel_create";

test_service_directory_ = std::make_unique<base::fuchsia::ServiceDirectory>(
std::move(service_directory_request));
test_component_context_ = std::make_unique<base::fuchsia::ComponentContext>(
std::move(service_directory_client));
// Create a new test ServiceDirectory, and ServiceDirectoryClient connected
// to it, for tests to use to drive the CastRunner.
fidl::InterfaceHandle<fuchsia::io::Directory> directory;
test_services_ = std::make_unique<base::fuchsia::ServiceDirectory>(
directory.NewRequest());
test_services_client_ =
std::make_unique<base::fuchsia::ServiceDirectoryClient>(
std::move(directory));

// Create the AppConfigManager.
app_config_binding_ = std::make_unique<
Expand All @@ -61,16 +58,15 @@ class CastRunnerIntegrationTest : public testing::Test,
chromium::cast::ApplicationConfigManagerPtr app_config_manager_interface;
app_config_binding_->Bind(app_config_manager_interface.NewRequest());

// Create the CastRunner, published into |test_service_directory_|.
// Create the CastRunner, published into |test_services_|.
cast_runner_ = std::make_unique<CastRunner>(
test_service_directory_.get(),
WebContentRunner::CreateDefaultWebContext(),
test_services_.get(), WebContentRunner::CreateDefaultWebContext(),
std::move(app_config_manager_interface),
cast_runner_run_loop_.QuitClosure());

// Connect to the CastRunner's fuchsia.sys.Runner interface.
cast_runner_ptr_ =
test_component_context_->ConnectToService<fuchsia::sys::Runner>();
test_services_client_->ConnectToService<fuchsia::sys::Runner>();
cast_runner_ptr_.set_error_handler([this](zx_status_t status) {
ZX_LOG(ERROR, status) << "CastRunner closed channel.";
ADD_FAILURE();
Expand Down Expand Up @@ -131,8 +127,8 @@ class CastRunnerIntegrationTest : public testing::Test,
fidl::Binding<chromium::cast::CastChannel> cast_channel_binding_;

// ServiceDirectory into which the CastRunner will publish itself.
std::unique_ptr<base::fuchsia::ServiceDirectory> test_service_directory_;
std::unique_ptr<base::fuchsia::ComponentContext> test_component_context_;
std::unique_ptr<base::fuchsia::ServiceDirectory> test_services_;
std::unique_ptr<base::fuchsia::ComponentContext> test_services_client_;

std::unique_ptr<CastRunner> cast_runner_;
fuchsia::sys::RunnerPtr cast_runner_ptr_;
Expand All @@ -151,7 +147,7 @@ TEST_F(CastRunnerIntegrationTest, BasicRequest) {

// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller_ptr;
base::fuchsia::ComponentContext component_services(StartCastComponent(
base::fuchsia::ServiceDirectoryClient services_client(StartCastComponent(
base::StringPrintf("cast:%s", kBlankAppId), &cast_runner_ptr_,
component_controller_ptr.NewRequest(), &cast_channel_binding_));
component_controller_ptr.set_error_handler(&ComponentErrorHandler);
Expand Down Expand Up @@ -193,7 +189,7 @@ TEST_F(CastRunnerIntegrationTest, BasicRequest) {
TEST_F(CastRunnerIntegrationTest, IncorrectCastAppId) {
// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller_ptr;
base::fuchsia::ComponentContext component_services(StartCastComponent(
base::fuchsia::ServiceDirectoryClient services_client(StartCastComponent(
"cast:99999999", &cast_runner_ptr_, component_controller_ptr.NewRequest(),
&cast_channel_binding_));
component_controller_ptr.set_error_handler(&ComponentErrorHandler);
Expand All @@ -214,7 +210,7 @@ TEST_F(CastRunnerIntegrationTest, CastChannel) {

// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller_ptr;
base::fuchsia::ComponentContext component_services(StartCastComponent(
base::fuchsia::ServiceDirectoryClient services_client(StartCastComponent(
base::StringPrintf("cast:%s", kCastChannelAppId), &cast_runner_ptr_,
component_controller_ptr.NewRequest(), &cast_channel_binding_));
component_controller_ptr.set_error_handler(&ComponentErrorHandler);
Expand Down Expand Up @@ -274,7 +270,7 @@ TEST_F(CastRunnerIntegrationTest, CastChannelConsumerDropped) {

// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller_ptr;
base::fuchsia::ComponentContext component_services(StartCastComponent(
base::fuchsia::ServiceDirectoryClient services_client(StartCastComponent(
base::StringPrintf("cast:%s", kCastChannelAppId), &cast_runner_ptr_,
component_controller_ptr.NewRequest(), &cast_channel_binding_));

Expand All @@ -297,7 +293,7 @@ TEST_F(CastRunnerIntegrationTest, CastChannelComponentControllerDropped) {

// Launch the test-app component.
fuchsia::sys::ComponentControllerPtr component_controller_ptr;
base::fuchsia::ComponentContext component_services(StartCastComponent(
base::fuchsia::ServiceDirectoryClient services_client(StartCastComponent(
base::StringPrintf("cast:%s", kCastChannelAppId), &cast_runner_ptr_,
component_controller_ptr.NewRequest(), &cast_channel_binding_));

Expand Down
4 changes: 2 additions & 2 deletions fuchsia/runners/cast/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/fuchsia/component_context.h"
#include "base/fuchsia/service_directory.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "fuchsia/runners/cast/cast_runner.h"
Expand All @@ -15,7 +15,7 @@ int main(int argc, char** argv) {
CastRunner runner(
base::fuchsia::ServiceDirectory::GetDefault(),
WebContentRunner::CreateDefaultWebContext(),
base::fuchsia::ComponentContext::GetDefault()
base::fuchsia::ServiceDirectoryClient::ForCurrentProcess()
->ConnectToService<chromium::cast::ApplicationConfigManager>(),
run_loop.QuitClosure());

Expand Down
52 changes: 21 additions & 31 deletions fuchsia/runners/cast/test_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "base/fuchsia/service_directory.h"
#include "base/run_loop.h"

zx::channel StartCastComponent(
fidl::InterfaceHandle<fuchsia::io::Directory> StartCastComponent(
const base::StringPiece& cast_url,
fuchsia::sys::RunnerPtr* sys_runner,
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
Expand All @@ -22,40 +22,30 @@ zx::channel StartCastComponent(
// Construct, bind, and populate a ServiceDirectory for publishing
// the CastChannel service to the CastComponent.
auto service_list = std::make_unique<fuchsia::sys::ServiceList>();
zx::channel cast_channel_dir_request, cast_channel_dir_client;
zx_status_t status = zx::channel::create(0, &cast_channel_dir_request,
&cast_channel_dir_client);
ZX_CHECK(status == ZX_OK, status) << "zx_channel_create";
fidl::InterfaceHandle<fuchsia::io::Directory> directory;
base::fuchsia::ServiceDirectory cast_channel_directory(
std::move(cast_channel_dir_request));
directory.NewRequest());
base::RunLoop service_connect_runloop;
cast_channel_directory.AddService(
chromium::cast::CastChannel::Name_,
base::BindRepeating(
[](base::RepeatingClosure on_connect_cb,
fidl::Binding<chromium::cast::CastChannel>* cast_channel_binding_,
zx::channel channel) {
cast_channel_binding_->Bind(std::move(channel));
on_connect_cb.Run();
},
base::Passed(service_connect_runloop.QuitClosure()),
base::Unretained(cast_channel_binding)));
cast_channel_directory.AddService(base::BindRepeating(
[](base::RepeatingClosure on_connect_cb,
fidl::Binding<chromium::cast::CastChannel>* cast_channel_binding_,
fidl::InterfaceRequest<chromium::cast::CastChannel> request) {
cast_channel_binding_->Bind(std::move(request));
on_connect_cb.Run();
},
base::Passed(service_connect_runloop.QuitClosure()),
base::Unretained(cast_channel_binding)));
service_list->names.push_back(chromium::cast::CastChannel::Name_);
service_list->host_directory = std::move(cast_channel_dir_client);

fuchsia::sys::LaunchInfo launch_info;
launch_info.url = cast_url.as_string();
launch_info.additional_services = std::move(service_list);

// Create a channel to pass to the Runner, through which to expose the new
// component's ServiceDirectory.
zx::channel service_directory_client;
status = zx::channel::create(0, &service_directory_client,
&launch_info.directory_request);
ZX_CHECK(status == ZX_OK, status) << "zx_channel_create";
service_list->host_directory = directory.TakeChannel();

// Configure the Runner, including a service directory channel to publish
// services to.
fuchsia::sys::StartupInfo startup_info;
startup_info.launch_info = std::move(launch_info);
startup_info.launch_info.url = cast_url.as_string();
startup_info.launch_info.additional_services = std::move(service_list);
fidl::InterfaceHandle<fuchsia::io::Directory> component_services;
startup_info.launch_info.directory_request =
component_services.NewRequest().TakeChannel();

// The FlatNamespace vectors must be non-null, but may be empty.
startup_info.flat_namespace.paths.resize(0);
Expand All @@ -73,5 +63,5 @@ zx::channel StartCastComponent(
// Prepare the service directory for clean teardown.
cast_channel_directory.RemoveAllServices();

return service_directory_client;
return component_services;
}
8 changes: 7 additions & 1 deletion fuchsia/runners/cast/test_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@
#include "base/strings/string_piece.h"
#include "fuchsia/fidl/chromium/cast/cpp/fidl.h"

namespace fuchsia {
namespace io {
class Directory;
}
} // namespace fuchsia

// Starts a Cast component from the runner |sys_runner| with the URL |cast_url|
// and returns the outgoing service directory client channel.
// The Cast component will connect to the CastChannel FIDL service bound at
// |cast_channel_binding|.
// Blocks until |cast_channel_binding| is bound.
zx::channel StartCastComponent(
fidl::InterfaceHandle<fuchsia::io::Directory> StartCastComponent(
const base::StringPiece& cast_url,
fuchsia::sys::RunnerPtr* sys_runner,
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
Expand Down
8 changes: 5 additions & 3 deletions fuchsia/runners/common/web_component.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ WebComponent::WebComponent(
if (startup_info.launch_info.additional_services &&
startup_info.launch_info.additional_services->host_directory) {
additional_services_ =
std::make_unique<base::fuchsia::ComponentContext>(std::move(
startup_info.launch_info.additional_services->host_directory));
std::make_unique<base::fuchsia::ServiceDirectoryClient>(
fidl::InterfaceHandle<fuchsia::io::Directory>(std::move(
startup_info.launch_info.additional_services->host_directory)));
additional_service_names_ =
std::move(startup_info.launch_info.additional_services->names);
}
Expand All @@ -75,7 +76,8 @@ WebComponent::WebComponent(
// message-loop, to ensure that it is available before the ServiceDirectory
// starts processing requests.
service_directory_ = std::make_unique<base::fuchsia::ServiceDirectory>(
std::move(startup_info.launch_info.directory_request));
fidl::InterfaceRequest<fuchsia::io::Directory>(
std::move(startup_info.launch_info.directory_request)));
view_provider_binding_ = std::make_unique<
base::fuchsia::ScopedServiceBinding<fuchsia::ui::app::ViewProvider>>(
service_directory_.get(), this);
Expand Down
12 changes: 6 additions & 6 deletions fuchsia/runners/common/web_component.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include <utility>
#include <vector>

#include "base/fuchsia/component_context.h"
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/logging.h"
#include "fuchsia/fidl/chromium/web/cpp/fidl.h"
#include "url/gurl.h"
Expand Down Expand Up @@ -73,14 +73,14 @@ class WebComponent : public fuchsia::sys::ComponentController,
virtual void DestroyComponent(int termination_exit_code,
fuchsia::sys::TerminationReason reason);

// Gets a directory of incoming services provided to the component, or returns
// Returns the directory of incoming services provided to the component, or
// nullptr if none was provided.
base::fuchsia::ComponentContext* additional_services() const {
base::fuchsia::ServiceDirectoryClient* additional_services() const {
return additional_services_.get();
}

// Gets the names of services available in additional_services().
const std::vector<std::string> additional_service_names() {
// Returns the names of services available in additional_services().
const std::vector<std::string>& additional_service_names() const {
return additional_service_names_;
}

Expand All @@ -96,7 +96,7 @@ class WebComponent : public fuchsia::sys::ComponentController,
fidl::Binding<fuchsia::sys::ComponentController> controller_binding_;

// Incoming services provided at component creation.
std::unique_ptr<base::fuchsia::ComponentContext> additional_services_;
std::unique_ptr<base::fuchsia::ServiceDirectoryClient> additional_services_;

// The names of services provided at component creation.
std::vector<std::string> additional_service_names_;
Expand Down
4 changes: 2 additions & 2 deletions fuchsia/runners/common/web_content_runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@

#include "base/bind.h"
#include "base/files/file.h"
#include "base/fuchsia/component_context.h"
#include "base/fuchsia/file_utils.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/logging.h"
#include "fuchsia/runners/common/web_component.h"
#include "url/gurl.h"

// static
chromium::web::ContextPtr WebContentRunner::CreateDefaultWebContext() {
auto web_context_provider =
base::fuchsia::ComponentContext::GetDefault()
base::fuchsia::ServiceDirectoryClient::ForCurrentProcess()
->ConnectToService<chromium::web::ContextProvider>();

chromium::web::CreateContextParams create_params;
Expand Down
4 changes: 2 additions & 2 deletions fuchsia/runners/web/web_runner_smoke_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <fuchsia/sys/cpp/fidl.h>

#include "base/bind.h"
#include "base/fuchsia/component_context.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/test/test_timeouts.h"
#include "base/threading/thread_task_runner_handle.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
Expand Down Expand Up @@ -64,7 +64,7 @@ TEST_F(WebRunnerSmokeTest, RequestHtmlAndImage) {
fuchsia::sys::LaunchInfo launch_info;
launch_info.url = test_server_.GetURL("/test.html").spec();

auto launcher = base::fuchsia::ComponentContext::GetDefault()
auto launcher = base::fuchsia::ServiceDirectoryClient::ForCurrentProcess()
->ConnectToServiceSync<fuchsia::sys::Launcher>();

fuchsia::sys::ComponentControllerSyncPtr controller;
Expand Down
4 changes: 2 additions & 2 deletions media/audio/fuchsia/audio_output_stream_fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <zircon/syscalls.h>

#include "base/bind.h"
#include "base/fuchsia/component_context.h"
#include "base/fuchsia/service_directory_client.h"
#include "media/audio/fuchsia/audio_manager_fuchsia.h"
#include "media/base/audio_sample_types.h"
#include "media/base/audio_timestamp_helper.h"
Expand Down Expand Up @@ -36,7 +36,7 @@ bool AudioOutputStreamFuchsia::Open() {

// Connect |audio_renderer_| to the audio service.
fuchsia::media::AudioPtr audio_server =
base::fuchsia::ComponentContext::GetDefault()
base::fuchsia::ServiceDirectoryClient::ForCurrentProcess()
->ConnectToService<fuchsia::media::Audio>();
audio_server->CreateAudioRenderer(audio_renderer_.NewRequest());
audio_renderer_.set_error_handler(
Expand Down
4 changes: 2 additions & 2 deletions media/filters/fuchsia/fuchsia_video_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/fuchsia/component_context.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/macros.h"
Expand Down Expand Up @@ -402,7 +402,7 @@ void FuchsiaVideoDecoder::Initialize(const VideoDecoderConfig& config,
codec_params.require_hw = !enable_sw_decoding_;

auto codec_factory =
base::fuchsia::ComponentContext::GetDefault()
base::fuchsia::ServiceDirectoryClient::ForCurrentProcess()
->ConnectToService<fuchsia::mediacodec::CodecFactory>();
codec_factory->CreateDecoder(std::move(codec_params), codec_.NewRequest());

Expand Down
Loading

0 comments on commit b10b9bb

Please sign in to comment.