[flutter_runner] Use sys::ComponentContext and remove RunnerContext
CF-776: #comment
Change-Id: Ie853a20a4b9259c1e8673c5ef12e68dc0321d4e3
diff --git a/runtime/flutter_runner/BUILD.gn b/runtime/flutter_runner/BUILD.gn
index 98a3bcb..07bb95a 100644
--- a/runtime/flutter_runner/BUILD.gn
+++ b/runtime/flutter_runner/BUILD.gn
@@ -81,8 +81,6 @@
"platform_view.h",
"runner.cc",
"runner.h",
- "runner_context.cc",
- "runner_context.h",
"session_connection.cc",
"session_connection.h",
"surface.cc",
@@ -261,7 +259,8 @@
path = rebase_path(
get_label_info(
"//topaz/runtime/dart/profiler_symbols:libdart_precompiled_runtime",
- "target_gen_dir") + "/libdart_precompiled_runtime.dartprofilersymbols")
+ "target_gen_dir") +
+ "/libdart_precompiled_runtime.dartprofilersymbols")
dest = "libdart_precompiled_runtime.dartprofilersymbols"
},
{
diff --git a/runtime/flutter_runner/runner.cc b/runtime/flutter_runner/runner.cc
index 2ab1f87..6629133 100644
--- a/runtime/flutter_runner/runner.cc
+++ b/runtime/flutter_runner/runner.cc
@@ -16,11 +16,12 @@
#include "flutter/fml/make_copyable.h"
#include "flutter/lib/ui/text/font_collection.h"
#include "fuchsia_font_manager.h"
+#include "lib/sys/cpp/component_context.h"
#include "third_party/flutter/runtime/dart_vm.h"
#include "third_party/icu/source/common/unicode/udata.h"
#include "third_party/skia/include/core/SkGraphics.h"
-#include "topaz/runtime/dart/utils/vmo.h"
#include "topaz/runtime/dart/utils/files.h"
+#include "topaz/runtime/dart/utils/vmo.h"
#include "topaz/runtime/dart/utils/vmservice_object.h"
namespace flutter_runner {
@@ -103,13 +104,12 @@
#endif // !defined(DART_PRODUCT)
Runner::Runner(async::Loop* loop)
- : loop_(loop),
- runner_context_(RunnerContext::CreateFromStartupInfo()) {
+ : loop_(loop), context_(sys::ComponentContext::Create()) {
#if !defined(DART_PRODUCT)
// The VM service isolate uses the process-wide namespace. It writes the
// vm service protocol port under /tmp. The VMServiceObject exposes that
// port number to The Hub.
- runner_context_->debug_dir()->AddEntry(
+ context_->outgoing()->debug_dir()->AddEntry(
dart_utils::VMServiceObject::kPortDirName,
std::make_unique<dart_utils::VMServiceObject>());
@@ -124,13 +124,14 @@
SetThreadName("io.flutter.runner.main");
- runner_context_->AddPublicService<fuchsia::sys::Runner>(
+ context_->outgoing()->AddPublicService<fuchsia::sys::Runner>(
std::bind(&Runner::RegisterApplication, this, std::placeholders::_1));
#if !defined(DART_PRODUCT)
if (Dart_IsPrecompiledRuntime()) {
- RegisterProfilerSymbols("pkg/data/libdart_precompiled_runtime.dartprofilersymbols",
- "libdart_precompiled_runtime.so");
+ RegisterProfilerSymbols(
+ "pkg/data/libdart_precompiled_runtime.dartprofilersymbols",
+ "libdart_precompiled_runtime.so");
RegisterProfilerSymbols("pkg/data/flutter_aot_runner.dartprofilersymbols",
"");
} else {
@@ -143,7 +144,7 @@
}
Runner::~Runner() {
- runner_context_->RemovePublicService<fuchsia::sys::Runner>();
+ context_->outgoing()->RemovePublicService<fuchsia::sys::Runner>();
#if !defined(DART_PRODUCT)
trace_observer_->Stop();
@@ -179,7 +180,7 @@
std::move(termination_callback), // termination callback
std::move(package), // application pacakge
std::move(startup_info), // startup info
- runner_context_->svc(), // runner incoming services
+ context_->svc(), // runner incoming services
std::move(controller) // controller request
);
diff --git a/runtime/flutter_runner/runner.h b/runtime/flutter_runner/runner.h
index 3ebf90a..fd73f63 100644
--- a/runtime/flutter_runner/runner.h
+++ b/runtime/flutter_runner/runner.h
@@ -5,19 +5,18 @@
#ifndef TOPAZ_RUNTIME_FLUTTER_RUNNER_RUNNER_H_
#define TOPAZ_RUNTIME_FLUTTER_RUNNER_RUNNER_H_
-#include <memory>
-#include <unordered_map>
-
#include <fuchsia/sys/cpp/fidl.h>
#include <lib/async-loop/cpp/loop.h>
#include <lib/sys/cpp/component_context.h>
-#include <trace/observer.h>
#include <trace-engine/instrumentation.h>
+#include <trace/observer.h>
+
+#include <memory>
+#include <unordered_map>
#include "component.h"
#include "flutter/fml/macros.h"
#include "lib/fidl/cpp/binding_set.h"
-#include "runner_context.h"
#include "thread.h"
#include "topaz/runtime/dart/utils/vmservice_object.h"
@@ -38,15 +37,14 @@
std::unique_ptr<Thread> thread;
std::unique_ptr<Application> application;
- ActiveApplication(std::pair<std::unique_ptr<Thread>,
- std::unique_ptr<Application>>
- pair)
+ ActiveApplication(
+ std::pair<std::unique_ptr<Thread>, std::unique_ptr<Application>> pair)
: thread(std::move(pair.first)), application(std::move(pair.second)) {}
ActiveApplication() = default;
};
- std::unique_ptr<RunnerContext> runner_context_;
+ std::unique_ptr<sys::ComponentContext> context_;
fidl::BindingSet<fuchsia::sys::Runner> active_applications_bindings_;
std::unordered_map<const Application*, ActiveApplication>
active_applications_;
diff --git a/runtime/flutter_runner/runner_context.cc b/runtime/flutter_runner/runner_context.cc
deleted file mode 100644
index dd697e0..0000000
--- a/runtime/flutter_runner/runner_context.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2019 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 "runner_context.h"
-
-namespace flutter_runner {
-
-RunnerContext::RunnerContext(std::shared_ptr<sys::ServiceDirectory> svc,
- zx::channel directory_request)
- : svc_(std::move(svc)),
- root_dir_(std::make_shared<vfs::PseudoDir>()),
- public_dir_(std::make_shared<vfs::PseudoDir>()),
- debug_dir_(std::make_shared<vfs::PseudoDir>()),
- ctrl_dir_(std::make_shared<vfs::PseudoDir>()) {
- root_dir_->AddSharedEntry("public", public_dir_);
- root_dir_->AddSharedEntry("debug", debug_dir_);
- root_dir_->AddSharedEntry("ctrl", ctrl_dir_);
-
- root_dir_->Serve(
- fuchsia::io::OPEN_RIGHT_READABLE | fuchsia::io::OPEN_RIGHT_WRITABLE,
- std::move(directory_request));
-}
-
-RunnerContext::~RunnerContext() = default;
-
-std::unique_ptr<RunnerContext> RunnerContext::CreateFromStartupInfo() {
- zx_handle_t directory_request = zx_take_startup_handle(PA_DIRECTORY_REQUEST);
- return std::make_unique<RunnerContext>(
- sys::ServiceDirectory::CreateFromNamespace(),
- zx::channel(directory_request));
-}
-
-zx_status_t RunnerContext::AddPublicService(
- std::unique_ptr<vfs::Service> service, std::string service_name) const {
- return public_dir_->AddEntry(std::move(service_name), std::move(service));
-}
-
-} // namespace flutter_runner
diff --git a/runtime/flutter_runner/runner_context.h b/runtime/flutter_runner/runner_context.h
deleted file mode 100644
index 6875f12..0000000
--- a/runtime/flutter_runner/runner_context.h
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2019 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_RUNNER_CONTEXT_H_
-#define TOPAZ_RUNTIME_FLUTTER_RUNNER_RUNNER_CONTEXT_H_
-
-#include <memory>
-#include <unordered_map>
-
-#include <fuchsia/sys/cpp/fidl.h>
-#include <lib/async-loop/cpp/loop.h>
-#include <lib/sys/cpp/component_context.h>
-#include <lib/vfs/cpp/pseudo_dir.h>
-#include <lib/vfs/cpp/service.h>
-#include <zircon/process.h>
-#include <zircon/processargs.h>
-
-#include "flutter/fml/macros.h"
-
-namespace flutter_runner {
-
-class RunnerContext {
- public:
- RunnerContext(std::shared_ptr<sys::ServiceDirectory> svc,
- zx::channel directory_request);
- ~RunnerContext();
-
- static std::unique_ptr<RunnerContext> CreateFromStartupInfo();
-
- const std::shared_ptr<sys::ServiceDirectory>& svc() const { return svc_; }
- const std::shared_ptr<vfs::PseudoDir>& root_dir() const { return root_dir_; }
- const std::shared_ptr<vfs::PseudoDir>& public_dir() const { return public_dir_; }
- const std::shared_ptr<vfs::PseudoDir>& debug_dir() const { return debug_dir_; }
- const std::shared_ptr<vfs::PseudoDir>& ctrl_dir() const { return ctrl_dir_; }
-
- template <typename Interface>
- zx_status_t AddPublicService(
- fidl::InterfaceRequestHandler<Interface> handler,
- std::string service_name = Interface::Name_) const {
- return AddPublicService(std::make_unique<vfs::Service>(std::move(handler)),
- std::move(service_name));
- }
-
- zx_status_t AddPublicService(std::unique_ptr<vfs::Service> service,
- std::string service_name) const;
-
- template <typename Interface>
- zx_status_t RemovePublicService(
- const std::string& name = Interface::Name_) const {
- return public_dir_->RemoveEntry(name);
- }
-
- private:
- std::shared_ptr<sys::ServiceDirectory> svc_;
- std::shared_ptr<vfs::PseudoDir> root_dir_;
- std::shared_ptr<vfs::PseudoDir> public_dir_;
- std::shared_ptr<vfs::PseudoDir> debug_dir_;
- std::shared_ptr<vfs::PseudoDir> ctrl_dir_;
-
- FML_DISALLOW_COPY_AND_ASSIGN(RunnerContext);
-};
-
-} // namespace flutter_runner
-
-#endif // TOPAZ_RUNTIME_FLUTTER_RUNNER_RUNNER_CONTEXT_H_