Commit 8cb38ff4 authored by Kevin Marshall's avatar Kevin Marshall Committed by Commit Bot

Fuchsia: Migrate ComponentContext 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: I421819558de9a20fe9e5fa24f083b103b46bd654
Reviewed-on: https://chromium-review.googlesource.com/1101461
Commit-Queue: Kevin Marshall <kmarshall@chromium.org>
Reviewed-by: default avatarSergey Ulanov <sergeyu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567457}
parent 0a4eb15d
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
#include "base/fuchsia/component_context.h" #include "base/fuchsia/component_context.h"
#include <lib/fdio/util.h> #include <lib/fdio/util.h>
#include <lib/zx/channel.h>
#include <utility>
#include "base/fuchsia/scoped_zx_handle.h"
#include "base/fuchsia/services_directory.h" #include "base/fuchsia/services_directory.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
...@@ -16,19 +17,19 @@ namespace fuchsia { ...@@ -16,19 +17,19 @@ namespace fuchsia {
namespace { namespace {
// static // static
ScopedZxHandle ConnectToServiceRoot() { zx::channel ConnectToServiceRoot() {
ScopedZxHandle h1; zx::channel client_channel;
ScopedZxHandle h2; zx::channel server_channel;
zx_status_t result = zx_channel_create(0, h1.receive(), h2.receive()); zx_status_t result = zx::channel::create(0, &client_channel, &server_channel);
ZX_CHECK(result == ZX_OK, result) << "zx_channel_create()"; ZX_CHECK(result == ZX_OK, result) << "zx_channel_create()";
result = fdio_service_connect("/svc/.", h1.release()); result = fdio_service_connect("/svc/.", server_channel.release());
ZX_CHECK(result == ZX_OK, result) << "Failed to open /svc"; ZX_CHECK(result == ZX_OK, result) << "Failed to open /svc";
return h2; return client_channel;
} }
} // namespace } // namespace
ComponentContext::ComponentContext(ScopedZxHandle service_root) ComponentContext::ComponentContext(zx::channel service_root)
: service_root_(std::move(service_root)) { : service_root_(std::move(service_root)) {
DCHECK(service_root_); DCHECK(service_root_);
} }
...@@ -51,4 +52,4 @@ void ComponentContext::ConnectToService(FidlInterfaceRequest request) { ...@@ -51,4 +52,4 @@ void ComponentContext::ConnectToService(FidlInterfaceRequest request) {
} }
} // namespace fuchsia } // namespace fuchsia
} // namespace base } // namespace base
\ No newline at end of file
...@@ -5,9 +5,10 @@ ...@@ -5,9 +5,10 @@
#ifndef BASE_FUCHSIA_COMPONENT_CONTEXT_H_ #ifndef BASE_FUCHSIA_COMPONENT_CONTEXT_H_
#define BASE_FUCHSIA_COMPONENT_CONTEXT_H_ #define BASE_FUCHSIA_COMPONENT_CONTEXT_H_
#include <lib/zx/channel.h>
#include "base/base_export.h" #include "base/base_export.h"
#include "base/fuchsia/fidl_interface_request.h" #include "base/fuchsia/fidl_interface_request.h"
#include "base/fuchsia/scoped_zx_handle.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/strings/string_piece.h" #include "base/strings/string_piece.h"
...@@ -27,7 +28,7 @@ namespace fuchsia { ...@@ -27,7 +28,7 @@ namespace fuchsia {
// Provides access to the component's environment. // Provides access to the component's environment.
class BASE_EXPORT ComponentContext { class BASE_EXPORT ComponentContext {
public: public:
explicit ComponentContext(ScopedZxHandle service_root); explicit ComponentContext(zx::channel service_root);
~ComponentContext(); ~ComponentContext();
// Returns default ComponentContext instance for the current process. It uses // Returns default ComponentContext instance for the current process. It uses
...@@ -55,7 +56,7 @@ class BASE_EXPORT ComponentContext { ...@@ -55,7 +56,7 @@ class BASE_EXPORT ComponentContext {
} }
private: private:
ScopedZxHandle service_root_; zx::channel service_root_;
DISALLOW_COPY_AND_ASSIGN(ComponentContext); DISALLOW_COPY_AND_ASSIGN(ComponentContext);
}; };
...@@ -63,4 +64,4 @@ class BASE_EXPORT ComponentContext { ...@@ -63,4 +64,4 @@ class BASE_EXPORT ComponentContext {
} // namespace fuchsia } // namespace fuchsia
} // namespace base } // namespace base
#endif // BASE_FUCHSIA_COMPONENT_CONTEXT_H_ #endif // BASE_FUCHSIA_COMPONENT_CONTEXT_H_
\ No newline at end of file
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <lib/fdio/util.h> #include <lib/fdio/util.h>
#include <lib/zx/channel.h> #include <lib/zx/channel.h>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/fuchsia/component_context.h" #include "base/fuchsia/component_context.h"
...@@ -51,8 +52,7 @@ TEST(ServicesDirectoryTest, Connect) { ...@@ -51,8 +52,7 @@ TEST(ServicesDirectoryTest, Connect) {
ZX_OK); ZX_OK);
// Create ComponentContext and connect to the test service. // Create ComponentContext and connect to the test service.
ComponentContext client_context( ComponentContext client_context(std::move(public_dir_client_channel));
base::ScopedZxHandle(public_dir_client_channel.release()));
auto stub = client_context.ConnectToService<test_fidl::TestInterface>(); auto stub = client_context.ConnectToService<test_fidl::TestInterface>();
// Call the service and wait for response. // 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