#include "components/image_fetcher/core/cache/image_metadata_store_leveldb.h"
#include <algorithm>
#include <utility>
#include "base/functional/bind.h"
#include "base/system/sys_info.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/clock.h"
#include "base/time/time.h"
#include "components/image_fetcher/core/cache/proto/cached_image_metadata.pb.h"
#include "components/image_fetcher/core/image_fetcher_metrics_reporter.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
CachedImageMetadataProto;
namespace image_fetcher {
namespace {
leveldb::ReadOptions CreateReadOptions() { … }
int64_t ToDatabaseTime(base::Time time) { … }
CacheOption ToCacheOption(CacheStrategy cache_strategy) { … }
const char kImageDatabaseFolder[] = …;
const size_t kDatabaseWriteBufferSizeBytes = …;
bool KeyMatcherFilter(std::string key, const std::string& other_key) { … }
bool SortByLastUsedTime(const CachedImageMetadataProto* a,
const CachedImageMetadataProto* b) { … }
}
MetadataKeyEntryVector;
ImageMetadataStoreLevelDB::ImageMetadataStoreLevelDB(
leveldb_proto::ProtoDatabaseProvider* proto_database_provider,
const base::FilePath& database_dir,
scoped_refptr<base::SequencedTaskRunner> task_runner,
base::Clock* clock)
: … { … }
ImageMetadataStoreLevelDB::ImageMetadataStoreLevelDB(
std::unique_ptr<leveldb_proto::ProtoDatabase<CachedImageMetadataProto>>
database,
base::Clock* clock)
: … { … }
ImageMetadataStoreLevelDB::~ImageMetadataStoreLevelDB() = default;
void ImageMetadataStoreLevelDB::Initialize(base::OnceClosure callback) { … }
bool ImageMetadataStoreLevelDB::IsInitialized() { … }
void ImageMetadataStoreLevelDB::LoadImageMetadata(
const std::string& key,
ImageMetadataCallback callback) { … }
void ImageMetadataStoreLevelDB::SaveImageMetadata(
const std::string& key,
const size_t data_size,
bool needs_transcoding,
ExpirationInterval expiration_interval) { … }
void ImageMetadataStoreLevelDB::DeleteImageMetadata(const std::string& key) { … }
void ImageMetadataStoreLevelDB::UpdateImageMetadata(const std::string& key) { … }
void ImageMetadataStoreLevelDB::GetAllKeys(KeysCallback callback) { … }
int64_t ImageMetadataStoreLevelDB::GetEstimatedSize(CacheOption cache_option) { … }
void ImageMetadataStoreLevelDB::EvictImageMetadata(base::Time expiration_time,
const size_t bytes_left,
KeysCallback callback) { … }
void ImageMetadataStoreLevelDB::OnDatabaseInitialized(
base::OnceClosure callback,
leveldb_proto::Enums::InitStatus status) { … }
void ImageMetadataStoreLevelDB::LoadImageMetadataImpl(
ImageMetadataCallback callback,
bool success,
std::unique_ptr<std::vector<CachedImageMetadataProto>> entries) { … }
void ImageMetadataStoreLevelDB::OnImageUpdated(bool success) { … }
void ImageMetadataStoreLevelDB::UpdateImageMetadataImpl(
bool success,
std::unique_ptr<std::vector<CachedImageMetadataProto>> entries) { … }
void ImageMetadataStoreLevelDB::GetAllKeysImpl(
KeysCallback callback,
bool success,
std::unique_ptr<std::vector<std::string>> keys) { … }
void ImageMetadataStoreLevelDB::EvictImageMetadataImpl(
base::Time expiration_time,
const size_t bytes_left,
KeysCallback callback,
bool success,
std::unique_ptr<std::vector<CachedImageMetadataProto>> entries) { … }
void ImageMetadataStoreLevelDB::GetMetadataToRemove(
CacheOption cache_option,
std::vector<const CachedImageMetadataProto*> entries,
base::Time expiration_time,
const size_t bytes_left,
std::vector<std::string>* keys_to_remove) { … }
void ImageMetadataStoreLevelDB::OnEvictImageMetadataDone(
KeysCallback callback,
std::vector<std::string> deleted_keys,
bool success) { … }
}