Commit eba2d0ab authored by Wez's avatar Wez Committed by Commit Bot

[fuchsia] Remove the old ServiceDirectoryClient.

ServiceDirectoryClient has been deprecated in favour of the Fuchsia-
provided sys::ServiceDirectory, so remove it.

Bug: 974072
Change-Id: I5fba438b946b05213a3686110cf733bb43ecb179
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2033154Reviewed-by: default avatarLuke Halliwell (slow) <halliwell@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Commit-Queue: Wez <wez@chromium.org>
Auto-Submit: Wez <wez@chromium.org>
Cr-Commit-Position: refs/heads/master@{#738232}
parent 43df9803
...@@ -1559,8 +1559,6 @@ jumbo_component("base") { ...@@ -1559,8 +1559,6 @@ jumbo_component("base") {
"fuchsia/scoped_service_binding.h", "fuchsia/scoped_service_binding.h",
"fuchsia/service_directory.cc", "fuchsia/service_directory.cc",
"fuchsia/service_directory.h", "fuchsia/service_directory.h",
"fuchsia/service_directory_client.cc",
"fuchsia/service_directory_client.h",
"fuchsia/service_provider_impl.cc", "fuchsia/service_provider_impl.cc",
"fuchsia/service_provider_impl.h", "fuchsia/service_provider_impl.h",
"fuchsia/startup_context.cc", "fuchsia/startup_context.cc",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/fuchsia/service_directory_client.h"
#include <lib/fdio/directory.h>
#include <utility>
#include "base/fuchsia/file_utils.h"
#include "base/fuchsia/fuchsia_logging.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/no_destructor.h"
namespace base {
namespace fuchsia {
ServiceDirectoryClient::ServiceDirectoryClient(
fidl::InterfaceHandle<::fuchsia::io::Directory> directory)
: directory_(std::move(directory)) {
DCHECK(directory_);
}
ServiceDirectoryClient::~ServiceDirectoryClient() = default;
// static
const ServiceDirectoryClient* ServiceDirectoryClient::ForCurrentProcess() {
return ServiceDirectoryClient::ProcessInstance()->get();
}
zx_status_t ServiceDirectoryClient::ConnectToServiceUnsafe(
const char* name,
zx::channel request) const {
DCHECK(request.is_valid());
return fdio_service_connect_at(directory_.channel().get(), name,
request.release());
}
ServiceDirectoryClient::ServiceDirectoryClient() {}
// static
std::unique_ptr<ServiceDirectoryClient>
ServiceDirectoryClient::CreateForProcess() {
fidl::InterfaceHandle<::fuchsia::io::Directory> directory =
OpenDirectory(base::FilePath(kServiceDirectoryPath));
if (directory)
return std::make_unique<ServiceDirectoryClient>(std::move(directory));
LOG(WARNING) << "/svc is not available.";
return base::WrapUnique(new ServiceDirectoryClient);
}
// static
std::unique_ptr<ServiceDirectoryClient>*
ServiceDirectoryClient::ProcessInstance() {
static base::NoDestructor<std::unique_ptr<ServiceDirectoryClient>>
service_directory_client_ptr(CreateForProcess());
return service_directory_client_ptr.get();
}
} // namespace fuchsia
} // namespace base
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef BASE_FUCHSIA_SERVICE_DIRECTORY_CLIENT_H_
#define BASE_FUCHSIA_SERVICE_DIRECTORY_CLIENT_H_
#include <fuchsia/io/cpp/fidl.h>
#include <lib/fidl/cpp/interface_handle.h>
#include <memory>
#include "base/base_export.h"
#include "base/macros.h"
namespace fidl {
template <typename Interface>
class InterfacePtr;
template <typename Interface>
class SynchronousInterfacePtr;
} // namespace fidl
namespace base {
namespace fuchsia {
// Helper for connecting to services from a supplied fuchsia.io.Directory.
class BASE_EXPORT ServiceDirectoryClient {
public:
// Wraps the supplied |directory| to access the services it contains.
explicit ServiceDirectoryClient(
fidl::InterfaceHandle<::fuchsia::io::Directory> directory);
~ServiceDirectoryClient();
// Returns the default ServiceDirectoryClient for the current process.
// This connects to the "/svc" path in the namespace that was supplied to the
// current process when it was launched.
static const ServiceDirectoryClient* ForCurrentProcess();
// Connects to the service satisfying the specified |request|.
template <typename Interface>
zx_status_t ConnectToService(
fidl::InterfaceRequest<Interface> request) const {
return ConnectToServiceUnsafe(Interface::Name_, request.TakeChannel());
}
// Convenience functions returning a [Synchronous]InterfacePtr directly.
// Returns an un-bound pointer if the connection attempt returns an error.
template <typename Interface>
fidl::InterfacePtr<Interface> ConnectToService() const {
fidl::InterfacePtr<Interface> result;
if (ConnectToService(result.NewRequest()) != ZX_OK)
result.Unbind();
return result;
}
template <typename Interface>
fidl::SynchronousInterfacePtr<Interface> ConnectToServiceSync() const {
fidl::SynchronousInterfacePtr<Interface> result;
if (ConnectToService(result.NewRequest()) != ZX_OK)
result.Unbind();
return result;
}
// Connects the |request| channel to the service specified by |name|.
// This is used only when proxying requests for interfaces not known at
// compile-time. Use the type-safe APIs above whenever possible.
zx_status_t ConnectToServiceUnsafe(const char* name,
zx::channel request) const;
private:
ServiceDirectoryClient();
// Creates a ServiceDirectoryClient connected to the process' "/svc"
// directory, or a dummy instance if the "/svc" directory is not available.
static std::unique_ptr<ServiceDirectoryClient> CreateForProcess();
// Returns the container holding the ForCurrentProcess() instance. The
// default ServiceDirectoryClient is created the first time this function is
// called.
static std::unique_ptr<ServiceDirectoryClient>* ProcessInstance();
const fidl::InterfaceHandle<::fuchsia::io::Directory> directory_;
DISALLOW_COPY_AND_ASSIGN(ServiceDirectoryClient);
};
} // namespace fuchsia
} // namespace base
#endif // BASE_FUCHSIA_SERVICE_DIRECTORY_CLIENT_H_
...@@ -75,7 +75,7 @@ StartupContext::StartupContext(::fuchsia::sys::StartupInfo startup_info) { ...@@ -75,7 +75,7 @@ StartupContext::StartupContext(::fuchsia::sys::StartupInfo startup_info) {
if (!incoming_services) { if (!incoming_services) {
LOG(WARNING) << "Component started without a service directory"; LOG(WARNING) << "Component started without a service directory";
// Create a dummy ServiceDirectoryClient with a channel that's not // Create a dummy ServiceDirectory with a channel that's not
// connected on the other end. // connected on the other end.
fidl::InterfaceHandle<::fuchsia::io::Directory> dummy_directory; fidl::InterfaceHandle<::fuchsia::io::Directory> dummy_directory;
ignore_result(dummy_directory.NewRequest()); ignore_result(dummy_directory.NewRequest());
...@@ -87,11 +87,6 @@ StartupContext::StartupContext(::fuchsia::sys::StartupInfo startup_info) { ...@@ -87,11 +87,6 @@ StartupContext::StartupContext(::fuchsia::sys::StartupInfo startup_info) {
std::make_unique<sys::ComponentContext>(std::move(incoming_services)); std::make_unique<sys::ComponentContext>(std::move(incoming_services));
outgoing_directory_request_ = outgoing_directory_request_ =
std::move(startup_info.launch_info.directory_request); std::move(startup_info.launch_info.directory_request);
service_directory_ =
std::make_unique<ServiceDirectory>(component_context_->outgoing().get());
service_directory_client_ = std::make_unique<ServiceDirectoryClient>(
component_context_->svc()->CloneChannel());
} }
StartupContext::~StartupContext() = default; StartupContext::~StartupContext() = default;
...@@ -101,11 +96,5 @@ void StartupContext::ServeOutgoingDirectory() { ...@@ -101,11 +96,5 @@ void StartupContext::ServeOutgoingDirectory() {
component_context_->outgoing()->Serve(std::move(outgoing_directory_request_)); component_context_->outgoing()->Serve(std::move(outgoing_directory_request_));
} }
ServiceDirectory* StartupContext::public_services() {
if (outgoing_directory_request_)
ServeOutgoingDirectory();
return service_directory_.get();
}
} // namespace fuchsia } // namespace fuchsia
} // namespace base } // namespace base
...@@ -7,12 +7,16 @@ ...@@ -7,12 +7,16 @@
#include <fuchsia/sys/cpp/fidl.h> #include <fuchsia/sys/cpp/fidl.h>
#include <lib/sys/cpp/component_context.h> #include <lib/sys/cpp/component_context.h>
#include <lib/zx/channel.h>
#include <memory> #include <memory>
#include "base/base_export.h" #include "base/base_export.h"
#include "base/fuchsia/service_directory.h"
#include "base/fuchsia/service_directory_client.h" namespace sys {
#include "base/macros.h" class ComponentContext;
class ServiceDirectory;
class OutgoingDirectory;
} // namespace sys
namespace base { namespace base {
namespace fuchsia { namespace fuchsia {
...@@ -27,29 +31,27 @@ class BASE_EXPORT StartupContext { ...@@ -27,29 +31,27 @@ class BASE_EXPORT StartupContext {
explicit StartupContext(::fuchsia::sys::StartupInfo startup_info); explicit StartupContext(::fuchsia::sys::StartupInfo startup_info);
virtual ~StartupContext(); virtual ~StartupContext();
StartupContext(const StartupContext&) = delete;
StartupContext& operator=(const StartupContext&) = delete;
// Returns the ComponentContext for the current component. // Returns the ComponentContext for the current component.
sys::ComponentContext* component_context() const { sys::ComponentContext* component_context() const {
return component_context_.get(); return component_context_.get();
} }
// Easy accessors for the incoming service directory, and outgoing directory.
const sys::ServiceDirectory* svc() const {
return component_context_->svc().get();
}
const sys::OutgoingDirectory* outgoing() const {
return component_context_->outgoing().get();
}
// Starts serving outgoing directory in the |component_context()|. Can be // Starts serving outgoing directory in the |component_context()|. Can be
// called at most once. All outgoing services should be published in // called at most once. All outgoing services should be published in
// |component_context()->outgoing()| before calling this function. // |component_context()->outgoing()| before calling this function.
void ServeOutgoingDirectory(); void ServeOutgoingDirectory();
// TODO(crbug.com/974072): ServiceDirectory and ServiceDirectoryClient are
// deprecated. Remove incoming_services() and public_services() once all
// clients have been migrated to sys::OutgoingDirectory and
// sys::ServiceDirectory.
ServiceDirectoryClient* incoming_services() const {
return service_directory_client_.get();
}
// Legacy ServiceDirectory instance. Also calls |ServeOutgoingDirectory()| if
// it hasn't been called yet, which means outgoing services should be bound
// immediately after the first call to this API.
ServiceDirectory* public_services();
bool has_outgoing_directory_request() { bool has_outgoing_directory_request() {
return outgoing_directory_request_.is_valid(); return outgoing_directory_request_.is_valid();
} }
...@@ -64,11 +66,6 @@ class BASE_EXPORT StartupContext { ...@@ -64,11 +66,6 @@ class BASE_EXPORT StartupContext {
// Used to store outgoing directory until ServeOutgoingDirectory() is called. // Used to store outgoing directory until ServeOutgoingDirectory() is called.
zx::channel outgoing_directory_request_; zx::channel outgoing_directory_request_;
std::unique_ptr<ServiceDirectory> service_directory_;
std::unique_ptr<ServiceDirectoryClient> service_directory_client_;
DISALLOW_COPY_AND_ASSIGN(StartupContext);
}; };
} // namespace fuchsia } // namespace fuchsia
......
...@@ -4,8 +4,10 @@ ...@@ -4,8 +4,10 @@
#include <fuchsia/hardware/power/statecontrol/cpp/fidl.h> #include <fuchsia/hardware/power/statecontrol/cpp/fidl.h>
#include <lib/sys/cpp/component_context.h>
#include "base/fuchsia/default_context.h"
#include "base/fuchsia/fuchsia_logging.h" #include "base/fuchsia/fuchsia_logging.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "chromecast/public/reboot_shlib.h" #include "chromecast/public/reboot_shlib.h"
...@@ -24,7 +26,7 @@ AdminSyncPtr& GetAdminSyncPtr() { ...@@ -24,7 +26,7 @@ AdminSyncPtr& GetAdminSyncPtr() {
// static // static
void RebootShlib::Initialize(const std::vector<std::string>& argv) { void RebootShlib::Initialize(const std::vector<std::string>& argv) {
base::fuchsia::ServiceDirectoryClient::ForCurrentProcess()->ConnectToService( base::fuchsia::ComponentContextForCurrentProcess()->svc()->Connect(
GetAdminSyncPtr().NewRequest()); GetAdminSyncPtr().NewRequest());
} }
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "base/auto_reset.h" #include "base/auto_reset.h"
#include "base/fuchsia/default_context.h" #include "base/fuchsia/default_context.h"
#include "base/fuchsia/scoped_service_binding.h" #include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/test/bind_test_util.h" #include "base/test/bind_test_util.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "base/fuchsia/default_context.h" #include "base/fuchsia/default_context.h"
#include "base/fuchsia/file_utils.h" #include "base/fuchsia/file_utils.h"
#include "base/fuchsia/fuchsia_logging.h" #include "base/fuchsia/fuchsia_logging.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
......
...@@ -24,10 +24,9 @@ WebComponent::WebComponent( ...@@ -24,10 +24,9 @@ WebComponent::WebComponent(
: runner_(runner), : runner_(runner),
startup_context_(std::move(context)), startup_context_(std::move(context)),
controller_binding_(this), controller_binding_(this),
module_context_( module_context_(startup_context()
startup_context() ->svc()
->incoming_services() ->Connect<fuchsia::modular::ModuleContext>()) {
->ConnectToService<fuchsia::modular::ModuleContext>()) {
DCHECK(runner); DCHECK(runner);
// If the ComponentController request is valid then bind it, and configure it // If the ComponentController request is valid then bind it, and configure it
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include <vector> #include <vector>
#include "base/fuchsia/scoped_service_binding.h" #include "base/fuchsia/scoped_service_binding.h"
#include "base/fuchsia/service_directory_client.h"
#include "base/fuchsia/startup_context.h" #include "base/fuchsia/startup_context.h"
#include "base/logging.h" #include "base/logging.h"
#include "fuchsia/base/lifecycle_impl.h" #include "fuchsia/base/lifecycle_impl.h"
......
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