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

Unified Diff: net/http/mock_http_cache.cc

Issue 2922973003: RFC: use some in-memory state in SimpleCache to quickly cache-miss some CantConditionalize cases
Patch Set: - Implement support for oracle bytes in MockHttpCache, so the code actually gets exercised in tests… Created 3 years, 6 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/disk_cache/simple/simple_index.cc ('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 47125a30cc53f4bdf2969ae35e1c5b607c2706c4..1800fbdaa69e18bcfaa7403f0602d8d1fded904c 100644
--- a/net/http/mock_http_cache.cc
+++ b/net/http/mock_http_cache.cc
@@ -68,6 +68,7 @@ struct MockDiskEntry::CallbackInfo {
MockDiskEntry::MockDiskEntry(const std::string& key)
: key_(key),
+ oracle_byte_(0),
doomed_(false),
sparse_(false),
fail_requests_(false),
@@ -98,6 +99,10 @@ base::Time MockDiskEntry::GetLastModified() const {
return base::Time::Now();
}
+void MockDiskEntry::SetOracleByte(uint8_t val) {
+ oracle_byte_ = val;
+}
+
int32_t MockDiskEntry::GetDataSize(int index) const {
DCHECK(index >= 0 && index < kNumCacheEntryDataIndices);
return static_cast<int32_t>(data_[index].size());
@@ -390,6 +395,13 @@ int32_t MockDiskCache::GetEntryCount() const {
int MockDiskCache::OpenEntry(const std::string& key,
disk_cache::Entry** entry,
const CompletionCallback& callback) {
+ return OpenEntryWithOracleByte(key, entry, OracleCallback(), callback);
+}
+
+int MockDiskCache::OpenEntryWithOracleByte(const std::string& key,
+ disk_cache::Entry** entry,
+ const OracleCallback& oracle,
+ const CompletionCallback& callback) {
DCHECK(!callback.is_null());
if (fail_requests_)
return ERR_CACHE_OPEN_FAILURE;
@@ -398,6 +410,12 @@ int MockDiskCache::OpenEntry(const std::string& key,
if (it == entries_.end())
return ERR_CACHE_OPEN_FAILURE;
+ if (!oracle.is_null() && oracle.Run(it->second->GetOracleByte()) ==
+ Backend::OracleJudgement::MISS_AND_DOOM) {
+ it->second->Doom();
+ // Will be handled immediately below.
+ }
+
if (it->second->is_doomed()) {
it->second->Release();
entries_.erase(it);
« net/disk_cache/simple/simple_index.cc ('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