chromium/content/browser/cache_storage/cache_storage.cc

// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/browser/cache_storage/cache_storage.h"

#include <stddef.h>

#include <memory>
#include <set>
#include <string>
#include <utility>
#include <vector>

#include "base/barrier_closure.h"
#include "base/containers/contains.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/hash/sha1.h"
#include "base/location.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/not_fatal_until.h"
#include "base/numerics/safe_conversions.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 "base/trace_event/trace_event.h"
#include "base/trace_event/traced_value.h"
#include "base/uuid.h"
#include "build/build_config.h"
#include "components/services/storage/public/cpp/buckets/bucket_locator.h"
#include "content/browser/cache_storage/cache_storage.pb.h"
#include "content/browser/cache_storage/cache_storage_cache.h"
#include "content/browser/cache_storage/cache_storage_cache_handle.h"
#include "content/browser/cache_storage/cache_storage_histogram_utils.h"
#include "content/browser/cache_storage/cache_storage_index.h"
#include "content/browser/cache_storage/cache_storage_manager.h"
#include "content/browser/cache_storage/cache_storage_quota_client.h"
#include "content/browser/cache_storage/cache_storage_scheduler.h"
#include "content/browser/cache_storage/cache_storage_trace_utils.h"
#include "content/common/background_fetch/background_fetch_types.h"
#include "crypto/symmetric_key.h"
#include "net/base/directory_lister.h"
#include "net/base/net_errors.h"
#include "storage/browser/blob/blob_storage_context.h"
#include "storage/browser/quota/quota_manager_proxy.h"
#include "third_party/blink/public/common/storage_key/storage_key.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h"

CacheStorageError;
StorageType;
SymmetricKey;

namespace content {

namespace {

std::string HexedHash(const std::string& value) {}

void SizeRetrievedFromAllCaches(std::unique_ptr<int64_t> accumulator,
                                CacheStorage::SizeCallback callback) {}

}  // namespace

const char CacheStorage::kIndexFileName[] =;

struct CacheStorage::CacheMatchResponse {};

// Handles the loading and clean up of CacheStorageCache objects.
class CacheStorage::CacheLoader {};

// Creates memory-only ServiceWorkerCaches. Because these caches have no
// persistent storage it is not safe to free them from memory if they might be
// used again. Therefore this class holds a reference to each cache until the
// cache is doomed.
class CacheStorage::MemoryLoader : public CacheStorage::CacheLoader {};

class CacheStorage::SimpleCacheLoader : public CacheStorage::CacheLoader {};

CacheStorage::CacheStorage(
    const base::FilePath& path,
    bool memory_only,
    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,
    CacheStorageManager* cache_storage_manager,
    const storage::BucketLocator& bucket_locator,
    storage::mojom::CacheStorageOwner owner)
    :{}

CacheStorage::~CacheStorage() {}

CacheStorageHandle CacheStorage::CreateHandle() {}

void CacheStorage::AddHandleRef() {}

void CacheStorage::DropHandleRef() {}

void CacheStorage::Init() {}

void CacheStorage::OpenCache(const std::string& cache_name,
                             int64_t trace_id,
                             CacheAndErrorCallback callback) {}

void CacheStorage::HasCache(const std::string& cache_name,
                            int64_t trace_id,
                            BoolAndErrorCallback callback) {}

void CacheStorage::DoomCache(const std::string& cache_name,
                             int64_t trace_id,
                             ErrorCallback callback) {}

void CacheStorage::EnumerateCaches(int64_t trace_id,
                                   EnumerateCachesCallback callback) {}

void CacheStorage::MatchCache(const std::string& cache_name,
                              blink::mojom::FetchAPIRequestPtr request,
                              blink::mojom::CacheQueryOptionsPtr match_options,
                              CacheStorageSchedulerPriority priority,
                              int64_t trace_id,
                              CacheStorageCache::ResponseCallback callback) {}

void CacheStorage::MatchAllCaches(
    blink::mojom::FetchAPIRequestPtr request,
    blink::mojom::CacheQueryOptionsPtr match_options,
    CacheStorageSchedulerPriority priority,
    int64_t trace_id,
    CacheStorageCache::ResponseCallback callback) {}

void CacheStorage::WriteToCache(const std::string& cache_name,
                                blink::mojom::FetchAPIRequestPtr request,
                                blink::mojom::FetchAPIResponsePtr response,
                                int64_t trace_id,
                                CacheStorage::ErrorCallback callback) {}

void CacheStorage::GetSizeThenCloseAllCaches(SizeCallback callback) {}

void CacheStorage::Size(CacheStorage::SizeCallback callback) {}

void CacheStorage::ResetManager() {}

void CacheStorage::NotifyCacheContentChanged(const std::string& cache_name) {}

void CacheStorage::ScheduleWriteIndex() {}

void CacheStorage::WriteIndex(base::OnceCallback<void(bool)> callback) {}

void CacheStorage::WriteIndexImpl(base::OnceCallback<void(bool)> callback) {}

bool CacheStorage::InitiateScheduledIndexWriteForTest(
    base::OnceCallback<void(bool)> callback) {}

void CacheStorage::CacheSizeUpdated(const CacheStorageCache* cache) {}

void CacheStorage::ReleaseUnreferencedCaches() {}

void CacheStorage::CacheUnreferenced(CacheStorageCache* cache) {}

CacheStorageSchedulerId CacheStorage::StartAsyncOperationForTesting() {}

void CacheStorage::CompleteAsyncOperationForTesting(
    CacheStorageSchedulerId id) {}

// Init is run lazily so that it is called on the proper MessageLoop.
void CacheStorage::LazyInit() {}

void CacheStorage::LazyInitImpl() {}

void CacheStorage::LazyInitDidLoadIndex(
    std::unique_ptr<CacheStorageIndex> index) {}

void CacheStorage::OpenCacheImpl(const std::string& cache_name,
                                 int64_t trace_id,
                                 CacheAndErrorCallback callback) {}

void CacheStorage::CreateCacheDidCreateCache(
    const std::string& cache_name,
    int64_t trace_id,
    CacheAndErrorCallback callback,
    std::unique_ptr<CacheStorageCache> cache,
    CacheStorageError status) {}

void CacheStorage::CreateCacheDidWriteIndex(
    CacheAndErrorCallback callback,
    CacheStorageCacheHandle cache_handle,
    int64_t trace_id,
    bool success) {}

void CacheStorage::HasCacheImpl(const std::string& cache_name,
                                int64_t trace_id,
                                BoolAndErrorCallback callback) {}

void CacheStorage::DoomCacheImpl(const std::string& cache_name,
                                 int64_t trace_id,
                                 ErrorCallback callback) {}

void CacheStorage::DeleteCacheDidWriteIndex(
    CacheStorageCacheHandle cache_handle,
    ErrorCallback callback,
    int64_t trace_id,
    bool success) {}

// Call this once the last handle to a doomed cache is gone. It's okay if this
// doesn't get to complete before shutdown, the cache will be removed from disk
// on next startup in that case.
void CacheStorage::DeleteCacheFinalize(CacheStorageCache* doomed_cache) {}

void CacheStorage::DeleteCacheDidGetSize(CacheStorageCache* doomed_cache,
                                         int64_t cache_size) {}

void CacheStorage::EnumerateCachesImpl(int64_t trace_id,
                                       EnumerateCachesCallback callback) {}

void CacheStorage::MatchCacheImpl(
    const std::string& cache_name,
    blink::mojom::FetchAPIRequestPtr request,
    blink::mojom::CacheQueryOptionsPtr match_options,
    CacheStorageSchedulerPriority priority,
    int64_t trace_id,
    CacheStorageCache::ResponseCallback callback) {}

void CacheStorage::MatchCacheDidMatch(
    CacheStorageCacheHandle cache_handle,
    int64_t trace_id,
    CacheStorageCache::ResponseCallback callback,
    CacheStorageError error,
    blink::mojom::FetchAPIResponsePtr response) {}

void CacheStorage::MatchAllCachesImpl(
    blink::mojom::FetchAPIRequestPtr request,
    blink::mojom::CacheQueryOptionsPtr match_options,
    CacheStorageSchedulerPriority priority,
    int64_t trace_id,
    CacheStorageCache::ResponseCallback callback) {}

void CacheStorage::MatchAllCachesDidMatch(
    CacheStorageCacheHandle cache_handle,
    CacheMatchResponse* out_match_response,
    const base::RepeatingClosure& barrier_closure,
    int64_t trace_id,
    CacheStorageError error,
    blink::mojom::FetchAPIResponsePtr response) {}

void CacheStorage::MatchAllCachesDidMatchAll(
    std::unique_ptr<std::vector<CacheMatchResponse>> match_responses,
    int64_t trace_id,
    CacheStorageCache::ResponseCallback callback) {}

void CacheStorage::WriteToCacheImpl(const std::string& cache_name,
                                    blink::mojom::FetchAPIRequestPtr request,
                                    blink::mojom::FetchAPIResponsePtr response,
                                    int64_t trace_id,
                                    CacheStorage::ErrorCallback callback) {}

CacheStorageCacheHandle CacheStorage::GetLoadedCache(
    const std::string& cache_name) {}

void CacheStorage::SizeRetrievedFromCache(CacheStorageCacheHandle cache_handle,
                                          base::OnceClosure closure,
                                          int64_t* accumulator,
                                          int64_t size) {}

void CacheStorage::GetSizeThenCloseAllCachesImpl(SizeCallback callback) {}

void CacheStorage::SizeImpl(SizeCallback callback) {}

void CacheStorage::FlushIndexIfDirty() {}

#if BUILDFLAG(IS_ANDROID)
void CacheStorage::OnApplicationStateChange(
    base::android::ApplicationState state) {
  DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
  if (state == base::android::APPLICATION_STATE_HAS_RUNNING_ACTIVITIES) {
    app_on_background_ = false;
  } else if (state == base::android::APPLICATION_STATE_HAS_STOPPED_ACTIVITIES) {
    app_on_background_ = true;
    FlushIndexIfDirty();
  }
}
#endif

}  // namespace content