#include "content/browser/cache_storage/cache_storage_manager.h"
#include <stdint.h>
#include <map>
#include <numeric>
#include <optional>
#include <set>
#include <tuple>
#include <utility>
#include <vector>
#include "base/barrier_callback.h"
#include "base/containers/id_map.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/hash/sha1.h"
#include "base/memory/ptr_util.h"
#include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h"
#include "base/metrics/histogram_functions.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/sequence_checker.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/sequenced_task_runner.h"
#include "base/time/time.h"
#include "components/services/storage/public/cpp/buckets/bucket_locator.h"
#include "components/services/storage/public/cpp/constants.h"
#include "content/browser/cache_storage/cache_storage.h"
#include "content/browser/cache_storage/cache_storage.pb.h"
#include "content/browser/cache_storage/cache_storage_quota_client.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "storage/browser/quota/storage_directory_util.h"
#include "storage/common/database/database_identifier.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
#include "url/gurl.h"
#include "url/origin.h"
namespace content {
namespace {
bool DeleteDir(const base::FilePath& path) { … }
void DeleteBucketDidDeleteDir(
storage::mojom::QuotaClient::DeleteBucketDataCallback callback,
bool rv) { … }
void DidDeleteAllBuckets(
storage::mojom::QuotaClient::DeleteBucketDataCallback callback,
std::vector<blink::mojom::QuotaStatusCode> results) { … }
enum class IndexResult { … };
IndexResult ValidateIndex(proto::CacheStorageIndex index) { … }
void RecordIndexValidationResult(IndexResult value) { … }
base::FilePath ConstructOriginPath(const base::FilePath& profile_path,
const url::Origin& origin,
storage::mojom::CacheStorageOwner owner) { … }
void ValidateAndAddBucketFromPath(
const base::FilePath& index_file_directory_path,
storage::mojom::CacheStorageOwner owner,
const base::FilePath& profile_path,
std::vector<storage::BucketLocator>& buckets,
bool is_origin_path = false) { … }
void GetBucketsFromDiskOnTaskRunner(
scoped_refptr<base::SequencedTaskRunner> scheduler_task_runner,
std::vector<storage::BucketLocator> buckets,
base::FilePath profile_path,
storage::mojom::CacheStorageOwner owner,
base::OnceCallback<void(std::vector<storage::BucketLocator>)> callback) { … }
bool BucketMatchesOriginsForDeletion(
const storage::BucketLocator& bucket_locator,
const std::set<url::Origin>& origins) { … }
}
scoped_refptr<CacheStorageManager> CacheStorageManager::Create(
const base::FilePath& profile_path,
scoped_refptr<base::SequencedTaskRunner> cache_task_runner,
scoped_refptr<base::SequencedTaskRunner> scheduler_task_runner,
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy,
scoped_refptr<BlobStorageContextWrapper> blob_storage_context,
base::WeakPtr<CacheStorageDispatcherHost> cache_storage_dispatcher_host) { … }
scoped_refptr<CacheStorageManager> CacheStorageManager::CreateForTesting(
CacheStorageManager* old_manager) { … }
CacheStorageManager::~CacheStorageManager() { … }
#if DCHECK_IS_ON()
bool CacheStorageManager::CacheStoragePathIsUnique(const base::FilePath& path) { … }
#endif
bool CacheStorageManager::ConflictingInstanceExistsInMap(
storage::mojom::CacheStorageOwner owner,
const storage::BucketLocator& bucket_locator) { … }
CacheStorageHandle CacheStorageManager::OpenCacheStorage(
const storage::BucketLocator& bucket_locator,
storage::mojom::CacheStorageOwner owner) { … }
void CacheStorageManager::NotifyCacheListChanged(
const storage::BucketLocator& bucket_locator) { … }
void CacheStorageManager::NotifyCacheContentChanged(
const storage::BucketLocator& bucket_locator,
const std::string& name) { … }
void CacheStorageManager::CacheStorageUnreferenced(
CacheStorage* cache_storage,
const storage::BucketLocator& bucket_locator,
storage::mojom::CacheStorageOwner owner) { … }
void CacheStorageManager::GetBucketUsage(
const storage::BucketLocator& bucket_locator,
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::GetBucketUsageCallback callback) { … }
void CacheStorageManager::GetBucketUsageDidGetExists(
const storage::BucketLocator& bucket_locator,
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::GetBucketUsageCallback callback,
bool exists) { … }
void CacheStorageManager::GetStorageKeys(
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::GetStorageKeysForTypeCallback callback) { … }
void CacheStorageManager::DeleteOriginsDataGotAllBucketInfo(
const std::set<url::Origin>& origins,
storage::mojom::CacheStorageOwner owner,
base::OnceCallback<void(blink::mojom::QuotaStatusCode)> callback,
std::vector<storage::BucketLocator> buckets) { … }
void CacheStorageManager::DeleteOriginData(
const std::set<url::Origin>& origins,
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::DeleteBucketDataCallback callback) { … }
void CacheStorageManager::DeleteBucketData(
const storage::BucketLocator& bucket_locator,
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::DeleteBucketDataCallback callback) { … }
void CacheStorageManager::DeleteBucketDataDidGetExists(
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::DeleteBucketDataCallback callback,
storage::BucketLocator bucket_locator,
bool exists) { … }
void CacheStorageManager::AddObserver(
mojo::PendingRemote<storage::mojom::CacheStorageObserver> observer) { … }
void CacheStorageManager::DeleteBucketDidClose(
const storage::BucketLocator& bucket_locator,
storage::mojom::CacheStorageOwner owner,
storage::mojom::QuotaClient::DeleteBucketDataCallback callback,
std::unique_ptr<CacheStorage> cache_storage,
int64_t bucket_size) { … }
CacheStorageManager::CacheStorageManager(
const base::FilePath& profile_path,
scoped_refptr<base::SequencedTaskRunner> cache_task_runner,
scoped_refptr<base::SequencedTaskRunner> scheduler_task_runner,
scoped_refptr<storage::QuotaManagerProxy> quota_manager_proxy,
scoped_refptr<BlobStorageContextWrapper> blob_storage_context,
base::WeakPtr<CacheStorageDispatcherHost> cache_storage_dispatcher_host)
: … { … }
base::FilePath CacheStorageManager::ConstructBucketPath(
const base::FilePath& profile_path,
const storage::BucketLocator& bucket_locator,
storage::mojom::CacheStorageOwner owner) { … }
bool CacheStorageManager::IsValidQuotaStorageKey(
const blink::StorageKey& storage_key) { … }
void CacheStorageManager::OnMemoryPressure(
base::MemoryPressureListener::MemoryPressureLevel level) { … }
base::FilePath CacheStorageManager::ConstructFirstPartyDefaultRootPath(
const base::FilePath& profile_path) { … }
base::FilePath CacheStorageManager::ConstructThirdPartyAndNonDefaultRootPath(
const base::FilePath& profile_path) { … }
void CacheStorageManager::ListStorageKeysOnTaskRunner(
storage::mojom::QuotaClient::GetStorageKeysForTypeCallback callback,
std::vector<storage::BucketLocator> buckets) { … }
}