#ifndef FLUTTER_SHELL_COMMON_PERSISTENT_CACHE_H_
#define FLUTTER_SHELL_COMMON_PERSISTENT_CACHE_H_
#include <memory>
#include <mutex>
#include <set>
#include "flutter/fml/macros.h"
#include "flutter/fml/synchronization/thread_annotations.h"
#include "flutter/fml/task_runner.h"
#include "flutter/fml/unique_fd.h"
#include "include/gpu/GrContextOptions.h"
namespace flutter {
class PersistentCache : public GrContextOptions::PersistentCache {
public:
static bool gIsReadOnly;
static PersistentCache* GetCacheForProcess();
static void SetCacheDirectoryPath(std::string path);
~PersistentCache() override;
void AddWorkerTaskRunner(fml::RefPtr<fml::TaskRunner> task_runner);
void RemoveWorkerTaskRunner(fml::RefPtr<fml::TaskRunner> task_runner);
bool StoredNewShaders() const { return stored_new_shaders_; }
void ResetStoredNewShaders() { stored_new_shaders_ = false; }
void DumpSkp(const SkData& data);
bool IsDumpingSkp() const { return is_dumping_skp_; }
void SetIsDumpingSkp(bool value) { is_dumping_skp_ = value; }
private:
static std::string cache_base_path_;
const bool is_read_only_;
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_);
bool stored_new_shaders_ = false;
bool is_dumping_skp_ = false;
bool IsValid() const;
PersistentCache(bool read_only = false);
sk_sp<SkData> load(const SkData& key) override;
void store(const SkData& key, const SkData& data) override;
fml::RefPtr<fml::TaskRunner> GetWorkerTaskRunner() const;
FML_DISALLOW_COPY_AND_ASSIGN(PersistentCache);
};
}
#endif