#ifdef UNSAFE_BUFFERS_BUILD
#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 {
const int kMaxMockCacheEntrySize = …;
int g_test_mode = …;
int GetTestModeForEntry(const std::string& key) { … }
}
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) { … }
void MockDiskEntry::IgnoreCallbacks(bool value) { … }
MockDiskEntry::~MockDiskEntry() = default;
void MockDiskEntry::CallbackLater(base::OnceClosure callback) { … }
void MockDiskEntry::CallbackLater(CompletionOnceCallback callback, int result) { … }
void MockDiskEntry::RunCallback(base::OnceClosure callback) { … }
void MockDiskEntry::StoreAndDeliverCallbacks(bool store,
MockDiskEntry* entry,
base::OnceClosure callback) { … }
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) { … }
int MockHttpCache::GetTestMode(int test_mode) { … }
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() { … }
}