From 25fcf531fabf2ac785597e3f9ecd61f25ba2f018 Mon Sep 17 00:00:00 2001 From: gaaclarke <30870216+gaaclarke@users.noreply.github.com> Date: Tue, 22 Oct 2019 14:01:52 -0700 Subject: [PATCH] Made restarting the Engine remember the last entrypoint that was used. (#13289) --- shell/common/engine.cc | 11 +++++++++++ shell/common/engine.h | 14 ++++++++++++++ shell/common/shell.cc | 7 +++---- shell/common/shell.h | 4 ---- shell/common/shell_unittests.cc | 27 +++++++++++++++++++++++++++ 5 files changed, 55 insertions(+), 8 deletions(-) diff --git a/shell/common/engine.cc b/shell/common/engine.cc index 3e183488282e5..10e826577e419 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -126,6 +126,9 @@ Engine::RunStatus Engine::Run(RunConfiguration configuration) { return RunStatus::Failure; } + last_entry_point_ = configuration.GetEntrypoint(); + last_entry_point_library_ = configuration.GetEntrypointLibrary(); + auto isolate_launch_status = PrepareAndLaunchIsolate(std::move(configuration)); if (isolate_launch_status == Engine::RunStatus::Failure) { @@ -501,4 +504,12 @@ void Engine::HandleAssetPlatformMessage(fml::RefPtr message) { response->CompleteEmpty(); } +const std::string& Engine::GetLastEntrypoint() const { + return last_entry_point_; +} + +const std::string& Engine::GetLastEntrypointLibrary() const { + return last_entry_point_library_; +} + } // namespace flutter diff --git a/shell/common/engine.h b/shell/common/engine.h index 75e8fcb7e18cb..64571063208d4 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -714,6 +714,18 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { // |PointerDataDispatcher::Delegate| void ScheduleSecondaryVsyncCallback(fml::closure callback) override; + //---------------------------------------------------------------------------- + /// @brief Get the last Entrypoint that was used in the RunConfiguration + /// when |Engine::Run| was called. + /// + const std::string& GetLastEntrypoint() const; + + //---------------------------------------------------------------------------- + /// @brief Get the last Entrypoint Library that was used in the + /// RunConfiguration when |Engine::Run| was called. + /// + const std::string& GetLastEntrypointLibrary() const; + private: Engine::Delegate& delegate_; const Settings settings_; @@ -725,6 +737,8 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate { // is destructed first. std::unique_ptr pointer_data_dispatcher_; + std::string last_entry_point_; + std::string last_entry_point_library_; std::string initial_route_; ViewportMetrics viewport_metrics_; std::shared_ptr asset_manager_; diff --git a/shell/common/shell.cc b/shell/common/shell.cc index 4bb7fd740f165..4151ef976ce5f 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -538,14 +538,10 @@ fml::WeakPtr Shell::GetRasterizer() { return weak_rasterizer_; } -// TODO(dnfield): Remove this when either Topaz is up to date or flutter_runner -// is built out of this repo. -#ifdef OS_FUCHSIA fml::WeakPtr Shell::GetEngine() { FML_DCHECK(is_setup_); return weak_engine_; } -#endif // OS_FUCHSIA fml::WeakPtr Shell::GetPlatformView() { FML_DCHECK(is_setup_); @@ -1264,6 +1260,9 @@ bool Shell::OnServiceProtocolRunInView( RunConfiguration configuration(std::move(isolate_configuration)); + configuration.SetEntrypointAndLibrary(engine_->GetLastEntrypoint(), + engine_->GetLastEntrypointLibrary()); + configuration.AddAssetResolver( std::make_unique(fml::OpenDirectory( asset_directory_path.c_str(), false, fml::FilePermission::kRead))); diff --git a/shell/common/shell.h b/shell/common/shell.h index cc3ed8fdc4481..74b3406ae3141 100644 --- a/shell/common/shell.h +++ b/shell/common/shell.h @@ -212,9 +212,6 @@ class Shell final : public PlatformView::Delegate, /// fml::WeakPtr GetRasterizer(); -// TODO(dnfield): Remove this when either Topaz is up to date or flutter_runner -// is built out of this repo. -#ifdef OS_FUCHSIA //------------------------------------------------------------------------------ /// @brief Engines may only be accessed on the UI thread. This method is /// deprecated, and implementers should instead use other API @@ -223,7 +220,6 @@ class Shell final : public PlatformView::Delegate, /// @return A weak pointer to the engine. /// fml::WeakPtr GetEngine(); -#endif // OS_FUCHSIA //---------------------------------------------------------------------------- /// @brief Platform views may only be accessed on the platform task diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index eb1299522d22c..840025e99658d 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -202,6 +202,33 @@ TEST_F(ShellTest, SecondaryIsolateBindingsAreSetupViaShellSettings) { ASSERT_FALSE(DartVMRef::IsInstanceRunning()); } +TEST_F(ShellTest, LastEntrypoint) { + ASSERT_FALSE(DartVMRef::IsInstanceRunning()); + auto settings = CreateSettingsForFixture(); + auto shell = CreateShell(settings); + ASSERT_TRUE(ValidateShell(shell.get())); + + auto configuration = RunConfiguration::InferFromSettings(settings); + ASSERT_TRUE(configuration.IsValid()); + std::string entry_point = "fixturesAreFunctionalMain"; + configuration.SetEntrypoint(entry_point); + + fml::AutoResetWaitableEvent main_latch; + std::string last_entry_point; + AddNativeCallback( + "SayHiFromFixturesAreFunctionalMain", CREATE_NATIVE_ENTRY([&](auto args) { + last_entry_point = shell->GetEngine()->GetLastEntrypoint(); + main_latch.Signal(); + })); + + RunEngine(shell.get(), std::move(configuration)); + main_latch.Wait(); + EXPECT_EQ(entry_point, last_entry_point); + ASSERT_TRUE(DartVMRef::IsInstanceRunning()); + DestroyShell(std::move(shell)); + ASSERT_FALSE(DartVMRef::IsInstanceRunning()); +} + TEST(ShellTestNoFixture, EnableMirrorsIsWhitelisted) { if (DartVM::IsRunningPrecompiledCode()) { // This covers profile and release modes which use AOT (where this flag does