Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
asset_resolver.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_RESOLVER_H_
6#define FLUTTER_ASSETS_ASSET_RESOLVER_H_
7
8#include <string>
9#include <vector>
10
11#include <optional>
12#include "flutter/fml/macros.h"
13#include "flutter/fml/mapping.h"
14
15namespace flutter {
16
17class AssetManager;
18class APKAssetProvider;
19class DirectoryAssetBundle;
20
22 public:
23 AssetResolver() = default;
24
25 virtual ~AssetResolver() = default;
26
27 //----------------------------------------------------------------------------
28 /// @brief Identifies the type of AssetResolver an instance is.
29 ///
35
36 virtual const AssetManager* as_asset_manager() const { return nullptr; }
37 virtual const APKAssetProvider* as_apk_asset_provider() const {
38 return nullptr;
39 }
41 return nullptr;
42 }
43
44 virtual bool IsValid() const = 0;
45
46 //----------------------------------------------------------------------------
47 /// @brief Certain asset resolvers are still valid after the asset
48 /// manager is replaced before a hot reload, or after a new run
49 /// configuration is created during a hot restart. By preserving
50 /// these resolvers and re-inserting them into the new resolver or
51 /// run configuration, the tooling can avoid needing to sync all
52 /// application assets through the Dart devFS upon connecting to
53 /// the VM Service. Besides improving the startup performance of
54 /// running a Flutter application, it also reduces the occurrence
55 /// of tool failures due to repeated network flakes caused by
56 /// damaged cables or hereto unknown bugs in the Dart HTTP server
57 /// implementation.
58 ///
59 /// @return Returns whether this resolver is valid after the asset manager
60 /// or run configuration is updated.
61 ///
62 virtual bool IsValidAfterAssetManagerChange() const = 0;
63
64 //----------------------------------------------------------------------------
65 /// @brief Gets the type of AssetResolver this is. Types are defined in
66 /// AssetResolverType.
67 ///
68 /// @return Returns the AssetResolverType that this resolver is.
69 ///
70 virtual AssetResolverType GetType() const = 0;
71
72 [[nodiscard]] virtual std::unique_ptr<fml::Mapping> GetAsMapping(
73 const std::string& asset_name) const = 0;
74
75 //--------------------------------------------------------------------------
76 /// @brief Same as GetAsMapping() but returns mappings for all files
77 /// who's name matches a given pattern. Returns empty vector
78 /// if no matching assets are found.
79 ///
80 /// @param[in] asset_pattern The pattern to match file names against.
81 ///
82 /// @param[in] subdir Optional subdirectory in which to search for files.
83 /// If supplied this function does a flat search within the
84 /// subdirectory instead of a recursive search through the entire
85 /// assets directory.
86 ///
87 /// @return Returns a vector of mappings of files which match the search
88 /// parameters.
89 ///
90 [[nodiscard]] virtual std::vector<std::unique_ptr<fml::Mapping>>
91 GetAsMappings(const std::string& asset_pattern,
92 const std::optional<std::string>& subdir) const {
93 return {};
94 };
95
96 virtual bool operator==(const AssetResolver& other) const = 0;
97
98 bool operator!=(const AssetResolver& other) const {
99 return !operator==(other);
100 }
101
102 private:
104};
105
106} // namespace flutter
107
108#endif // FLUTTER_ASSETS_ASSET_RESOLVER_H_
virtual const AssetManager * as_asset_manager() const
virtual bool operator==(const AssetResolver &other) const =0
virtual AssetResolverType GetType() const =0
Gets the type of AssetResolver this is. Types are defined in AssetResolverType.
virtual std::unique_ptr< fml::Mapping > GetAsMapping(const std::string &asset_name) const =0
virtual bool IsValid() const =0
bool operator!=(const AssetResolver &other) const
AssetResolverType
Identifies the type of AssetResolver an instance is.
virtual bool IsValidAfterAssetManagerChange() const =0
Certain asset resolvers are still valid after the asset manager is replaced before a hot reload,...
virtual std::vector< std::unique_ptr< fml::Mapping > > GetAsMappings(const std::string &asset_pattern, const std::optional< std::string > &subdir) const
Same as GetAsMapping() but returns mappings for all files who's name matches a given pattern....
virtual const DirectoryAssetBundle * as_directory_asset_bundle() const
virtual const APKAssetProvider * as_apk_asset_provider() const
virtual ~AssetResolver()=default
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27