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

Unified Diff: net/http/mock_http_cache.cc

Issue 2970133002: DoomPartialEntry should not attempt to doom an already doomed entry. (Closed)
Patch Set: Test and test framework changes added. 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
« net/http/mock_http_cache.h ('K') | « 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 5363d3af29dd0067ce58b9cd9489b40f2b545b16..eea29d0a4d866223d752131221f543fb207e9747 100644
--- a/net/http/mock_http_cache.cc
+++ b/net/http/mock_http_cache.cc
@@ -74,7 +74,8 @@ MockDiskEntry::MockDiskEntry(const std::string& key)
fail_sparse_requests_(false),
busy_(false),
delayed_(false),
- cancel_(false) {
+ cancel_(false),
+ resume_return_code_(0) {
test_mode_ = GetTestModeForEntry(key);
}
@@ -125,10 +126,32 @@ int MockDiskEntry::ReadData(int index,
if (MockHttpCache::GetTestMode(test_mode_) & TEST_MODE_SYNC_CACHE_READ)
return num;
+ // Pause and resume.
+ if (!before_cache_callback_.is_null()) {
+ bool defer = false;
+ before_cache_callback_.Run(&defer);
+ if (defer) {
+ resume_callback_ = callback;
+ resume_return_code_ = num;
+ return ERR_IO_PENDING;
+ }
+ }
jkarlin 2017/07/07 19:12:39 This seems overly complex for our use case. Why no
jkarlin 2017/07/07 19:14:12 Note that this comment came before I added the sug
shivanisha 2017/07/10 18:51:27 Simplified by using an enum DeferOp.
+
CallbackLater(callback, num);
return ERR_IO_PENDING;
}
+int MockDiskEntry::ResumeCacheOperation() {
+ DCHECK(!resume_callback_.is_null());
+ CallbackLater(resume_callback_, resume_return_code_);
+ return ERR_IO_PENDING;
+}
+
+void MockDiskEntry::SetBeforeCacheOperationCallback(
+ const BeforeCacheOperationCallback& callback) {
+ before_cache_callback_ = callback;
+}
+
int MockDiskEntry::WriteData(int index,
int offset,
IOBuffer* buf,
@@ -399,7 +422,7 @@ int MockDiskCache::OpenEntry(const std::string& key,
return ERR_CACHE_OPEN_FAILURE;
if (it->second->is_doomed()) {
- it->second->Release();
+ doomed_entries_[key] = it->second;
entries_.erase(it);
return ERR_CACHE_OPEN_FAILURE;
}
@@ -434,7 +457,7 @@ int MockDiskCache::CreateEntry(const std::string& key,
else
return ERR_CACHE_CREATE_FAILURE;
}
- it->second->Release();
+ doomed_entries_[key] = it->second;
entries_.erase(it);
}
@@ -466,7 +489,7 @@ int MockDiskCache::DoomEntry(const std::string& key,
DCHECK(!callback.is_null());
EntryMap::iterator it = entries_.find(key);
if (it != entries_.end()) {
- it->second->Release();
+ doomed_entries_[key] = it->second;
entries_.erase(it);
}
@@ -522,10 +545,13 @@ 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();
+
+ for (auto doomed : doomed_entries_)
+ doomed.second->Release();
+ doomed_entries_.clear();
}
void MockDiskCache::CallbackLater(const CompletionCallback& callback,
@@ -535,10 +561,46 @@ void MockDiskCache::CallbackLater(const CompletionCallback& callback,
}
bool MockDiskCache::IsDiskEntryDoomed(const std::string& key) {
+ auto doomed_it = doomed_entries_.find(key);
+ if (doomed_it != doomed_entries_.end())
+ return true;
+
+ auto it = entries_.find(key);
+ if (it != entries_.end())
+ return it->second->is_doomed();
+
+ return false;
+}
+
+void MockDiskCache::SetBeforeCacheOperationCallback(
+ const std::string& key,
+ const MockDiskEntry::BeforeCacheOperationCallback& callback) {
auto it = entries_.find(key);
if (it == entries_.end())
- return false;
- return it->second->is_doomed();
+ return;
+ it->second->SetBeforeCacheOperationCallback(callback);
+}
+
+int MockDiskCache::ResumeCacheOperation(const std::string& key) {
+ auto it = entries_.find(key);
+ if (it != entries_.end())
+ return it->second->ResumeCacheOperation();
+
+ return ERR_UNEXPECTED;
+}
+
+int MockDiskCache::ResumeDoomedEntryCacheOperation(const std::string& key) {
+ auto doomed_it = doomed_entries_.find(key);
+ if (doomed_it != doomed_entries_.end())
+ return doomed_it->second->ResumeCacheOperation();
+
+ auto it = entries_.find(key);
+ if (it != entries_.end()) {
+ DCHECK(it->second->is_doomed());
+ return it->second->ResumeCacheOperation();
+ }
+
+ return ERR_UNEXPECTED;
}
//-----------------------------------------------------------------------------
« net/http/mock_http_cache.h ('K') | « net/http/mock_http_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698