Commit 089bc8ad authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

Fuchsia: Migrate ServicesDirectory from ScopedZxHandle to zx::channel.

Part of a larger effort to use Fuchsia native zx::channel objects
for smoother integration with FIDL types and API calls.


Bug: 852541
Change-Id: I095e17b98a334964e72cbb97dc7ea4dbded67ec8
Reviewed-on: https://chromium-review.googlesource.com/1101413
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567405}
parent 4066ee9d
......@@ -29,9 +29,9 @@ class ScopedServiceBinding {
~ScopedServiceBinding() { directory_->RemoveService(Interface::Name_); }
private:
void BindClient(ScopedZxHandle channel) {
binding_.Bind(typename fidl::InterfaceRequest<Interface>(
zx::channel(channel.release())));
void BindClient(zx::channel channel) {
binding_.Bind(
typename fidl::InterfaceRequest<Interface>(std::move(channel)));
}
ServicesDirectory* directory_;
......
......@@ -6,6 +6,7 @@
#include <lib/async/default.h>
#include <lib/svc/dir.h>
#include <lib/zx/channel.h>
#include <zircon/process.h>
#include <zircon/processargs.h>
......@@ -16,7 +17,7 @@
namespace base {
namespace fuchsia {
ServicesDirectory::ServicesDirectory(ScopedZxHandle directory_request) {
ServicesDirectory::ServicesDirectory(zx::channel directory_request) {
zx_status_t status = svc_dir_create(async_get_default(),
directory_request.release(), &svc_dir_);
ZX_CHECK(status == ZX_OK, status);
......@@ -33,7 +34,7 @@ ServicesDirectory::~ServicesDirectory() {
// static
ServicesDirectory* ServicesDirectory::GetDefault() {
static base::NoDestructor<ServicesDirectory> directory(
ScopedZxHandle(zx_get_startup_handle(PA_DIRECTORY_REQUEST)));
zx::channel(zx_get_startup_handle(PA_DIRECTORY_REQUEST)));
return directory.get();
}
......@@ -77,7 +78,7 @@ void ServicesDirectory::HandleConnectRequest(void* context,
// services.
DCHECK(it != directory->services_.end());
it->second.Run(ScopedZxHandle(service_request));
it->second.Run(zx::channel(service_request));
}
} // namespace fuchsia
......
......@@ -5,10 +5,11 @@
#ifndef BASE_FUCHSIA_SERVICES_DIRECTORY_H_
#define BASE_FUCHSIA_SERVICES_DIRECTORY_H_
#include <lib/zx/channel.h>
#include "base/base_export.h"
#include "base/callback.h"
#include "base/containers/flat_map.h"
#include "base/fuchsia/scoped_zx_handle.h"
#include "base/macros.h"
#include "base/strings/string_piece.h"
#include "base/threading/thread_checker.h"
......@@ -32,11 +33,11 @@ class BASE_EXPORT ServicesDirectory {
public:
// Callback called to connect incoming requests.
using ConnectServiceCallback =
base::RepeatingCallback<void(ScopedZxHandle channel)>;
base::RepeatingCallback<void(zx::channel channel)>;
// Creates services directory that will be served over the
// |directory_channel|.
explicit ServicesDirectory(ScopedZxHandle directory_channel);
explicit ServicesDirectory(zx::channel directory_channel);
~ServicesDirectory();
......
......@@ -5,6 +5,7 @@
#include "base/fuchsia/services_directory.h"
#include <lib/fdio/util.h>
#include <lib/zx/channel.h>
#include "base/bind.h"
#include "base/fuchsia/component_context.h"
......@@ -28,30 +29,30 @@ class TestInterfaceImpl : public test_fidl::TestInterface {
TEST(ServicesDirectoryTest, Connect) {
MessageLoopForIO message_loop_;
ScopedZxHandle dir_service_handle;
ScopedZxHandle dir_client_handle;
ASSERT_EQ(zx_channel_create(0, dir_service_handle.receive(),
dir_client_handle.receive()),
zx::channel dir_service_channel;
zx::channel dir_client_channel;
ASSERT_EQ(zx::channel::create(0, &dir_service_channel, &dir_client_channel),
ZX_OK);
// Mount service dir and publish the service.
ServicesDirectory service_dir(std::move(dir_service_handle));
ServicesDirectory service_dir(std::move(dir_service_channel));
TestInterfaceImpl test_service;
ScopedServiceBinding<test_fidl::TestInterface> service_binding(&service_dir,
&test_service);
// Open public directory from the service directory.
ScopedZxHandle public_dir_service_handle;
ScopedZxHandle public_dir_client_handle;
ASSERT_EQ(zx_channel_create(0, public_dir_service_handle.receive(),
public_dir_client_handle.receive()),
zx::channel public_dir_service_channel;
zx::channel public_dir_client_channel;
ASSERT_EQ(zx::channel::create(0, &public_dir_service_channel,
&public_dir_client_channel),
ZX_OK);
ASSERT_EQ(fdio_open_at(dir_client_handle.get(), "public", 0,
public_dir_service_handle.release()),
ASSERT_EQ(fdio_open_at(dir_client_channel.get(), "public", 0,
public_dir_service_channel.release()),
ZX_OK);
// Create ComponentContext and connect to the test service.
ComponentContext client_context(std::move(public_dir_client_handle));
ComponentContext client_context(
base::ScopedZxHandle(public_dir_client_channel.release()));
auto stub = client_context.ConnectToService<test_fidl::TestInterface>();
// Call the service and wait for response.
......
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