5#include "flutter/assets/asset_manager.h"
7#include "flutter/assets/directory_asset_bundle.h"
8#include "flutter/fml/trace_event.h"
17 if (resolver ==
nullptr || !resolver->IsValid()) {
21 resolvers_.push_front(std::move(resolver));
26 if (resolver ==
nullptr || !resolver->IsValid()) {
30 resolvers_.push_back(std::move(resolver));
35 std::unique_ptr<AssetResolver> updated_asset_resolver,
37 if (updated_asset_resolver ==
nullptr) {
41 std::deque<std::unique_ptr<AssetResolver>> new_resolvers;
42 for (
auto& old_resolver : resolvers_) {
43 if (!updated && old_resolver->GetType() ==
type) {
45 new_resolvers.push_back(std::move(updated_asset_resolver));
48 new_resolvers.push_back(std::move(old_resolver));
53 new_resolvers.push_back(std::move(updated_asset_resolver));
55 resolvers_.swap(new_resolvers);
59 return std::move(resolvers_);
64 const std::string& asset_name)
const {
65 if (asset_name.empty()) {
68 TRACE_EVENT1(
"flutter",
"AssetManager::GetAsMapping",
"name",
70 for (
const auto& resolver : resolvers_) {
71 auto mapping = resolver->GetAsMapping(asset_name);
72 if (mapping !=
nullptr) {
76 FML_DLOG(WARNING) <<
"Could not find asset: " << asset_name;
82 const std::string& asset_pattern,
83 const std::optional<std::string>& subdir)
const {
84 std::vector<std::unique_ptr<fml::Mapping>> mappings;
85 if (asset_pattern.empty()) {
88 TRACE_EVENT1(
"flutter",
"AssetManager::GetAsMappings",
"pattern",
89 asset_pattern.c_str());
90 for (
const auto& resolver : resolvers_) {
91 auto resolver_mappings = resolver->GetAsMappings(asset_pattern, subdir);
92 mappings.insert(mappings.end(),
93 std::make_move_iterator(resolver_mappings.begin()),
94 std::make_move_iterator(resolver_mappings.end()));
101 return !resolvers_.empty();
111 return AssetResolverType::kAssetManager;
116 if (!other_manager) {
119 if (resolvers_.size() != other_manager->resolvers_.size()) {
123 for (
size_t i = 0;
i < resolvers_.size();
i++) {
124 if (*resolvers_[
i] != *other_manager->resolvers_[
i]) {
void UpdateResolverByType(std::unique_ptr< AssetResolver > updated_asset_resolver, AssetResolver::AssetResolverType type)
Replaces an asset resolver of the specified type with updated_asset_resolver. The matching AssetResol...
std::vector< std::unique_ptr< fml::Mapping > > GetAsMappings(const std::string &asset_pattern, const std::optional< std::string > &subdir) const override
Same as GetAsMapping() but returns mappings for all files who's name matches a given pattern....
std::unique_ptr< fml::Mapping > GetAsMapping(const std::string &asset_name) const override
std::deque< std::unique_ptr< AssetResolver > > TakeResolvers()
bool IsValid() const override
bool operator==(const AssetResolver &other) const override
bool PushBack(std::unique_ptr< AssetResolver > resolver)
Adds an asset resolver to the end of the resolver queue. Assets would be loaded from this resolver af...
bool PushFront(std::unique_ptr< AssetResolver > resolver)
Adds an asset resolver to the front of the resolver queue. Assets would be loaded from this resolver ...
AssetResolver::AssetResolverType GetType() const override
Gets the type of AssetResolver this is. Types are defined in AssetResolverType.
bool IsValidAfterAssetManagerChange() const override
Certain asset resolvers are still valid after the asset manager is replaced before a hot reload,...
virtual const AssetManager * as_asset_manager() const
AssetResolverType
Identifies the type of AssetResolver an instance is.
#define FML_DLOG(severity)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)