diff --git a/engine/src/flutter/shell/platform/fuchsia/dart_runner/dart_runner.cc b/engine/src/flutter/shell/platform/fuchsia/dart_runner/dart_runner.cc index bfcb00391e..4226754b77 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart_runner/dart_runner.cc +++ b/engine/src/flutter/shell/platform/fuchsia/dart_runner/dart_runner.cc @@ -17,6 +17,7 @@ #include #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*>(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 runner_incoming_services, ::fidl::InterfaceRequest 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 runner_incoming_services, + fidl::InterfaceRequest + 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 controller) { + fidl::InterfaceRequest 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 + 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 diff --git a/engine/src/flutter/shell/platform/fuchsia/dart_runner/dart_runner.h b/engine/src/flutter/shell/platform/fuchsia/dart_runner/dart_runner.h index 8e8b089ec9..cee7a7b34f 100644 --- a/engine/src/flutter/shell/platform/fuchsia/dart_runner/dart_runner.h +++ b/engine/src/flutter/shell/platform/fuchsia/dart_runner/dart_runner.h @@ -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 #include #include #include @@ -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 controller) - override; + void StartComponent(fuchsia::sys::Package package, + fuchsia::sys::StartupInfo startup_info, + fidl::InterfaceRequest + controller) override; + + // |fuchsia::component::runner::ComponentRunner| implementation: + void Start( + fuchsia::component::runner::ComponentStartInfo start_info, + fidl::InterfaceRequest + controller) override; // Not owned by DartRunner. sys::ComponentContext* context_;