From 0e31f0102cbc99991e88f438f056b3b9f74307dc Mon Sep 17 00:00:00 2001 From: israel4435-sys Date: Wed, 27 Aug 2025 17:12:23 -0700 Subject: [PATCH] Delete assets directory --- assets/BUILD.gn | 58 ------------- assets/asset_manager.cc | 131 ---------------------------- assets/asset_manager.h | 105 ----------------------- assets/asset_resolver.h | 108 ------------------------ assets/directory_asset_bundle.cc | 123 --------------------------- assets/directory_asset_bundle.h | 59 ------------- assets/native_assets.cc | 136 ------------------------------ assets/native_assets.h | 54 ------------ assets/native_assets_unittests.cc | 90 -------------------- 9 files changed, 864 deletions(-) delete mode 100644 assets/BUILD.gn delete mode 100644 assets/asset_manager.cc delete mode 100644 assets/asset_manager.h delete mode 100644 assets/asset_resolver.h delete mode 100644 assets/directory_asset_bundle.cc delete mode 100644 assets/directory_asset_bundle.h delete mode 100644 assets/native_assets.cc delete mode 100644 assets/native_assets.h delete mode 100644 assets/native_assets_unittests.cc diff --git a/assets/BUILD.gn b/assets/BUILD.gn deleted file mode 100644 index c470cb6971c3f..0000000000000 --- a/assets/BUILD.gn +++ /dev/null @@ -1,58 +0,0 @@ -# Copyright 2013 The Flutter Authors. All rights reserved. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import("//flutter/common/config.gni") -import("//flutter/testing/testing.gni") - -if (is_fuchsia) { - import("//flutter/tools/fuchsia/gn-sdk/src/gn_configs.gni") -} - -source_set("assets") { - sources = [ - "asset_manager.cc", - "asset_manager.h", - "asset_resolver.h", - "directory_asset_bundle.cc", - "directory_asset_bundle.h", - "native_assets.cc", - "native_assets.h", - ] - - deps = [ - "//flutter/common", - "//flutter/fml", - "//flutter/third_party/rapidjson", - ] - - public_configs = [ "//flutter:config" ] -} - -test_fixtures("assets_fixtures") { - fixtures = [] -} - -if (enable_unittests) { - executable("assets_unittests") { - testonly = true - - sources = [ "native_assets_unittests.cc" ] - - deps = [ - ":assets", - ":assets_fixtures", - "//flutter/testing", - ] - - if (!defined(defines)) { - defines = [] - } - - # This is needed for //flutter/third_party/googletest for linking zircon - # symbols. - if (is_fuchsia) { - libs = [ "${fuchsia_arch_root}/sysroot/lib/libzircon.so" ] - } - } -} diff --git a/assets/asset_manager.cc b/assets/asset_manager.cc deleted file mode 100644 index d18cf921f3975..0000000000000 --- a/assets/asset_manager.cc +++ /dev/null @@ -1,131 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/assets/asset_manager.h" - -#include "flutter/assets/directory_asset_bundle.h" -#include "flutter/fml/trace_event.h" - -namespace flutter { - -AssetManager::AssetManager() = default; - -AssetManager::~AssetManager() = default; - -bool AssetManager::PushFront(std::unique_ptr resolver) { - if (resolver == nullptr || !resolver->IsValid()) { - return false; - } - - resolvers_.push_front(std::move(resolver)); - return true; -} - -bool AssetManager::PushBack(std::unique_ptr resolver) { - if (resolver == nullptr || !resolver->IsValid()) { - return false; - } - - resolvers_.push_back(std::move(resolver)); - return true; -} - -void AssetManager::UpdateResolverByType( - std::unique_ptr updated_asset_resolver, - AssetResolver::AssetResolverType type) { - if (updated_asset_resolver == nullptr) { - return; - } - bool updated = false; - std::deque> new_resolvers; - for (auto& old_resolver : resolvers_) { - if (!updated && old_resolver->GetType() == type) { - // Push the replacement updated resolver in place of the old_resolver. - new_resolvers.push_back(std::move(updated_asset_resolver)); - updated = true; - } else { - new_resolvers.push_back(std::move(old_resolver)); - } - } - // Append resolver to the end if not used as a replacement. - if (!updated) { - new_resolvers.push_back(std::move(updated_asset_resolver)); - } - resolvers_.swap(new_resolvers); -} - -std::deque> AssetManager::TakeResolvers() { - return std::move(resolvers_); -} - -// |AssetResolver| -std::unique_ptr AssetManager::GetAsMapping( - const std::string& asset_name) const { - if (asset_name.empty()) { - return nullptr; - } - TRACE_EVENT1("flutter", "AssetManager::GetAsMapping", "name", - asset_name.c_str()); - for (const auto& resolver : resolvers_) { - auto mapping = resolver->GetAsMapping(asset_name); - if (mapping != nullptr) { - return mapping; - } - } - FML_DLOG(WARNING) << "Could not find asset: " << asset_name; - return nullptr; -} - -// |AssetResolver| -std::vector> AssetManager::GetAsMappings( - const std::string& asset_pattern, - const std::optional& subdir) const { - std::vector> mappings; - if (asset_pattern.empty()) { - return mappings; - } - TRACE_EVENT1("flutter", "AssetManager::GetAsMappings", "pattern", - asset_pattern.c_str()); - for (const auto& resolver : resolvers_) { - auto resolver_mappings = resolver->GetAsMappings(asset_pattern, subdir); - mappings.insert(mappings.end(), - std::make_move_iterator(resolver_mappings.begin()), - std::make_move_iterator(resolver_mappings.end())); - } - return mappings; -} - -// |AssetResolver| -bool AssetManager::IsValid() const { - return !resolvers_.empty(); -} - -// |AssetResolver| -bool AssetManager::IsValidAfterAssetManagerChange() const { - return false; -} - -// |AssetResolver| -AssetResolver::AssetResolverType AssetManager::GetType() const { - return AssetResolverType::kAssetManager; -} - -bool AssetManager::operator==(const AssetResolver& other) const { - const AssetManager* other_manager = other.as_asset_manager(); - if (!other_manager) { - return false; - } - if (resolvers_.size() != other_manager->resolvers_.size()) { - return false; - } - - for (size_t i = 0; i < resolvers_.size(); i++) { - if (*resolvers_[i] != *other_manager->resolvers_[i]) { - return false; - } - } - return true; -} - -} // namespace flutter diff --git a/assets/asset_manager.h b/assets/asset_manager.h deleted file mode 100644 index 7292484f00252..0000000000000 --- a/assets/asset_manager.h +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_ASSETS_ASSET_MANAGER_H_ -#define FLUTTER_ASSETS_ASSET_MANAGER_H_ - -#include -#include -#include - -#include -#include "flutter/assets/asset_resolver.h" -#include "flutter/fml/macros.h" -#include "flutter/fml/memory/ref_counted.h" - -namespace flutter { - -class AssetManager final : public AssetResolver { - public: - AssetManager(); - - ~AssetManager() override; - - //-------------------------------------------------------------------------- - /// @brief Adds an asset resolver to the front of the resolver queue. - /// Assets would be loaded from this resolver before any follwing - /// resolvers. - /// - /// @return Returns whether this resolver is valid and has been added to - /// the resolver queue. - bool PushFront(std::unique_ptr resolver); - - //-------------------------------------------------------------------------- - /// @brief Adds an asset resolver to the end of the resolver queue. - /// Assets would be loaded from this resolver after any previous - /// resolvers. - /// - /// @return Returns whether this resolver is valid and has been added to - /// the resolver queue. - bool PushBack(std::unique_ptr resolver); - - //-------------------------------------------------------------------------- - /// @brief Replaces an asset resolver of the specified `type` with - /// `updated_asset_resolver`. The matching AssetResolver is - /// removed and replaced with `updated_asset_resolvers`. - /// - /// AssetResolvers should be updated when the existing resolver - /// becomes obsolete and a newer one becomes available that - /// provides updated access to the same type of assets as the - /// existing one. This update process is meant to be performed - /// at runtime. - /// - /// If a null resolver is provided, nothing will be done. If no - /// matching resolver is found, the provided resolver will be - /// added to the end of the AssetManager resolvers queue. The - /// replacement only occurs with the first matching resolver. - /// Any additional matching resolvers are untouched. - /// - /// @param[in] updated_asset_resolver The asset resolver to replace the - /// resolver of matching type with. - /// - /// @param[in] type The type of AssetResolver to update. Only resolvers of - /// the specified type will be replaced by the updated - /// resolver. - /// - void UpdateResolverByType( - std::unique_ptr updated_asset_resolver, - AssetResolver::AssetResolverType type); - - std::deque> TakeResolvers(); - - // |AssetResolver| - bool IsValid() const override; - - // |AssetResolver| - bool IsValidAfterAssetManagerChange() const override; - - // |AssetResolver| - AssetResolver::AssetResolverType GetType() const override; - - // |AssetResolver| - std::unique_ptr GetAsMapping( - const std::string& asset_name) const override; - - // |AssetResolver| - std::vector> GetAsMappings( - const std::string& asset_pattern, - const std::optional& subdir) const override; - - // |AssetResolver| - bool operator==(const AssetResolver& other) const override; - - // |AssetResolver| - const AssetManager* as_asset_manager() const override { return this; } - - private: - std::deque> resolvers_; - - FML_DISALLOW_COPY_AND_ASSIGN(AssetManager); -}; - -} // namespace flutter - -#endif // FLUTTER_ASSETS_ASSET_MANAGER_H_ diff --git a/assets/asset_resolver.h b/assets/asset_resolver.h deleted file mode 100644 index f8ec95ece6797..0000000000000 --- a/assets/asset_resolver.h +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_ASSETS_ASSET_RESOLVER_H_ -#define FLUTTER_ASSETS_ASSET_RESOLVER_H_ - -#include -#include - -#include -#include "flutter/fml/macros.h" -#include "flutter/fml/mapping.h" - -namespace flutter { - -class AssetManager; -class APKAssetProvider; -class DirectoryAssetBundle; - -class AssetResolver { - public: - AssetResolver() = default; - - virtual ~AssetResolver() = default; - - //---------------------------------------------------------------------------- - /// @brief Identifies the type of AssetResolver an instance is. - /// - enum AssetResolverType { - kAssetManager, - kApkAssetProvider, - kDirectoryAssetBundle - }; - - virtual const AssetManager* as_asset_manager() const { return nullptr; } - virtual const APKAssetProvider* as_apk_asset_provider() const { - return nullptr; - } - virtual const DirectoryAssetBundle* as_directory_asset_bundle() const { - return nullptr; - } - - virtual bool IsValid() const = 0; - - //---------------------------------------------------------------------------- - /// @brief Certain asset resolvers are still valid after the asset - /// manager is replaced before a hot reload, or after a new run - /// configuration is created during a hot restart. By preserving - /// these resolvers and re-inserting them into the new resolver or - /// run configuration, the tooling can avoid needing to sync all - /// application assets through the Dart devFS upon connecting to - /// the VM Service. Besides improving the startup performance of - /// running a Flutter application, it also reduces the occurrence - /// of tool failures due to repeated network flakes caused by - /// damaged cables or hereto unknown bugs in the Dart HTTP server - /// implementation. - /// - /// @return Returns whether this resolver is valid after the asset manager - /// or run configuration is updated. - /// - virtual bool IsValidAfterAssetManagerChange() const = 0; - - //---------------------------------------------------------------------------- - /// @brief Gets the type of AssetResolver this is. Types are defined in - /// AssetResolverType. - /// - /// @return Returns the AssetResolverType that this resolver is. - /// - virtual AssetResolverType GetType() const = 0; - - [[nodiscard]] virtual std::unique_ptr GetAsMapping( - const std::string& asset_name) const = 0; - - //-------------------------------------------------------------------------- - /// @brief Same as GetAsMapping() but returns mappings for all files - /// who's name matches a given pattern. Returns empty vector - /// if no matching assets are found. - /// - /// @param[in] asset_pattern The pattern to match file names against. - /// - /// @param[in] subdir Optional subdirectory in which to search for files. - /// If supplied this function does a flat search within the - /// subdirectory instead of a recursive search through the entire - /// assets directory. - /// - /// @return Returns a vector of mappings of files which match the search - /// parameters. - /// - [[nodiscard]] virtual std::vector> - GetAsMappings(const std::string& asset_pattern, - const std::optional& subdir) const { - return {}; - }; - - virtual bool operator==(const AssetResolver& other) const = 0; - - bool operator!=(const AssetResolver& other) const { - return !operator==(other); - } - - private: - FML_DISALLOW_COPY_AND_ASSIGN(AssetResolver); -}; - -} // namespace flutter - -#endif // FLUTTER_ASSETS_ASSET_RESOLVER_H_ diff --git a/assets/directory_asset_bundle.cc b/assets/directory_asset_bundle.cc deleted file mode 100644 index 3401db12583a3..0000000000000 --- a/assets/directory_asset_bundle.cc +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/assets/directory_asset_bundle.h" - -#include -#include - -#include "flutter/fml/eintr_wrapper.h" -#include "flutter/fml/file.h" -#include "flutter/fml/mapping.h" -#include "flutter/fml/trace_event.h" - -namespace flutter { - -DirectoryAssetBundle::DirectoryAssetBundle( - fml::UniqueFD descriptor, - bool is_valid_after_asset_manager_change) - : descriptor_(std::move(descriptor)) { - if (!fml::IsDirectory(descriptor_)) { - return; - } - is_valid_after_asset_manager_change_ = is_valid_after_asset_manager_change; - is_valid_ = true; -} - -DirectoryAssetBundle::~DirectoryAssetBundle() = default; - -// |AssetResolver| -bool DirectoryAssetBundle::IsValid() const { - return is_valid_; -} - -// |AssetResolver| -bool DirectoryAssetBundle::IsValidAfterAssetManagerChange() const { - return is_valid_after_asset_manager_change_; -} - -// |AssetResolver| -AssetResolver::AssetResolverType DirectoryAssetBundle::GetType() const { - return AssetResolver::AssetResolverType::kDirectoryAssetBundle; -} - -// |AssetResolver| -std::unique_ptr DirectoryAssetBundle::GetAsMapping( - const std::string& asset_name) const { - if (!is_valid_) { - FML_DLOG(WARNING) << "Asset bundle was not valid."; - return nullptr; - } - - auto mapping = std::make_unique(fml::OpenFile( - descriptor_, asset_name.c_str(), false, fml::FilePermission::kRead)); - - if (!mapping->IsValid()) { - return nullptr; - } - - return mapping; -} - -std::vector> DirectoryAssetBundle::GetAsMappings( - const std::string& asset_pattern, - const std::optional& subdir) const { - std::vector> mappings; - if (!is_valid_) { - FML_DLOG(WARNING) << "Asset bundle was not valid."; - return mappings; - } - - std::regex asset_regex(asset_pattern); - fml::FileVisitor visitor = [&](const fml::UniqueFD& directory, - const std::string& filename) { - TRACE_EVENT0("flutter", "DirectoryAssetBundle::GetAsMappings FileVisitor"); - - if (std::regex_match(filename, asset_regex)) { - TRACE_EVENT0("flutter", "Matched File"); - - fml::UniqueFD fd = fml::OpenFile(directory, filename.c_str(), false, - fml::FilePermission::kRead); - - if (fml::IsDirectory(fd)) { - return true; - } - - auto mapping = std::make_unique(fd); - - if (mapping && mapping->IsValid()) { - mappings.push_back(std::move(mapping)); - } else { - FML_LOG(ERROR) << "Mapping " << filename << " failed"; - } - } - return true; - }; - if (!subdir) { - fml::VisitFilesRecursively(descriptor_, visitor); - } else { - fml::UniqueFD subdir_fd = - fml::OpenFileReadOnly(descriptor_, subdir.value().c_str()); - if (!fml::IsDirectory(subdir_fd)) { - FML_LOG(ERROR) << "Subdirectory path " << subdir.value() - << " is not a directory"; - return mappings; - } - fml::VisitFiles(subdir_fd, visitor); - } - - return mappings; -} - -bool DirectoryAssetBundle::operator==(const AssetResolver& other) const { - auto other_bundle = other.as_directory_asset_bundle(); - if (!other_bundle) { - return false; - } - return is_valid_after_asset_manager_change_ == - other_bundle->is_valid_after_asset_manager_change_ && - descriptor_.get() == other_bundle->descriptor_.get(); -} - -} // namespace flutter diff --git a/assets/directory_asset_bundle.h b/assets/directory_asset_bundle.h deleted file mode 100644 index c901c55557aed..0000000000000 --- a/assets/directory_asset_bundle.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_ASSETS_DIRECTORY_ASSET_BUNDLE_H_ -#define FLUTTER_ASSETS_DIRECTORY_ASSET_BUNDLE_H_ - -#include -#include "flutter/assets/asset_resolver.h" -#include "flutter/fml/macros.h" -#include "flutter/fml/memory/ref_counted.h" -#include "flutter/fml/unique_fd.h" - -namespace flutter { - -class DirectoryAssetBundle : public AssetResolver { - public: - DirectoryAssetBundle(fml::UniqueFD descriptor, - bool is_valid_after_asset_manager_change); - - ~DirectoryAssetBundle() override; - - private: - const fml::UniqueFD descriptor_; - bool is_valid_ = false; - bool is_valid_after_asset_manager_change_ = false; - - // |AssetResolver| - bool IsValid() const override; - - // |AssetResolver| - bool IsValidAfterAssetManagerChange() const override; - - // |AssetResolver| - AssetResolver::AssetResolverType GetType() const override; - - // |AssetResolver| - std::unique_ptr GetAsMapping( - const std::string& asset_name) const override; - - // |AssetResolver| - std::vector> GetAsMappings( - const std::string& asset_pattern, - const std::optional& subdir) const override; - - // |AssetResolver| - bool operator==(const AssetResolver& other) const override; - - // |AssetResolver| - const DirectoryAssetBundle* as_directory_asset_bundle() const override { - return this; - } - - FML_DISALLOW_COPY_AND_ASSIGN(DirectoryAssetBundle); -}; - -} // namespace flutter - -#endif // FLUTTER_ASSETS_DIRECTORY_ASSET_BUNDLE_H_ diff --git a/assets/native_assets.cc b/assets/native_assets.cc deleted file mode 100644 index afdf7ad86f549..0000000000000 --- a/assets/native_assets.cc +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "assets/native_assets.h" - -#include "flutter/fml/build_config.h" -#include "rapidjson/document.h" - -namespace flutter { - -#if defined(FML_ARCH_CPU_ARMEL) -#define kTargetArchitectureName "arm" -#elif defined(FML_ARCH_CPU_ARM64) -#define kTargetArchitectureName "arm64" -#elif defined(FML_ARCH_CPU_X86) -#define kTargetArchitectureName "ia32" -#elif defined(FML_ARCH_CPU_X86_64) -#define kTargetArchitectureName "x64" -#else -#error Target architecture detection failed. -#endif - -#if defined(FML_OS_ANDROID) -#define kTargetOperatingSystemName "android" -#elif defined(OS_FUCHSIA) -#define kTargetOperatingSystemName "fuchsia" -#elif defined(FML_OS_LINUX) -#define kTargetOperatingSystemName "linux" -#elif defined(FML_OS_IOS) || defined(FML_OS_IOS_SIMULATOR) -#define kTargetOperatingSystemName "ios" -#elif defined(FML_OS_MACOSX) -#define kTargetOperatingSystemName "macos" -#elif defined(FML_OS_WIN) -#define kTargetOperatingSystemName "windows" -#else -#error Target operating system detection failed. -#endif - -#define kTarget kTargetOperatingSystemName "_" kTargetArchitectureName - -void NativeAssetsManager::RegisterNativeAssets(const uint8_t* manifest, - size_t manifest_size) { - parsed_mapping_.clear(); - - rapidjson::Document document; - static_assert(sizeof(decltype(document)::Ch) == sizeof(uint8_t), ""); - document.Parse(reinterpret_cast(manifest), - manifest_size); - if (document.HasParseError()) { - FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed."; - return; - } - if (!document.IsObject()) { - FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed."; - return; - } - auto native_assets = document.FindMember("native-assets"); - if (native_assets == document.MemberEnd() || - !native_assets->value.IsObject()) { - FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed."; - return; - } - auto mapping = native_assets->value.FindMember(kTarget); - if (mapping == native_assets->value.MemberEnd() || - !mapping->value.IsObject()) { - FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed."; - return; - } - for (auto entry = mapping->value.MemberBegin(); - entry != mapping->value.MemberEnd(); entry++) { - std::vector parsed_path; - entry->name.GetString(); - auto& value = entry->value; - if (!value.IsArray()) { - FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed."; - continue; - } - for (const auto& element : value.GetArray()) { - if (!element.IsString()) { - FML_DLOG(WARNING) << "NativeAssetsManifest.json is malformed."; - continue; - } - parsed_path.push_back(element.GetString()); - } - parsed_mapping_[entry->name.GetString()] = std::move(parsed_path); - } -} - -void NativeAssetsManager::RegisterNativeAssets( - const std::shared_ptr& asset_manager) { - std::unique_ptr manifest_mapping = - asset_manager->GetAsMapping("NativeAssetsManifest.json"); - if (manifest_mapping == nullptr) { - FML_DLOG(WARNING) - << "Could not find NativeAssetsManifest.json in the asset store."; - return; - } - - RegisterNativeAssets(manifest_mapping->GetMapping(), - manifest_mapping->GetSize()); -} - -std::vector NativeAssetsManager::LookupNativeAsset( - std::string_view asset_id) { - // Cpp17 does not support unordered_map lookup with std::string_view on a - // std::string key. - std::string as_string = std::string(asset_id); - if (parsed_mapping_.find(as_string) == parsed_mapping_.end()) { - return std::vector(); - } - return parsed_mapping_[as_string]; -} - -std::string NativeAssetsManager::AvailableNativeAssets() { - if (parsed_mapping_.empty()) { - return std::string("No available native assets."); - } - - std::string result; - result.append("Available native assets: "); - bool first = true; - for (const auto& n : parsed_mapping_) { - if (first) { - first = false; - } else { - result.append(", "); - } - result.append(n.first); - } - - result.append("."); - return result; -} - -} // namespace flutter diff --git a/assets/native_assets.h b/assets/native_assets.h deleted file mode 100644 index 4e3524948496e..0000000000000 --- a/assets/native_assets.h +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_ASSETS_NATIVE_ASSETS_H_ -#define FLUTTER_ASSETS_NATIVE_ASSETS_H_ - -#include -#include - -#include "flutter/assets/asset_manager.h" - -namespace flutter { - -// Parses the `NativeAssetsManifest.json` and provides a way to look up assets -// and the available assets for the callbacks that are registered to the Dart VM -// via the dart_api.h. -// -// The engine eagerly populates a native assets manager on startup. This native -// assets manager is stored in the `IsolateGroupData` so it can be accessed on -// the native assets callbacks registered in `InitDartFFIForIsolateGroup`. -class NativeAssetsManager { - public: - NativeAssetsManager() = default; - ~NativeAssetsManager() = default; - - // Reads the `NativeAssetsManifest.json` bundled in the Flutter application. - void RegisterNativeAssets(const uint8_t* manifest, size_t manifest_size); - void RegisterNativeAssets(const std::shared_ptr& asset_manager); - - // Looks up the asset path for [asset_id]. - // - // The asset path consists of a type, and an optional path. For example: - // `["system", "libsqlite3.so"]`. - std::vector LookupNativeAsset(std::string_view asset_id); - - // Lists the available asset ids. - // - // Used when a user tries to look up an asset with an ID that does not exist - // to report the list of available asset ids. - std::string AvailableNativeAssets(); - - private: - std::unordered_map> parsed_mapping_; - - NativeAssetsManager(const NativeAssetsManager&) = delete; - NativeAssetsManager(NativeAssetsManager&&) = delete; - NativeAssetsManager& operator=(const NativeAssetsManager&) = delete; - NativeAssetsManager& operator=(NativeAssetsManager&&) = delete; -}; - -} // namespace flutter - -#endif // FLUTTER_ASSETS_NATIVE_ASSETS_H_ diff --git a/assets/native_assets_unittests.cc b/assets/native_assets_unittests.cc deleted file mode 100644 index 006f72437c0d0..0000000000000 --- a/assets/native_assets_unittests.cc +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/assets/native_assets.h" - -#include "gtest/gtest.h" - -namespace flutter { -namespace testing { - -// Manifest containing all hosts on which this test is run. -// In practise, a manifest will only contain a single OS. -// A manifest might contain multiple architectures if the OS supports -// multi-arch apps. -const char* kTestManifest = R"({ - "format-version": [ - 1, - 0, - 0 - ], - "native-assets": { - "linux_arm64": { - "package:my_package/my_package_bindings_generated.dart": [ - "absolute", - "libmy_package.so" - ] - }, - "linux_x64": { - "package:my_package/my_package_bindings_generated.dart": [ - "absolute", - "libmy_package.so" - ] - }, - "macos_arm64": { - "package:my_package/my_package_bindings_generated.dart": [ - "absolute", - "my_package.framework/my_package" - ] - }, - "macos_x64": { - "package:my_package/my_package_bindings_generated.dart": [ - "absolute", - "my_package.framework/my_package" - ] - }, - "windows_x64": { - "package:my_package/my_package_bindings_generated.dart": [ - "absolute", - "my_package.dll" - ] - } - } -})"; - -TEST(NativeAssetsManagerTest, NoAvailableAssets) { - NativeAssetsManager manager; - std::string available_assets = manager.AvailableNativeAssets(); - ASSERT_EQ(available_assets, "No available native assets."); -} - -TEST(NativeAssetsManagerTest, NativeAssetsManifestParsing) { - NativeAssetsManager manager; - manager.RegisterNativeAssets(reinterpret_cast(kTestManifest), - strlen(kTestManifest)); - - std::string available_assets = manager.AvailableNativeAssets(); - ASSERT_EQ(available_assets, - "Available native assets: " - "package:my_package/my_package_bindings_generated.dart."); - - std::vector existing_asset = manager.LookupNativeAsset( - "package:my_package/my_package_bindings_generated.dart"); - ASSERT_EQ(existing_asset.size(), 2u); - ASSERT_EQ(existing_asset[0], "absolute"); -#if defined(FML_OS_MACOSX) - ASSERT_EQ(existing_asset[1], "my_package.framework/my_package"); -#elif defined(FML_OS_LINUX) - ASSERT_EQ(existing_asset[1], "libmy_package.so"); -#elif defined(FML_OS_WIN) - ASSERT_EQ(existing_asset[1], "my_package.dll"); -#endif - - std::vector non_existing_asset = - manager.LookupNativeAsset("non_existing_asset"); - ASSERT_EQ(non_existing_asset.size(), 0u); -} - -} // namespace testing -} // namespace flutter