| Index: net/http/mock_http_cache.cc
|
| diff --git a/net/http/mock_http_cache.cc b/net/http/mock_http_cache.cc
|
| index 514cc4208f82c79b3cafb876ef027716fd69b09f..bf81c4ee1eea6f6c14f5ff5544c7a31184b507cc 100644
|
| --- a/net/http/mock_http_cache.cc
|
| +++ b/net/http/mock_http_cache.cc
|
| @@ -74,7 +74,9 @@ MockDiskEntry::MockDiskEntry(const std::string& key)
|
| fail_sparse_requests_(false),
|
| busy_(false),
|
| delayed_(false),
|
| - cancel_(false) {
|
| + cancel_(false),
|
| + defer_op_(DEFER_NONE),
|
| + resume_return_code_(0) {
|
| test_mode_ = GetTestModeForEntry(key);
|
| }
|
|
|
| @@ -125,10 +127,25 @@ int MockDiskEntry::ReadData(int index,
|
| if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ)
|
| return num;
|
|
|
| + // Pause and resume.
|
| + if (defer_op_ == DEFER_READ) {
|
| + defer_op_ = DEFER_NONE;
|
| + resume_callback_ = callback;
|
| + resume_return_code_ = num;
|
| + return ERR_IO_PENDING;
|
| + }
|
| +
|
| CallbackLater(callback, num);
|
| return ERR_IO_PENDING;
|
| }
|
|
|
| +void MockDiskEntry::ResumeDiskEntryOperation() {
|
| + DCHECK(!resume_callback_.is_null());
|
| + CallbackLater(resume_callback_, resume_return_code_);
|
| + resume_callback_.Reset();
|
| + resume_return_code_ = 0;
|
| +}
|
| +
|
| int MockDiskEntry::WriteData(int index,
|
| int offset,
|
| IOBuffer* buf,
|
| @@ -376,7 +393,9 @@ MockDiskCache::MockDiskCache()
|
| fail_requests_(false),
|
| soft_failures_(false),
|
| double_create_check_(true),
|
| - fail_sparse_requests_(false) {}
|
| + fail_sparse_requests_(false),
|
| + defer_op_(MockDiskEntry::DEFER_NONE),
|
| + resume_return_code_(0) {}
|
|
|
| MockDiskCache::~MockDiskCache() {
|
| ReleaseAll();
|
| @@ -460,6 +479,14 @@ int MockDiskCache::CreateEntry(const std::string& key,
|
| if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
|
| return OK;
|
|
|
| + // Pause and resume.
|
| + if (defer_op_ == MockDiskEntry::DEFER_CREATE) {
|
| + defer_op_ = MockDiskEntry::DEFER_NONE;
|
| + resume_callback_ = callback;
|
| + resume_return_code_ = OK;
|
| + return ERR_IO_PENDING;
|
| + }
|
| +
|
| CallbackLater(callback, OK);
|
| return ERR_IO_PENDING;
|
| }
|
| @@ -526,9 +553,8 @@ size_t MockDiskCache::DumpMemoryStats(
|
| }
|
|
|
| void MockDiskCache::ReleaseAll() {
|
| - EntryMap::iterator it = entries_.begin();
|
| - for (; it != entries_.end(); ++it)
|
| - it->second->Release();
|
| + for (auto entry : entries_)
|
| + entry.second->Release();
|
| entries_.clear();
|
| }
|
|
|
| @@ -540,9 +566,25 @@ void MockDiskCache::CallbackLater(const CompletionCallback& callback,
|
|
|
| bool MockDiskCache::IsDiskEntryDoomed(const std::string& key) {
|
| auto it = entries_.find(key);
|
| + if (it != entries_.end())
|
| + return it->second->is_doomed();
|
| +
|
| + return false;
|
| +}
|
| +
|
| +void MockDiskCache::ResumeCacheOperation() {
|
| + DCHECK(!resume_callback_.is_null());
|
| + CallbackLater(resume_callback_, resume_return_code_);
|
| + resume_callback_.Reset();
|
| + resume_return_code_ = 0;
|
| +}
|
| +
|
| +scoped_refptr<MockDiskEntry> MockDiskCache::GetDiskEntryRef(
|
| + const std::string& key) {
|
| + auto it = entries_.find(key);
|
| if (it == entries_.end())
|
| - return false;
|
| - return it->second->is_doomed();
|
| + return nullptr;
|
| + return it->second;
|
| }
|
|
|
| //-----------------------------------------------------------------------------
|
|
|