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..e8309a0a0a9041320c60451b248d12284020ca43 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,26 @@ 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; |
} |
+int MockDiskEntry::ResumeCacheOperation() { |
+ DCHECK(!resume_callback_.is_null()); |
+ CallbackLater(resume_callback_, resume_return_code_); |
+ resume_callback_.Reset(); |
+ resume_return_code_ = 0; |
+ return ERR_IO_PENDING; |
+} |
+ |
int MockDiskEntry::WriteData(int index, |
int offset, |
IOBuffer* buf, |
@@ -376,7 +394,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 +480,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 +554,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(); |
} |
@@ -539,10 +566,27 @@ 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; |
+} |
+ |
+int MockDiskCache::ResumeCacheOperation() { |
+ DCHECK(!resume_callback_.is_null()); |
+ CallbackLater(resume_callback_, resume_return_code_); |
+ resume_callback_.Reset(); |
+ resume_return_code_ = 0; |
+ return ERR_IO_PENDING; |
+} |
+ |
+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; |
+ it->second->AddRef(); |
+ return it->second; |
} |
//----------------------------------------------------------------------------- |