[fuchsia] Dart Runner for CF v2 components. (flutter/engine#28923)

Bug: fxb/79871

Implements the ComponentRunner protocol for the Dart runner, making the Dart runner compatible with CF v2.
This commit is contained in:
Alexander Biggs
2021-09-30 19:41:02 -04:00
committed by GitHub
parent bde0f38b61
commit dad7453c05
2 changed files with 57 additions and 9 deletions

View File

@@ -17,6 +17,7 @@
#include <utility>
#include "dart_component_controller.h"
#include "dart_component_controller_v2.h"
#include "flutter/fml/trace_event.h"
#include "logging.h"
#include "runtime/dart/utils/inlines.h"
@@ -32,6 +33,7 @@ extern "C" uint8_t _kDartVmSnapshotInstructions[];
#endif
namespace dart_runner {
namespace {
const char* kDartVMArgs[] = {
@@ -100,16 +102,19 @@ void IsolateGroupCleanupCallback(void* isolate_group_data) {
delete static_cast<std::shared_ptr<tonic::DartState>*>(isolate_group_data);
}
void RunApplication(
// Runs the application for a V1 component.
void RunApplicationV1(
DartRunner* runner,
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
::fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
int64_t start = Dart_TimelineGetMicros();
DartComponentController app(std::move(package), std::move(startup_info),
runner_incoming_services, std::move(controller));
bool success = app.Setup();
int64_t end = Dart_TimelineGetMicros();
Dart_TimelineEvent("DartComponentController::Setup", start, end,
Dart_Timeline_Event_Duration, 0, NULL, NULL);
@@ -122,6 +127,31 @@ void RunApplication(
}
}
// Runs the application for a V2 component.
void RunApplicationV2(
DartRunner* runner,
fuchsia::component::runner::ComponentStartInfo start_info,
std::shared_ptr<sys::ServiceDirectory> runner_incoming_services,
fidl::InterfaceRequest<fuchsia::component::runner::ComponentController>
controller) {
const int64_t start = Dart_TimelineGetMicros();
DartComponentControllerV2 app(std::move(start_info), runner_incoming_services,
std::move(controller));
const bool success = app.SetUp();
const int64_t end = Dart_TimelineGetMicros();
Dart_TimelineEvent("DartComponentControllerV2::Setup", start, end,
Dart_Timeline_Event_Duration, 0, NULL, NULL);
if (success) {
app.Run();
}
if (Dart_CurrentIsolate()) {
Dart_ShutdownIsolate();
}
}
bool EntropySource(uint8_t* buffer, intptr_t count) {
zx_cprng_draw(buffer, count);
return true;
@@ -192,7 +222,7 @@ DartRunner::~DartRunner() {
void DartRunner::StartComponent(
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
::fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller) {
// TRACE_DURATION currently requires that the string data does not change
// in the traced scope. Since |package| gets moved in the construction of
// |thread| below, we cannot ensure that |package.resolved_url| does not
@@ -201,10 +231,21 @@ void DartRunner::StartComponent(
// eagerly.
std::string url_copy = package.resolved_url;
TRACE_EVENT1("dart", "StartComponent", "url", url_copy.c_str());
std::thread thread(RunApplication, this, std::move(package),
std::thread thread(RunApplicationV1, this, std::move(package),
std::move(startup_info), context_->svc(),
std::move(controller));
thread.detach();
}
void DartRunner::Start(
fuchsia::component::runner::ComponentStartInfo start_info,
fidl::InterfaceRequest<fuchsia::component::runner::ComponentController>
controller) {
std::string url_copy = start_info.resolved_url();
TRACE_EVENT1("dart", "Start", "url", url_copy.c_str());
std::thread thread(RunApplicationV2, this, std::move(start_info),
context_->svc(), std::move(controller));
thread.detach();
}
} // namespace dart_runner

View File

@@ -5,6 +5,7 @@
#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_RUNNER_DART_RUNNER_H_
#define FLUTTER_SHELL_PLATFORM_FUCHSIA_DART_RUNNER_DART_RUNNER_H_
#include <fuchsia/component/runner/cpp/fidl.h>
#include <fuchsia/sys/cpp/fidl.h>
#include <lib/fidl/cpp/binding_set.h>
#include <lib/sys/cpp/component_context.h>
@@ -13,18 +14,24 @@
namespace dart_runner {
class DartRunner : public fuchsia::sys::Runner {
class DartRunner : public fuchsia::sys::Runner,
public fuchsia::component::runner::ComponentRunner {
public:
explicit DartRunner(sys::ComponentContext* context);
~DartRunner() override;
private:
// |fuchsia::sys::Runner| implementation:
void StartComponent(
fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
::fidl::InterfaceRequest<fuchsia::sys::ComponentController> controller)
override;
void StartComponent(fuchsia::sys::Package package,
fuchsia::sys::StartupInfo startup_info,
fidl::InterfaceRequest<fuchsia::sys::ComponentController>
controller) override;
// |fuchsia::component::runner::ComponentRunner| implementation:
void Start(
fuchsia::component::runner::ComponentStartInfo start_info,
fidl::InterfaceRequest<fuchsia::component::runner::ComponentController>
controller) override;
// Not owned by DartRunner.
sys::ComponentContext* context_;