diff --git a/assets/directory_asset_bundle.cc b/assets/directory_asset_bundle.cc index afb419c300f2099c0ca587cefa40258cf3d24bd2..9d4f2935f7d24cc4086ab52d44b2c3781868e41b 100644 --- a/assets/directory_asset_bundle.cc +++ b/assets/directory_asset_bundle.cc @@ -23,49 +23,15 @@ namespace blink { bool DirectoryAssetBundle::GetAsBuffer(const std::string& asset_name, std::vector* data) { std::string asset_path = GetPathForAsset(asset_name); - if (asset_path.empty()) return false; - - if (fd_.is_valid()) { - fxl::UniqueFD asset_file(openat(fd_.get(), asset_path.c_str(), O_RDONLY)); - if (!asset_file.is_valid()) { - FXL_LOG(ERROR) << "Could not load asset " << asset_name << " from " - << asset_path; - return false; - } - - constexpr size_t kBufferSize = 1 << 16; - size_t offset = 0; - ssize_t bytes_read = 0; - do { - offset += bytes_read; - data->resize(offset + kBufferSize); - bytes_read = read(asset_file.get(), &(*data)[offset], kBufferSize); - } while (bytes_read > 0); - - if (bytes_read < 0) { - FXL_LOG(ERROR) << "Reading " << asset_name << " failed"; - data->clear(); - return false; - } - - data->resize(offset + bytes_read); - return true; - } - return files::ReadFileToVector(asset_path, data); } DirectoryAssetBundle::~DirectoryAssetBundle() {} DirectoryAssetBundle::DirectoryAssetBundle(std::string directory) - : directory_(std::move(directory)), - fd_(fxl::internal::UniqueFDTraits::InvalidValue()) {} - -DirectoryAssetBundle::DirectoryAssetBundle(fxl::UniqueFD fd, - std::string directory) - : directory_(std::move(directory)), fd_(std::move(fd)) {} + : directory_(std::move(directory)) {} std::string DirectoryAssetBundle::GetPathForAsset( const std::string& asset_name) { diff --git a/assets/directory_asset_bundle.h b/assets/directory_asset_bundle.h index 0a2cf297263fc6365bec938577f45ac987f24903..7c1466d737218b35c01231ffa4ee090e608357e6 100644 --- a/assets/directory_asset_bundle.h +++ b/assets/directory_asset_bundle.h @@ -8,7 +8,6 @@ #include #include -#include "lib/fxl/files/unique_fd.h" #include "lib/fxl/macros.h" #include "lib/fxl/memory/ref_counted.h" @@ -18,8 +17,6 @@ class DirectoryAssetBundle : public fxl::RefCountedThreadSafe { public: explicit DirectoryAssetBundle(std::string directory); - // Expects fd to be valid, otherwise the file descriptor is ignored. - explicit DirectoryAssetBundle(fxl::UniqueFD fd, std::string directory); ~DirectoryAssetBundle(); bool GetAsBuffer(const std::string& asset_name, std::vector* data); @@ -28,7 +25,6 @@ class DirectoryAssetBundle private: const std::string directory_; - fxl::UniqueFD fd_; FXL_DISALLOW_COPY_AND_ASSIGN(DirectoryAssetBundle); }; diff --git a/content_handler/application_controller_impl.cc b/content_handler/application_controller_impl.cc index b49433de0e84f86f4bf3c74153486d767d1978ea..1922846234ca544716cb50d631ac078ca47b790e 100644 --- a/content_handler/application_controller_impl.cc +++ b/content_handler/application_controller_impl.cc @@ -32,11 +32,9 @@ ApplicationControllerImpl::ApplicationControllerImpl( } std::vector bundle; - if (application->data) { - if (!fsl::VectorFromVmo(std::move(application->data), &bundle)) { - FXL_LOG(ERROR) << "Failed to receive bundle."; - return; - } + if (!fsl::VectorFromVmo(std::move(application->data), &bundle)) { + FXL_LOG(ERROR) << "Failed to receive bundle."; + return; } // TODO(jeffbrown): Decide what to do with command-line arguments and diff --git a/content_handler/runtime_holder.cc b/content_handler/runtime_holder.cc index 51cea77573c03b42ac6dc0f71f311963695e250c..e42ad668561efe27d1bc979e32a5980742bf4292 100644 --- a/content_handler/runtime_holder.cc +++ b/content_handler/runtime_holder.cc @@ -23,7 +23,6 @@ #include "flutter/runtime/runtime_init.h" #include "lib/app/cpp/connect.h" #include "lib/fsl/vmo/vector.h" -#include "lib/fxl/files/unique_fd.h" #include "lib/fxl/functional/make_copyable.h" #include "lib/fxl/logging.h" #include "lib/fxl/time/time_delta.h" @@ -46,7 +45,6 @@ constexpr char kAssetChannel[] = "flutter/assets"; constexpr char kKeyEventChannel[] = "flutter/keyevent"; constexpr char kTextInputChannel[] = "flutter/textinput"; constexpr char kFlutterPlatformChannel[] = "flutter/platform"; -constexpr char kFuchsiaPackageResourceDirectory[] = "pkg/data"; void SetThreadName(fxl::RefPtr runner, std::string name) { runner->PostTask([name]() { @@ -119,7 +117,6 @@ void RuntimeHolder::Init( context_->ConnectToEnvironmentService(view_manager_.NewRequest()); - // TODO(zarah): remove bundle entirely once flx is removed. InitRootBundle(std::move(bundle)); const uint8_t* vm_snapshot_data; @@ -133,7 +130,7 @@ void RuntimeHolder::Init( default_isolate_snapshot_instr = ::kDartIsolateCoreSnapshotInstructions; } else { std::vector dylib_blob; - if (!GetAssetAsBuffer(kDylibKey, &dylib_blob)) { + if (!asset_store_->GetAsBuffer(kDylibKey, &dylib_blob)) { FXL_LOG(ERROR) << "Failed to extract app dylib"; return; } @@ -196,8 +193,8 @@ void RuntimeHolder::CreateView( std::vector kernel; std::vector snapshot; if (!Dart_IsPrecompiledRuntime()) { - if (!GetAssetAsBuffer(kKernelKey, &kernel) && - !GetAssetAsBuffer(kSnapshotKey, &snapshot)) { + if (!asset_store_->GetAsBuffer(kKernelKey, &kernel) && + !asset_store_->GetAsBuffer(kSnapshotKey, &snapshot)) { FXL_LOG(ERROR) << "Unable to load kernel or snapshot from root bundle."; return; } @@ -390,11 +387,8 @@ void RuntimeHolder::HandlePlatformMessage( } void RuntimeHolder::DidCreateMainIsolate(Dart_Isolate isolate) { - if (directory_asset_bundle_) { - blink::AssetFontSelector::Install(directory_asset_bundle_); - } else if (asset_store_) { + if (asset_store_) blink::AssetFontSelector::Install(asset_store_); - } InitDartIoInternal(); InitFuchsia(); InitMozartInternal(); @@ -454,19 +448,9 @@ void RuntimeHolder::InitMozartInternal() { } void RuntimeHolder::InitRootBundle(std::vector bundle) { - if (!bundle.empty()) { - root_bundle_data_ = std::move(bundle); - asset_store_ = fxl::MakeRefCounted( - GetUnzipperProviderForRootBundle()); - } else { - fxl::UniqueFD root_dir(fdio_ns_opendir(namespc_)); - if (!root_dir.is_valid()) { - FXL_LOG(ERROR) << "Unable to load root dir"; - return; - } - directory_asset_bundle_ = fxl::MakeRefCounted( - std::move(root_dir), kFuchsiaPackageResourceDirectory); - } + root_bundle_data_ = std::move(bundle); + asset_store_ = fxl::MakeRefCounted( + GetUnzipperProviderForRootBundle()); } mozart::View* RuntimeHolder::GetMozartView() { @@ -482,7 +466,7 @@ bool RuntimeHolder::HandleAssetPlatformMessage( std::string asset_name(reinterpret_cast(data.data()), data.size()); std::vector asset_data; - if (GetAssetAsBuffer(asset_name, &asset_data)) { + if (asset_store_ && asset_store_->GetAsBuffer(asset_name, &asset_data)) { response->Complete(std::move(asset_data)); } else { response->CompleteEmpty(); @@ -490,13 +474,6 @@ bool RuntimeHolder::HandleAssetPlatformMessage( return true; } -bool RuntimeHolder::GetAssetAsBuffer(const std::string& name, - std::vector* data) { - return (directory_asset_bundle_ && - directory_asset_bundle_->GetAsBuffer(name, data)) || - (asset_store_ && asset_store_->GetAsBuffer(name, data)); -} - bool RuntimeHolder::HandleFlutterPlatformMessage( blink::PlatformMessage* message) { const auto& data = message->data(); diff --git a/content_handler/runtime_holder.h b/content_handler/runtime_holder.h index 4b616c979d6d9c1f0ea59e25be452da6ef8bf6a1..b726ee472b375d72e43d53ab99404f3bba81d00a 100644 --- a/content_handler/runtime_holder.h +++ b/content_handler/runtime_holder.h @@ -11,7 +11,6 @@ #include #include "dart-pkg/fuchsia/sdk_ext/fuchsia.h" -#include "flutter/assets/directory_asset_bundle.h" #include "flutter/assets/unzipper_provider.h" #include "flutter/assets/zip_asset_store.h" #include "flutter/content_handler/accessibility_bridge.h" @@ -93,7 +92,6 @@ class RuntimeHolder : public blink::RuntimeDelegate, void InitRootBundle(std::vector bundle); blink::UnzipperProvider GetUnzipperProviderForRootBundle(); bool HandleAssetPlatformMessage(blink::PlatformMessage* message); - bool GetAssetAsBuffer(const std::string& name, std::vector* data); bool HandleTextInputPlatformMessage(blink::PlatformMessage* message); bool HandleFlutterPlatformMessage(blink::PlatformMessage* message); @@ -111,9 +109,7 @@ class RuntimeHolder : public blink::RuntimeDelegate, std::unique_ptr context_; fidl::InterfaceRequest outgoing_services_; std::vector root_bundle_data_; - // TODO(zarah): Remove asset_store_ when flx is completely removed fxl::RefPtr asset_store_; - fxl::RefPtr directory_asset_bundle_; void* dylib_handle_ = nullptr; std::unique_ptr rasterizer_; std::unique_ptr runtime_;