#include <utility>
#include "base/barrier_closure.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/field_trial.h"
#include "base/task/bind_post_task.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "build/build_config.h"
#include "net/base/cache_type.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/backend_cleanup_tracker.h"
#include "net/disk_cache/blockfile/backend_impl.h"
#include "net/disk_cache/cache_util.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/memory/mem_backend_impl.h"
#include "net/disk_cache/simple/simple_backend_impl.h"
#include "net/disk_cache/simple/simple_file_enumerator.h"
#include "net/disk_cache/simple/simple_util.h"
namespace {
FileEnumerator;
ApplicationStatusListenerGetter;
class CacheCreator { … };
CacheCreator::CacheCreator(
const base::FilePath& path,
disk_cache::ResetHandling reset_handling,
int64_t max_bytes,
net::CacheType type,
net::BackendType backend_type,
scoped_refptr<disk_cache::BackendFileOperationsFactory> file_operations,
#if BUILDFLAG(IS_ANDROID)
ApplicationStatusListenerGetter app_status_listener_getter,
#endif
net::NetLog* net_log,
base::OnceClosure post_cleanup_callback,
disk_cache::BackendResultCallback callback)
: … { … }
CacheCreator::~CacheCreator() = default;
net::Error CacheCreator::Run() { … }
net::Error CacheCreator::TryCreateCleanupTrackerAndRun() { … }
void CacheCreator::DoCallback(int net_error) { … }
void CacheCreator::OnIOComplete(int result) { … }
void CacheCreator::OnCacheCleanupComplete(int original_result,
bool cleanup_result) { … }
class TrivialFileEnumerator final : public FileEnumerator { … };
class UnboundTrivialFileOperations
: public disk_cache::UnboundBackendFileOperations { … };
}
namespace disk_cache {
BackendResult::BackendResult() = default;
BackendResult::~BackendResult() = default;
BackendResult::BackendResult(BackendResult&&) = default;
BackendResult& BackendResult::operator=(BackendResult&&) = default;
BackendResult BackendResult::MakeError(net::Error error_in) { … }
BackendResult BackendResult::Make(std::unique_ptr<Backend> backend_in) { … }
BackendResult CreateCacheBackendImpl(
net::CacheType type,
net::BackendType backend_type,
scoped_refptr<BackendFileOperationsFactory> file_operations,
const base::FilePath& path,
int64_t max_bytes,
ResetHandling reset_handling,
#if BUILDFLAG(IS_ANDROID)
ApplicationStatusListenerGetter app_status_listener_getter,
#endif
net::NetLog* net_log,
base::OnceClosure post_cleanup_callback,
BackendResultCallback callback) { … }
BackendResult CreateCacheBackend(
net::CacheType type,
net::BackendType backend_type,
scoped_refptr<BackendFileOperationsFactory> file_operations,
const base::FilePath& path,
int64_t max_bytes,
ResetHandling reset_handling,
net::NetLog* net_log,
BackendResultCallback callback) { … }
#if BUILDFLAG(IS_ANDROID)
NET_EXPORT BackendResult
CreateCacheBackend(net::CacheType type,
net::BackendType backend_type,
scoped_refptr<BackendFileOperationsFactory> file_operations,
const base::FilePath& path,
int64_t max_bytes,
ResetHandling reset_handling,
net::NetLog* net_log,
BackendResultCallback callback,
ApplicationStatusListenerGetter app_status_listener_getter) {
return CreateCacheBackendImpl(type, backend_type, std::move(file_operations),
path, max_bytes, reset_handling,
std::move(app_status_listener_getter), net_log,
base::OnceClosure(), std::move(callback));
}
#endif
BackendResult CreateCacheBackend(
net::CacheType type,
net::BackendType backend_type,
scoped_refptr<BackendFileOperationsFactory> file_operations,
const base::FilePath& path,
int64_t max_bytes,
ResetHandling reset_handling,
net::NetLog* net_log,
base::OnceClosure post_cleanup_callback,
BackendResultCallback callback) { … }
void FlushCacheThreadForTesting() { … }
void FlushCacheThreadAsynchronouslyForTesting(base::OnceClosure callback) { … }
int64_t Backend::CalculateSizeOfEntriesBetween(
base::Time initial_time,
base::Time end_time,
Int64CompletionOnceCallback callback) { … }
uint8_t Backend::GetEntryInMemoryData(const std::string& key) { … }
void Backend::SetEntryInMemoryData(const std::string& key, uint8_t data) { … }
EntryResult::EntryResult() = default;
EntryResult::~EntryResult() = default;
EntryResult::EntryResult(EntryResult&& other) { … }
EntryResult& EntryResult::operator=(EntryResult&& other) { … }
EntryResult EntryResult::MakeOpened(Entry* new_entry) { … }
EntryResult EntryResult::MakeCreated(Entry* new_entry) { … }
EntryResult EntryResult::MakeError(net::Error status) { … }
Entry* EntryResult::ReleaseEntry() { … }
TrivialFileOperations::TrivialFileOperations() { … }
TrivialFileOperations::~TrivialFileOperations() { … }
bool TrivialFileOperations::CreateDirectory(const base::FilePath& path) { … }
bool TrivialFileOperations::PathExists(const base::FilePath& path) { … }
bool TrivialFileOperations::DirectoryExists(const base::FilePath& path) { … }
base::File TrivialFileOperations::OpenFile(const base::FilePath& path,
uint32_t flags) { … }
bool TrivialFileOperations::DeleteFile(const base::FilePath& path,
DeleteFileMode mode) { … }
bool TrivialFileOperations::ReplaceFile(const base::FilePath& from_path,
const base::FilePath& to_path,
base::File::Error* error) { … }
std::optional<base::File::Info> TrivialFileOperations::GetFileInfo(
const base::FilePath& path) { … }
std::unique_ptr<FileEnumerator> TrivialFileOperations::EnumerateFiles(
const base::FilePath& path) { … }
void TrivialFileOperations::CleanupDirectory(
const base::FilePath& path,
base::OnceCallback<void(bool)> callback) { … }
std::unique_ptr<UnboundBackendFileOperations> TrivialFileOperations::Unbind() { … }
TrivialFileOperationsFactory::TrivialFileOperationsFactory() = default;
TrivialFileOperationsFactory::~TrivialFileOperationsFactory() = default;
std::unique_ptr<BackendFileOperations> TrivialFileOperationsFactory::Create(
scoped_refptr<base::SequencedTaskRunner> task_runner) { … }
std::unique_ptr<UnboundBackendFileOperations>
TrivialFileOperationsFactory::CreateUnbound() { … }
}