forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
asset_resolver.h
90 lines (75 loc) · 3.35 KB
/
asset_resolver.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 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 <string>
#include <vector>
#include <optional>
#include "flutter/fml/macros.h"
#include "flutter/fml/mapping.h"
namespace flutter {
class AssetResolver {
public:
AssetResolver() = default;
virtual ~AssetResolver() = default;
//----------------------------------------------------------------------------
/// @brief Identifies the type of AssetResolver an instance is.
///
enum AssetResolverType {
kAssetManager,
kApkAssetProvider,
kDirectoryAssetBundle
};
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<fml::Mapping> 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<std::unique_ptr<fml::Mapping>>
GetAsMappings(const std::string& asset_pattern,
const std::optional<std::string>& subdir) const {
return {};
};
private:
FML_DISALLOW_COPY_AND_ASSIGN(AssetResolver);
};
} // namespace flutter
#endif // FLUTTER_ASSETS_ASSET_RESOLVER_H_