Skip to content

Commit 68ae872

Browse files
authored
Made the persistent cache's directory a const pointer. (#9815)
1 parent 8720043 commit 68ae872

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

shell/common/persistent_cache.cc

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,33 @@ void PersistentCache::SetCacheDirectoryPath(std::string path) {
5151
cache_base_path_ = path;
5252
}
5353

54-
PersistentCache::PersistentCache(bool read_only) : is_read_only_(read_only) {
54+
namespace {
55+
std::shared_ptr<fml::UniqueFD> MakeCacheDirectory(
56+
const std::string& global_cache_base_path,
57+
bool read_only) {
5558
fml::UniqueFD cache_base_dir;
56-
if (cache_base_path_.length()) {
57-
cache_base_dir = fml::OpenDirectory(cache_base_path_.c_str(), false,
59+
if (global_cache_base_path.length()) {
60+
cache_base_dir = fml::OpenDirectory(global_cache_base_path.c_str(), false,
5861
fml::FilePermission::kRead);
5962
} else {
6063
cache_base_dir = fml::paths::GetCachesDirectory();
6164
}
6265

6366
if (cache_base_dir.is_valid()) {
64-
cache_directory_ = std::make_shared<fml::UniqueFD>(CreateDirectory(
67+
return std::make_shared<fml::UniqueFD>(CreateDirectory(
6568
cache_base_dir,
6669
{"flutter_engine", GetFlutterEngineVersion(), "skia", GetSkiaVersion()},
6770
read_only ? fml::FilePermission::kRead
6871
: fml::FilePermission::kReadWrite));
72+
} else {
73+
return std::make_shared<fml::UniqueFD>();
6974
}
75+
}
76+
} // namespace
77+
78+
PersistentCache::PersistentCache(bool read_only)
79+
: is_read_only_(read_only),
80+
cache_directory_(MakeCacheDirectory(cache_base_path_, read_only)) {
7081
if (!IsValid()) {
7182
FML_LOG(WARNING) << "Could not acquire the persistent cache directory. "
7283
"Caching of GPU resources on disk is disabled.";

shell/common/persistent_cache.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ namespace flutter {
1919

2020
/// A cache of SkData that gets stored to disk.
2121
///
22-
/// This is mainly used for Shaders but is also written to by Dart.
22+
/// This is mainly used for Shaders but is also written to by Dart. It is
23+
/// thread-safe for reading and writing from multiple threads.
2324
class PersistentCache : public GrContextOptions::PersistentCache {
2425
public:
2526
// Mutable static switch that can be set before GetCacheForProcess. If true,
@@ -52,7 +53,7 @@ class PersistentCache : public GrContextOptions::PersistentCache {
5253
static std::string cache_base_path_;
5354

5455
const bool is_read_only_;
55-
std::shared_ptr<fml::UniqueFD> cache_directory_;
56+
const std::shared_ptr<fml::UniqueFD> cache_directory_;
5657
mutable std::mutex worker_task_runners_mutex_;
5758
std::multiset<fml::RefPtr<fml::TaskRunner>> worker_task_runners_
5859
FML_GUARDED_BY(worker_task_runners_mutex_);

0 commit comments

Comments
 (0)