Flutter Engine
asset_manager.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/assets/asset_manager.h"
6 
7 #include "flutter/assets/directory_asset_bundle.h"
8 #include "flutter/fml/trace_event.h"
9 
10 namespace flutter {
11 
12 AssetManager::AssetManager() = default;
13 
14 AssetManager::~AssetManager() = default;
15 
16 void AssetManager::PushFront(std::unique_ptr<AssetResolver> resolver) {
17  if (resolver == nullptr || !resolver->IsValid()) {
18  return;
19  }
20 
21  resolvers_.push_front(std::move(resolver));
22 }
23 
24 void AssetManager::PushBack(std::unique_ptr<AssetResolver> resolver) {
25  if (resolver == nullptr || !resolver->IsValid()) {
26  return;
27  }
28 
29  resolvers_.push_back(std::move(resolver));
30 }
31 
32 std::deque<std::unique_ptr<AssetResolver>> AssetManager::TakeResolvers() {
33  return std::move(resolvers_);
34 }
35 
36 // |AssetResolver|
37 std::unique_ptr<fml::Mapping> AssetManager::GetAsMapping(
38  const std::string& asset_name) const {
39  if (asset_name.size() == 0) {
40  return nullptr;
41  }
42  TRACE_EVENT1("flutter", "AssetManager::GetAsMapping", "name",
43  asset_name.c_str());
44  for (const auto& resolver : resolvers_) {
45  auto mapping = resolver->GetAsMapping(asset_name);
46  if (mapping != nullptr) {
47  return mapping;
48  }
49  }
50  FML_DLOG(WARNING) << "Could not find asset: " << asset_name;
51  return nullptr;
52 }
53 
54 // |AssetResolver|
55 bool AssetManager::IsValid() const {
56  return resolvers_.size() > 0;
57 }
58 
59 // |AssetResolver|
61  return false;
62 }
63 
64 } // namespace flutter
void PushFront(std::unique_ptr< AssetResolver > resolver)
bool IsValid() const override
std::unique_ptr< fml::Mapping > GetAsMapping(const std::string &asset_name) const override
std::deque< std::unique_ptr< AssetResolver > > TakeResolvers()
bool IsValidAfterAssetManagerChange() const override
Certain asset resolvers are still valid after the asset manager is replaced before a hot reload...
~AssetManager() override
void PushBack(std::unique_ptr< AssetResolver > resolver)
#define TRACE_EVENT1(category_group, name, arg1_name, arg1_val)
Definition: trace_event.h:79
#define FML_DLOG(severity)
Definition: logging.h:85