diff --git a/shell/common/engine.cc b/shell/common/engine.cc index e8994a5a1e2f7f4adfa9e2fcb262aac378e27b47..3629b729c29f7438e49ca8264c24ec5a84889e4a 100644 --- a/shell/common/engine.cc +++ b/shell/common/engine.cc @@ -301,7 +301,14 @@ void Engine::RunBundle(const std::string& bundle_path, bool reuse_runtime_controller) { TRACE_EVENT0("flutter", "Engine::RunBundle"); ConfigureAssetBundle(bundle_path); - ConfigureRuntime(GetScriptUriFromPath(bundle_path), reuse_runtime_controller); + DoRunBundle(GetScriptUriFromPath(bundle_path), entrypoint, + reuse_runtime_controller); +} + +void Engine::DoRunBundle(const std::string& script_uri, + const std::string& entrypoint, + bool reuse_runtime_controller) { + ConfigureRuntime(script_uri, reuse_runtime_controller); if (blink::IsRunningPrecompiledCode()) { runtime_->dart_controller()->RunFromPrecompiledSnapshot(entrypoint); } else { @@ -318,26 +325,16 @@ void Engine::RunBundle(const std::string& bundle_path, } } -void Engine::RunBundleAndSnapshot(const std::string& bundle_path, - const std::string& snapshot_override, - const std::string& entrypoint, - bool reuse_runtime_controller) { - TRACE_EVENT0("flutter", "Engine::RunBundleAndSnapshot"); - if (snapshot_override.empty()) { - RunBundle(bundle_path, entrypoint, reuse_runtime_controller); - return; - } - ConfigureAssetBundle(bundle_path); - ConfigureRuntime(GetScriptUriFromPath(bundle_path), reuse_runtime_controller); - if (blink::IsRunningPrecompiledCode()) { - runtime_->dart_controller()->RunFromPrecompiledSnapshot(entrypoint); - } else { - std::vector snapshot; - if (!files::ReadFileToVector(snapshot_override, &snapshot)) - return; - runtime_->dart_controller()->RunFromScriptSnapshot( - snapshot.data(), snapshot.size(), entrypoint); - } +// TODO(jsimmons): merge this with RunBundle +void Engine::RunBundleWithAssets( + fxl::RefPtr asset_provider, + const std::string& bundle_path, + const std::string& entrypoint, + bool reuse_runtime_controller) { + TRACE_EVENT0("flutter", "Engine::RunBundleWithAssets"); + asset_provider_ = asset_provider; + DoRunBundle(GetScriptUriFromPath(bundle_path), entrypoint, + reuse_runtime_controller); } void Engine::RunBundleAndSource(const std::string& bundle_path, @@ -572,11 +569,7 @@ void Engine::SetSemanticsEnabled(bool enabled) { } void Engine::ConfigureAssetBundle(const std::string& path) { - auto platform_view = platform_view_.lock(); - asset_provider_ = platform_view->GetAssetProvider(); - if (!asset_provider_) { - asset_provider_ = fxl::MakeRefCounted(path); - } + asset_provider_ = fxl::MakeRefCounted(path); struct stat stat_result = {}; diff --git a/shell/common/engine.h b/shell/common/engine.h index e5d327ae625cf2a9ec8460142e194647ffdb32bc..a0c5183338a434f5c1522bf7c051c3f216371f28 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -40,13 +40,11 @@ class Engine : public blink::RuntimeDelegate { const std::string& entrypoint = main_entrypoint_, bool reuse_runtime_controller = false); - // Uses the given snapshot instead of looking inside the bundle for the - // snapshot. If |snapshot_override| is empty, this function looks for the - // snapshot in the bundle itself. - void RunBundleAndSnapshot(const std::string& bundle_path, - const std::string& snapshot_override, - const std::string& entrypoint = main_entrypoint_, - bool reuse_runtime_controller = false); + // Uses the given provider to locate assets. + void RunBundleWithAssets(fxl::RefPtr asset_provider, + const std::string& bundle_path, + const std::string& entrypoint = main_entrypoint_, + bool reuse_runtime_controller = false); // Uses the given source code instead of looking inside the bundle for the // source code. @@ -95,6 +93,10 @@ class Engine : public blink::RuntimeDelegate { void StopAnimator(); void StartAnimatorIfPossible(); + void DoRunBundle(const std::string& script_uri, + const std::string& entrypoint, + bool reuse_runtime_controller); + void ConfigureAssetBundle(const std::string& path); void ConfigureRuntime(const std::string& script_uri, bool reuse_runtime_controller = false); diff --git a/shell/common/platform_view.cc b/shell/common/platform_view.cc index b015b8c4a115befe2834b57d415367bc509131dc..2d5715a1733bdc9ec7d1fe84f907a86e784a307e 100644 --- a/shell/common/platform_view.cc +++ b/shell/common/platform_view.cc @@ -126,10 +126,6 @@ VsyncWaiter* PlatformView::GetVsyncWaiter() { return vsync_waiter_.get(); } -fxl::RefPtr PlatformView::GetAssetProvider() { - return asset_provider_; -} - void PlatformView::UpdateSemantics(blink::SemanticsNodeUpdates update) {} void PlatformView::HandlePlatformMessage( diff --git a/shell/common/platform_view.h b/shell/common/platform_view.h index 75e0124ba7c81edb4a8837190027290c8d768c16..1162bc1ec8145c2fe2998b247f3787b6d14b61ea 100644 --- a/shell/common/platform_view.h +++ b/shell/common/platform_view.h @@ -7,7 +7,6 @@ #include -#include "flutter/assets/asset_provider.h" #include "flutter/flow/texture.h" #include "flutter/lib/ui/semantics/semantics_node.h" #include "flutter/shell/common/engine.h" @@ -65,8 +64,6 @@ class PlatformView : public std::enable_shared_from_this { virtual void HandlePlatformMessage( fxl::RefPtr message); - virtual fxl::RefPtr GetAssetProvider(); - // Called once per texture, on the platform thread. void RegisterTexture(std::shared_ptr texture); @@ -100,7 +97,6 @@ class PlatformView : public std::enable_shared_from_this { flow::TextureRegistry texture_registry_; std::unique_ptr engine_; std::unique_ptr vsync_waiter_; - fxl::RefPtr asset_provider_; SkISize size_; diff --git a/shell/platform/android/platform_view_android.cc b/shell/platform/android/platform_view_android.cc index 7c1d115fc9f98006408175c70127bf39c10cc6d9..931fc28575ea3160b7b3c83ab3252f3adce5bccc 100644 --- a/shell/platform/android/platform_view_android.cc +++ b/shell/platform/android/platform_view_android.cc @@ -213,22 +213,28 @@ void PlatformViewAndroid::RunBundleAndSnapshot(JNIEnv* env, std::string bundle_p std::string entrypoint, bool reuse_runtime_controller, jobject assetManager) { - // The flutter assets directory name is the last directory of the bundle_path and the path into the APK + // TODO(jsimmons): remove snapshot_override from the public FlutterView API + FXL_CHECK(snapshot_override.empty()) << "snapshot_override is obsolete"; + + // The flutter assets directory name is the last directory of the bundle_path + // and the path into the APK size_t last_slash_idx = bundle_path.rfind("/", bundle_path.size()); - std::string flutter_assets_dir = bundle_path.substr(last_slash_idx+1, bundle_path.size()-last_slash_idx); + std::string flutter_assets_dir = bundle_path.substr( + last_slash_idx + 1, bundle_path.size() - last_slash_idx); - asset_provider_ = fxl::MakeRefCounted(env, assetManager, flutter_assets_dir); - blink::Threads::UI()->PostTask([ - engine = engine_->GetWeakPtr(), bundle_path = std::move(bundle_path), - snapshot_override = std::move(snapshot_override), - entrypoint = std::move(entrypoint), - reuse_runtime_controller = reuse_runtime_controller - ] { - if (engine) - engine->RunBundleAndSnapshot( - std::move(bundle_path), std::move(snapshot_override), - std::move(entrypoint), reuse_runtime_controller); - }); + fxl::RefPtr asset_provider = + fxl::MakeRefCounted(env, assetManager, + flutter_assets_dir); + blink::Threads::UI()->PostTask( + [engine = engine_->GetWeakPtr(), + asset_provider = std::move(asset_provider), + bundle_path = std::move(bundle_path), entrypoint = std::move(entrypoint), + reuse_runtime_controller = reuse_runtime_controller] { + if (engine) + engine->RunBundleWithAssets( + std::move(asset_provider), std::move(bundle_path), + std::move(entrypoint), reuse_runtime_controller); + }); } void PlatformViewAndroid::RunBundleAndSource(std::string bundle_path,