#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "net/disk_cache/simple/simple_index_file.h"
#include <utility>
#include <vector>
#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/numerics/safe_conversions.h"
#include "base/pickle.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/thread_pool.h"
#include "base/threading/thread_restrictions.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "net/disk_cache/simple/simple_backend_impl.h"
#include "net/disk_cache/simple/simple_entry_format.h"
#include "net/disk_cache/simple/simple_file_enumerator.h"
#include "net/disk_cache/simple/simple_histogram_macros.h"
#include "net/disk_cache/simple/simple_index.h"
#include "net/disk_cache/simple/simple_synchronous_entry.h"
#include "net/disk_cache/simple/simple_util.h"
namespace disk_cache {
namespace {
const int kEntryFilesHashLength = …;
const int kEntryFilesSuffixLength = …;
const int kMaxEntriesInIndex = …;
const int64_t kMaxIndexFileSizeBytes = …;
uint32_t CalculatePickleCRC(const base::Pickle& pickle) { … }
enum IndexFileState { … };
enum StaleIndexQuality { … };
void UmaRecordIndexFileState(IndexFileState state, net::CacheType cache_type) { … }
void UmaRecordIndexInitMethod(SimpleIndex::IndexInitMethod method,
net::CacheType cache_type) { … }
void UmaRecordStaleIndexQuality(int missed_entry_count,
int extra_entry_count,
net::CacheType cache_type) { … }
struct PickleHeader : public base::Pickle::Header { … };
class SimpleIndexPickle : public base::Pickle { … };
bool WritePickleFile(BackendFileOperations* file_operations,
base::Pickle* pickle,
const base::FilePath& file_name) { … }
void ProcessEntryFile(BackendFileOperations* file_operations,
net::CacheType cache_type,
SimpleIndex::EntrySet* entries,
const base::FilePath& file_path,
base::Time last_accessed,
base::Time last_modified,
int64_t size) { … }
}
SimpleIndexLoadResult::SimpleIndexLoadResult() = default;
SimpleIndexLoadResult::~SimpleIndexLoadResult() = default;
void SimpleIndexLoadResult::Reset() { … }
const char SimpleIndexFile::kIndexFileName[] = …;
const char SimpleIndexFile::kIndexDirectory[] = …;
const char SimpleIndexFile::kTempIndexFileName[] = …;
SimpleIndexFile::IndexMetadata::IndexMetadata()
: … { … }
SimpleIndexFile::IndexMetadata::IndexMetadata(
SimpleIndex::IndexWriteToDiskReason reason,
uint64_t entry_count,
uint64_t cache_size)
: … { … }
void SimpleIndexFile::IndexMetadata::Serialize(base::Pickle* pickle) const { … }
void SimpleIndexFile::SerializeFinalData(base::Time cache_modified,
base::Pickle* pickle) { … }
bool SimpleIndexFile::IndexMetadata::Deserialize(base::PickleIterator* it) { … }
void SimpleIndexFile::SyncWriteToDisk(
std::unique_ptr<BackendFileOperations> file_operations,
net::CacheType cache_type,
const base::FilePath& cache_directory,
const base::FilePath& index_filename,
const base::FilePath& temp_index_filename,
std::unique_ptr<base::Pickle> pickle) { … }
bool SimpleIndexFile::IndexMetadata::CheckIndexMetadata() { … }
SimpleIndexFile::SimpleIndexFile(
scoped_refptr<base::SequencedTaskRunner> cache_runner,
scoped_refptr<BackendFileOperationsFactory> file_operations_factory,
net::CacheType cache_type,
const base::FilePath& cache_directory)
: … { … }
SimpleIndexFile::~SimpleIndexFile() = default;
void SimpleIndexFile::LoadIndexEntries(base::Time cache_last_modified,
base::OnceClosure callback,
SimpleIndexLoadResult* out_result) { … }
void SimpleIndexFile::WriteToDisk(net::CacheType cache_type,
SimpleIndex::IndexWriteToDiskReason reason,
const SimpleIndex::EntrySet& entry_set,
uint64_t cache_size,
base::OnceClosure callback) { … }
void SimpleIndexFile::SyncLoadIndexEntries(
std::unique_ptr<BackendFileOperations> file_operations,
net::CacheType cache_type,
base::Time cache_last_modified,
const base::FilePath& cache_directory,
const base::FilePath& index_file_path,
SimpleIndexLoadResult* out_result) { … }
void SimpleIndexFile::SyncLoadFromDisk(BackendFileOperations* file_operations,
net::CacheType cache_type,
const base::FilePath& index_filename,
base::Time* out_last_cache_seen_by_index,
SimpleIndexLoadResult* out_result) { … }
std::unique_ptr<base::Pickle> SimpleIndexFile::Serialize(
net::CacheType cache_type,
const SimpleIndexFile::IndexMetadata& index_metadata,
const SimpleIndex::EntrySet& entries) { … }
void SimpleIndexFile::Deserialize(net::CacheType cache_type,
const char* data,
int data_len,
base::Time* out_cache_last_modified,
SimpleIndexLoadResult* out_result) { … }
void SimpleIndexFile::SyncRestoreFromDisk(
BackendFileOperations* file_operations,
net::CacheType cache_type,
const base::FilePath& cache_directory,
const base::FilePath& index_file_path,
SimpleIndexLoadResult* out_result) { … }
bool SimpleIndexFile::LegacyIsIndexFileStale(
BackendFileOperations* file_operations,
base::Time cache_last_modified,
const base::FilePath& index_file_path) { … }
}