Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Unified Diff: net/http/mock_http_cache.cc

Issue 2970133002: DoomPartialEntry should not attempt to doom an already doomed entry. (Closed)
Patch Set: Feedback addressed Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/mock_http_cache.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
}
//-----------------------------------------------------------------------------
« no previous file with comments | « net/http/mock_http_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698