[flutter_runner] Remove service_provider_dir.
Use one from libvfs which was copied from this implementation,
This CL depends on https://fuchsia-review.googlesource.com/c/fuchsia/+/277181
Change-Id: Ice3be8daf15f0636cdddc0902d6c041b23e4086d
diff --git a/runtime/flutter_runner/BUILD.gn b/runtime/flutter_runner/BUILD.gn
index f348922..f3f053d 100644
--- a/runtime/flutter_runner/BUILD.gn
+++ b/runtime/flutter_runner/BUILD.gn
@@ -83,8 +83,6 @@
"runner.h",
"runner_context.cc",
"runner_context.h",
- "service_provider_dir.cc",
- "service_provider_dir.h",
"session_connection.cc",
"session_connection.h",
"surface.cc",
diff --git a/runtime/flutter_runner/component.cc b/runtime/flutter_runner/component.cc
index a59ea12..a00ce52 100644
--- a/runtime/flutter_runner/component.cc
+++ b/runtime/flutter_runner/component.cc
@@ -11,27 +11,27 @@
#include <lib/fdio/directory.h>
#include <lib/fdio/namespace.h>
#include <lib/ui/scenic/cpp/view_token_pair.h>
+#include <lib/vfs/cpp/composed_service_dir.h>
#include <lib/vfs/cpp/remote_dir.h>
#include <lib/vfs/cpp/service.h>
#include <src/lib/files/file.h>
#include <sys/stat.h>
#include <zircon/dlfcn.h>
#include <zircon/status.h>
+
#include <regex>
#include <sstream>
#include "flutter/fml/synchronization/waitable_event.h"
#include "flutter/shell/common/switches.h"
+#include "task_observers.h"
#include "third_party/flutter/runtime/dart_vm_lifecycle.h"
+#include "thread.h"
#include "topaz/runtime/dart/utils/files.h"
#include "topaz/runtime/dart/utils/handle_exception.h"
#include "topaz/runtime/dart/utils/tempfs.h"
#include "topaz/runtime/dart/utils/vmo.h"
-#include "service_provider_dir.h"
-#include "task_observers.h"
-#include "thread.h"
-
namespace flutter_runner {
constexpr char kDataKey[] = "data";
@@ -160,8 +160,8 @@
fdio_service_connect_at(directory_ptr_.channel().get(), "public",
request.release());
- auto service_provider_dir = std::make_unique<ServiceProviderDir>();
- service_provider_dir->set_fallback(std::move(flutter_public_dir));
+ auto composed_service_dir = std::make_unique<vfs::ComposedServiceDir>();
+ composed_service_dir->set_fallback(std::move(flutter_public_dir));
// Clone and check if client is servicing the directory.
directory_ptr_->Clone(fuchsia::io::OPEN_FLAG_DESCRIBE |
@@ -198,7 +198,7 @@
// All launch arguments have been read. Perform service binding and
// final settings configuration. The next call will be to create a view
// for this application.
- service_provider_dir->AddService(
+ composed_service_dir->AddService(
fuchsia::ui::app::ViewProvider::Name_,
std::make_unique<vfs::Service>(
[this](zx::channel channel, async_dispatcher_t* dispatcher) {
@@ -207,7 +207,7 @@
std::move(channel)));
}));
- outgoing_dir_->AddEntry("public", std::move(service_provider_dir));
+ outgoing_dir_->AddEntry("public", std::move(composed_service_dir));
// Setup the application controller binding.
if (application_controller_request) {
@@ -436,9 +436,9 @@
"shared_snapshot_instructions.bin", true));
auto vm = flutter::DartVMRef::Create(settings_, //
- std::move(vm_snapshot), //
- isolate_snapshot_, //
- shared_snapshot_ //
+ std::move(vm_snapshot), //
+ isolate_snapshot_, //
+ shared_snapshot_ //
);
FML_CHECK(vm) << "Mut be able to initialize the VM.";
}
diff --git a/runtime/flutter_runner/service_provider_dir.cc b/runtime/flutter_runner/service_provider_dir.cc
deleted file mode 100644
index 8645828..0000000
--- a/runtime/flutter_runner/service_provider_dir.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2018 The Fuchsia 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 "topaz/runtime/flutter_runner/service_provider_dir.h"
-
-#include <lib/async/default.h>
-#include <lib/fdio/directory.h>
-#include <zircon/status.h>
-
-namespace flutter_runner {
-
-ServiceProviderDir::ServiceProviderDir() : root_(new vfs::PseudoDir()) {}
-
-ServiceProviderDir::~ServiceProviderDir() {}
-
-void ServiceProviderDir::set_fallback(
- fidl::InterfaceHandle<fuchsia::io::Directory> fallback_dir) {
- fallback_dir_ = fallback_dir.TakeChannel();
-}
-
-void ServiceProviderDir::AddService(const std::string& service_name,
- std::unique_ptr<vfs::Service> service) {
- root_->AddEntry(service_name, std::move(service));
-}
-
-zx_status_t ServiceProviderDir::GetAttr(
- fuchsia::io::NodeAttributes* out_attributes) const {
- return root_->GetAttr(out_attributes);
-}
-
-zx_status_t ServiceProviderDir::Readdir(uint64_t offset, void* data,
- uint64_t len, uint64_t* out_offset,
- uint64_t* out_actual) {
- // TODO(anmittal): enumerate fallback_dir_ in future once we have simple
- // implementation of fuchsia.io.Directory.
- return root_->Readdir(offset, data, len, out_offset, out_actual);
-}
-
-zx_status_t ServiceProviderDir::Lookup(const std::string& name,
- vfs::Node** out) const {
- zx_status_t status = root_->Lookup(name, out);
- if (status == ZX_OK) {
- return status;
- }
- if (fallback_dir_) {
- auto entry = fallback_services_.find(name);
- if (entry != fallback_services_.end()) {
- *out = entry->second.get();
- } else {
- auto service = std::make_unique<vfs::Service>(
- [name = std::string(name.data(), name.length()),
- dir = &fallback_dir_](zx::channel request,
- async_dispatcher_t* dispatcher) {
- fdio_service_connect_at(dir->get(), name.c_str(), request.release());
- });
- *out = service.get();
- fallback_services_[name] = std::move(service);
- }
- } else {
- return ZX_ERR_NOT_FOUND;
- }
- return ZX_OK;
-}
-
-} // namespace flutter_runner
diff --git a/runtime/flutter_runner/service_provider_dir.h b/runtime/flutter_runner/service_provider_dir.h
deleted file mode 100644
index 068f498..0000000
--- a/runtime/flutter_runner/service_provider_dir.h
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright 2018 The Fuchsia 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 TOPAZ_RUNTIME_FLUTTER_RUNNER_SERVICE_PROVIDER_DIR_H_
-#define TOPAZ_RUNTIME_FLUTTER_RUNNER_SERVICE_PROVIDER_DIR_H_
-
-#include <map>
-#include <string>
-#include <unordered_set>
-#include <utility>
-#include <vector>
-
-#include <fuchsia/io/cpp/fidl.h>
-#include <fuchsia/sys/cpp/fidl.h>
-#include <lib/vfs/cpp/pseudo_dir.h>
-#include <lib/vfs/cpp/service.h>
-
-#include "lib/fidl/cpp/binding_set.h"
-
-namespace flutter_runner {
-
-// A directory-like object which dynamically creates Service nodes
-// for any file lookup. It also exposes service provider interface.
-//
-// It supports enumeration for only first level of services.
-class ServiceProviderDir : public vfs::Directory {
- public:
- ServiceProviderDir();
- ~ServiceProviderDir() override;
-
- void set_fallback(fidl::InterfaceHandle<fuchsia::io::Directory> fallback_dir);
-
- void AddService(const std::string& service_name,
- std::unique_ptr<vfs::Service> service);
-
- //
- // Overridden from |vfs::Node|:
- //
-
- zx_status_t Lookup(const std::string& name, vfs::Node** out_node) const final;
-
- zx_status_t GetAttr(fuchsia::io::NodeAttributes* out_attributes) const final;
-
- zx_status_t Readdir(uint64_t offset, void* data, uint64_t len,
- uint64_t* out_offset, uint64_t* out_actual) final;
-
- private:
- // |root_| has all services offered by this provider (including those
- // inherited from the parent, if any).
- std::unique_ptr<vfs::PseudoDir> root_;
- zx::channel fallback_dir_;
- // The collection of services that have been looked up on the fallback
- // directory. These services are just passthrough in the sense that they
- // forward connection requests to the fallback directory. Since there is no
- // good way in the present context to know whether these service entries
- // actually match an existing service, and since the present object must own
- // these entries, we keep them around until the present object gets deleted.
- // Needs to be marked mutable so that it can be altered by the Lookup method.
- mutable std::map<std::string,
- std::unique_ptr<vfs::Service>> fallback_services_;
-
- // Disallow copy and assignment.
- ServiceProviderDir(const ServiceProviderDir&) = delete;
- ServiceProviderDir& operator=(const ServiceProviderDir&) = delete;
-};
-
-} // namespace flutter_runner
-
-#endif // TOPAZ_RUNTIME_FLUTTER_RUNNER_SERVICE_PROVIDER_DIR_H_