chromium/net/http/mock_http_cache.cc

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

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

#include "net/http/mock_http_cache.h"

#include <algorithm>
#include <limits>
#include <memory>
#include <utility>

#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/task/single_thread_task_runner.h"
#include "net/base/features.h"
#include "net/base/net_errors.h"
#include "net/disk_cache/disk_cache_test_util.h"
#include "net/http/http_cache_writers.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace net {

namespace {

// During testing, we are going to limit the size of a cache entry to this many
// bytes using DCHECKs in order to prevent a test from causing unbounded memory
// growth. In practice cache entry shouldn't come anywhere near this limit for
// tests that use the mock cache. If they do, that's likely a problem with the
// test. If a test requires using massive cache entries, they should use a real
// cache backend instead.
const int kMaxMockCacheEntrySize =;

// We can override the test mode for a given operation by setting this global
// variable.
int g_test_mode =;

int GetTestModeForEntry(const std::string& key) {}

}  // namespace

//-----------------------------------------------------------------------------

struct MockDiskEntry::CallbackInfo {};

MockDiskEntry::MockDiskEntry(const std::string& key)
    :{}

void MockDiskEntry::Doom() {}

void MockDiskEntry::Close() {}

std::string MockDiskEntry::GetKey() const {}

base::Time MockDiskEntry::GetLastUsed() const {}

base::Time MockDiskEntry::GetLastModified() const {}

int32_t MockDiskEntry::GetDataSize(int index) const {}

int MockDiskEntry::ReadData(int index,
                            int offset,
                            IOBuffer* buf,
                            int buf_len,
                            CompletionOnceCallback callback) {}

void MockDiskEntry::ResumeDiskEntryOperation() {}

int MockDiskEntry::WriteData(int index,
                             int offset,
                             IOBuffer* buf,
                             int buf_len,
                             CompletionOnceCallback callback,
                             bool truncate) {}

int MockDiskEntry::ReadSparseData(int64_t offset,
                                  IOBuffer* buf,
                                  int buf_len,
                                  CompletionOnceCallback callback) {}

int MockDiskEntry::WriteSparseData(int64_t offset,
                                   IOBuffer* buf,
                                   int buf_len,
                                   CompletionOnceCallback callback) {}

disk_cache::RangeResult MockDiskEntry::GetAvailableRange(
    int64_t offset,
    int len,
    RangeResultCallback callback) {}

bool MockDiskEntry::CouldBeSparse() const {}

void MockDiskEntry::CancelSparseIO() {}

Error MockDiskEntry::ReadyForSparseIO(CompletionOnceCallback callback) {}

void MockDiskEntry::SetLastUsedTimeForTest(base::Time time) {}

// If |value| is true, don't deliver any completion callbacks until called
// again with |value| set to false.  Caution: remember to enable callbacks
// again or all subsequent tests will fail.
// Static.
void MockDiskEntry::IgnoreCallbacks(bool value) {}

MockDiskEntry::~MockDiskEntry() = default;

// Unlike the callbacks for MockHttpTransaction, we want this one to run even
// if the consumer called Close on the MockDiskEntry.  We achieve that by
// leveraging the fact that this class is reference counted.
void MockDiskEntry::CallbackLater(base::OnceClosure callback) {}

void MockDiskEntry::CallbackLater(CompletionOnceCallback callback, int result) {}

void MockDiskEntry::RunCallback(base::OnceClosure callback) {}

// When |store| is true, stores the callback to be delivered later; otherwise
// delivers any callback previously stored.
// Static.
void MockDiskEntry::StoreAndDeliverCallbacks(bool store,
                                             MockDiskEntry* entry,
                                             base::OnceClosure callback) {}

// Statics.
bool MockDiskEntry::ignore_callbacks_ =;

//-----------------------------------------------------------------------------

MockDiskCache::MockDiskCache()
    :{}

MockDiskCache::~MockDiskCache() {}

int32_t MockDiskCache::GetEntryCount() const {}

disk_cache::EntryResult MockDiskCache::OpenOrCreateEntry(
    const std::string& key,
    RequestPriority request_priority,
    EntryResultCallback callback) {}

disk_cache::EntryResult MockDiskCache::OpenEntry(
    const std::string& key,
    RequestPriority request_priority,
    EntryResultCallback callback) {}

disk_cache::EntryResult MockDiskCache::CreateEntry(
    const std::string& key,
    RequestPriority request_priority,
    EntryResultCallback callback) {}

Error MockDiskCache::DoomEntry(const std::string& key,
                               RequestPriority request_priority,
                               CompletionOnceCallback callback) {}

Error MockDiskCache::DoomAllEntries(CompletionOnceCallback callback) {}

Error MockDiskCache::DoomEntriesBetween(const base::Time initial_time,
                                        const base::Time end_time,
                                        CompletionOnceCallback callback) {}

Error MockDiskCache::DoomEntriesSince(const base::Time initial_time,
                                      CompletionOnceCallback callback) {}

int64_t MockDiskCache::CalculateSizeOfAllEntries(
    Int64CompletionOnceCallback callback) {}

class MockDiskCache::NotImplementedIterator : public Iterator {};

std::unique_ptr<disk_cache::Backend::Iterator> MockDiskCache::CreateIterator() {}

void MockDiskCache::GetStats(base::StringPairs* stats) {}

void MockDiskCache::OnExternalCacheHit(const std::string& key) {}

uint8_t MockDiskCache::GetEntryInMemoryData(const std::string& key) {}

void MockDiskCache::SetEntryInMemoryData(const std::string& key, uint8_t data) {}

int64_t MockDiskCache::MaxFileSize() const {}

void MockDiskCache::ReleaseAll() {}

void MockDiskCache::CallbackLater(base::OnceClosure callback) {}

bool MockDiskCache::IsDiskEntryDoomed(const std::string& key) {}

void MockDiskCache::ResumeCacheOperation() {}

scoped_refptr<MockDiskEntry> MockDiskCache::GetDiskEntryRef(
    const std::string& key) {}

const std::vector<std::string>& MockDiskCache::GetExternalCacheHits() const {}

//-----------------------------------------------------------------------------

disk_cache::BackendResult MockBackendFactory::CreateBackend(
    NetLog* net_log,
    disk_cache::BackendResultCallback callback) {}

//-----------------------------------------------------------------------------

MockHttpCache::MockHttpCache()
    :{}

MockHttpCache::MockHttpCache(
    std::unique_ptr<HttpCache::BackendFactory> disk_cache_factory)
    :{}

disk_cache::Backend* MockHttpCache::backend() {}

MockDiskCache* MockHttpCache::disk_cache() {}

int MockHttpCache::CreateTransaction(std::unique_ptr<HttpTransaction>* trans) {}

void MockHttpCache::SimulateCacheLockTimeout() {}

void MockHttpCache::SimulateCacheLockTimeoutAfterHeaders() {}

void MockHttpCache::FailConditionalizations() {}

bool MockHttpCache::ReadResponseInfo(disk_cache::Entry* disk_entry,
                                     HttpResponseInfo* response_info,
                                     bool* response_truncated) {}

bool MockHttpCache::WriteResponseInfo(disk_cache::Entry* disk_entry,
                                      const HttpResponseInfo* response_info,
                                      bool skip_transient_headers,
                                      bool response_truncated) {}

bool MockHttpCache::OpenBackendEntry(const std::string& key,
                                     disk_cache::Entry** entry) {}

bool MockHttpCache::CreateBackendEntry(const std::string& key,
                                       disk_cache::Entry** entry,
                                       NetLog* net_log) {}

// Static.
int MockHttpCache::GetTestMode(int test_mode) {}

// Static.
void MockHttpCache::SetTestMode(int test_mode) {}

bool MockHttpCache::IsWriterPresent(const std::string& key) {}

bool MockHttpCache::IsHeadersTransactionPresent(const std::string& key) {}

int MockHttpCache::GetCountReaders(const std::string& key) {}

int MockHttpCache::GetCountAddToEntryQueue(const std::string& key) {}

int MockHttpCache::GetCountDoneHeadersQueue(const std::string& key) {}

int MockHttpCache::GetCountWriterTransactions(const std::string& key) {}

base::WeakPtr<HttpCache> MockHttpCache::GetWeakPtr() {}

//-----------------------------------------------------------------------------

disk_cache::EntryResult MockDiskCacheNoCB::CreateEntry(
    const std::string& key,
    RequestPriority request_priority,
    EntryResultCallback callback) {}

//-----------------------------------------------------------------------------

disk_cache::BackendResult MockBackendNoCbFactory::CreateBackend(
    NetLog* net_log,
    disk_cache::BackendResultCallback callback) {}

//-----------------------------------------------------------------------------

MockBlockingBackendFactory::MockBlockingBackendFactory() = default;
MockBlockingBackendFactory::~MockBlockingBackendFactory() = default;

disk_cache::BackendResult MockBlockingBackendFactory::CreateBackend(
    NetLog* net_log,
    disk_cache::BackendResultCallback callback) {}

void MockBlockingBackendFactory::FinishCreation() {}

disk_cache::BackendResult MockBlockingBackendFactory::MakeResult() {}

}  // namespace net