Skip to content

Commit

Permalink
Made restarting the Engine remember the last entrypoint that was used. (
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke authored Oct 22, 2019
1 parent fc6ac96 commit 25fcf53
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 8 deletions.
11 changes: 11 additions & 0 deletions shell/common/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -501,4 +504,12 @@ void Engine::HandleAssetPlatformMessage(fml::RefPtr<PlatformMessage> 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
14 changes: 14 additions & 0 deletions shell/common/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -725,6 +737,8 @@ class Engine final : public RuntimeDelegate, PointerDataDispatcher::Delegate {
// is destructed first.
std::unique_ptr<PointerDataDispatcher> pointer_data_dispatcher_;

std::string last_entry_point_;
std::string last_entry_point_library_;
std::string initial_route_;
ViewportMetrics viewport_metrics_;
std::shared_ptr<AssetManager> asset_manager_;
Expand Down
7 changes: 3 additions & 4 deletions shell/common/shell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -538,14 +538,10 @@ fml::WeakPtr<Rasterizer> 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<Engine> Shell::GetEngine() {
FML_DCHECK(is_setup_);
return weak_engine_;
}
#endif // OS_FUCHSIA

fml::WeakPtr<PlatformView> Shell::GetPlatformView() {
FML_DCHECK(is_setup_);
Expand Down Expand Up @@ -1264,6 +1260,9 @@ bool Shell::OnServiceProtocolRunInView(

RunConfiguration configuration(std::move(isolate_configuration));

configuration.SetEntrypointAndLibrary(engine_->GetLastEntrypoint(),
engine_->GetLastEntrypointLibrary());

configuration.AddAssetResolver(
std::make_unique<DirectoryAssetBundle>(fml::OpenDirectory(
asset_directory_path.c_str(), false, fml::FilePermission::kRead)));
Expand Down
4 changes: 0 additions & 4 deletions shell/common/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,6 @@ class Shell final : public PlatformView::Delegate,
///
fml::WeakPtr<Rasterizer> 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
Expand All @@ -223,7 +220,6 @@ class Shell final : public PlatformView::Delegate,
/// @return A weak pointer to the engine.
///
fml::WeakPtr<Engine> GetEngine();
#endif // OS_FUCHSIA

//----------------------------------------------------------------------------
/// @brief Platform views may only be accessed on the platform task
Expand Down
27 changes: 27 additions & 0 deletions shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 25fcf53

Please sign in to comment.