Flutter Engine
The Flutter Engine
asset_manager.h
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#ifndef FLUTTER_ASSETS_ASSET_MANAGER_H_
6#define FLUTTER_ASSETS_ASSET_MANAGER_H_
7
8#include <deque>
9#include <memory>
10#include <string>
11
12#include <optional>
13#include "flutter/assets/asset_resolver.h"
14#include "flutter/fml/macros.h"
15#include "flutter/fml/memory/ref_counted.h"
16
17namespace flutter {
18
19class AssetManager final : public AssetResolver {
20 public:
22
23 ~AssetManager() override;
24
25 //--------------------------------------------------------------------------
26 /// @brief Adds an asset resolver to the front of the resolver queue.
27 /// Assets would be loaded from this resolver before any follwing
28 /// resolvers.
29 ///
30 /// @return Returns whether this resolver is valid and has been added to
31 /// the resolver queue.
32 bool PushFront(std::unique_ptr<AssetResolver> resolver);
33
34 //--------------------------------------------------------------------------
35 /// @brief Adds an asset resolver to the end of the resolver queue.
36 /// Assets would be loaded from this resolver after any previous
37 /// resolvers.
38 ///
39 /// @return Returns whether this resolver is valid and has been added to
40 /// the resolver queue.
41 bool PushBack(std::unique_ptr<AssetResolver> resolver);
42
43 //--------------------------------------------------------------------------
44 /// @brief Replaces an asset resolver of the specified `type` with
45 /// `updated_asset_resolver`. The matching AssetResolver is
46 /// removed and replaced with `updated_asset_resolvers`.
47 ///
48 /// AssetResolvers should be updated when the existing resolver
49 /// becomes obsolete and a newer one becomes available that
50 /// provides updated access to the same type of assets as the
51 /// existing one. This update process is meant to be performed
52 /// at runtime.
53 ///
54 /// If a null resolver is provided, nothing will be done. If no
55 /// matching resolver is found, the provided resolver will be
56 /// added to the end of the AssetManager resolvers queue. The
57 /// replacement only occurs with the first matching resolver.
58 /// Any additional matching resolvers are untouched.
59 ///
60 /// @param[in] updated_asset_resolver The asset resolver to replace the
61 /// resolver of matching type with.
62 ///
63 /// @param[in] type The type of AssetResolver to update. Only resolvers of
64 /// the specified type will be replaced by the updated
65 /// resolver.
66 ///
68 std::unique_ptr<AssetResolver> updated_asset_resolver,
70
71 std::deque<std::unique_ptr<AssetResolver>> TakeResolvers();
72
73 // |AssetResolver|
74 bool IsValid() const override;
75
76 // |AssetResolver|
77 bool IsValidAfterAssetManagerChange() const override;
78
79 // |AssetResolver|
81
82 // |AssetResolver|
83 std::unique_ptr<fml::Mapping> GetAsMapping(
84 const std::string& asset_name) const override;
85
86 // |AssetResolver|
87 std::vector<std::unique_ptr<fml::Mapping>> GetAsMappings(
88 const std::string& asset_pattern,
89 const std::optional<std::string>& subdir) const override;
90
91 // |AssetResolver|
92 bool operator==(const AssetResolver& other) const override;
93
94 // |AssetResolver|
95 const AssetManager* as_asset_manager() const override { return this; }
96
97 private:
98 std::deque<std::unique_ptr<AssetResolver>> resolvers_;
99
100 FML_DISALLOW_COPY_AND_ASSIGN(AssetManager);
101};
102
103} // namespace flutter
104
105#endif // FLUTTER_ASSETS_ASSET_MANAGER_H_
GLenum type
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
const AssetManager * as_asset_manager() const override
Definition: asset_manager.h:95
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 ...
~AssetManager() override
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,...
AssetResolverType
Identifies the type of AssetResolver an instance is.