Skip to content

Commit

Permalink
Made the persistent cache's directory a const pointer. (#9815)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaaclarke committed Jul 18, 2019
1 parent 8720043 commit 68ae872
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
19 changes: 15 additions & 4 deletions shell/common/persistent_cache.cc
Expand Up @@ -51,22 +51,33 @@ void PersistentCache::SetCacheDirectoryPath(std::string path) {
cache_base_path_ = path;
}

PersistentCache::PersistentCache(bool read_only) : is_read_only_(read_only) {
namespace {
std::shared_ptr<fml::UniqueFD> MakeCacheDirectory(
const std::string& global_cache_base_path,
bool read_only) {
fml::UniqueFD cache_base_dir;
if (cache_base_path_.length()) {
cache_base_dir = fml::OpenDirectory(cache_base_path_.c_str(), false,
if (global_cache_base_path.length()) {
cache_base_dir = fml::OpenDirectory(global_cache_base_path.c_str(), false,
fml::FilePermission::kRead);
} else {
cache_base_dir = fml::paths::GetCachesDirectory();
}

if (cache_base_dir.is_valid()) {
cache_directory_ = std::make_shared<fml::UniqueFD>(CreateDirectory(
return std::make_shared<fml::UniqueFD>(CreateDirectory(
cache_base_dir,
{"flutter_engine", GetFlutterEngineVersion(), "skia", GetSkiaVersion()},
read_only ? fml::FilePermission::kRead
: fml::FilePermission::kReadWrite));
} else {
return std::make_shared<fml::UniqueFD>();
}
}
} // namespace

PersistentCache::PersistentCache(bool read_only)
: is_read_only_(read_only),
cache_directory_(MakeCacheDirectory(cache_base_path_, read_only)) {
if (!IsValid()) {
FML_LOG(WARNING) << "Could not acquire the persistent cache directory. "
"Caching of GPU resources on disk is disabled.";
Expand Down
5 changes: 3 additions & 2 deletions shell/common/persistent_cache.h
Expand Up @@ -19,7 +19,8 @@ namespace flutter {

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

const bool is_read_only_;
std::shared_ptr<fml::UniqueFD> cache_directory_;
const std::shared_ptr<fml::UniqueFD> cache_directory_;
mutable std::mutex worker_task_runners_mutex_;
std::multiset<fml::RefPtr<fml::TaskRunner>> worker_task_runners_
FML_GUARDED_BY(worker_task_runners_mutex_);
Expand Down

0 comments on commit 68ae872

Please sign in to comment.