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

Unified Diff: net/http/mock_http_cache.h

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/http_cache_unittest.cc ('k') | net/http/mock_http_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/mock_http_cache.h
diff --git a/net/http/mock_http_cache.h b/net/http/mock_http_cache.h
index d568c64db9a5d206a04973c2b82d37d289f97f30..bc7847b7bfff8b541ada5049b7a6c2453141b661 100644
--- a/net/http/mock_http_cache.h
+++ b/net/http/mock_http_cache.h
@@ -27,6 +27,12 @@ namespace net {
class MockDiskEntry : public disk_cache::Entry,
public base::RefCounted<MockDiskEntry> {
public:
+ enum DeferOp {
+ DEFER_NONE,
+ DEFER_CREATE,
+ DEFER_READ,
+ };
+
explicit MockDiskEntry(const std::string& key);
bool is_doomed() const { return doomed_; }
@@ -74,6 +80,14 @@ class MockDiskEntry : public disk_cache::Entry,
// again or all subsequent tests will fail.
static void IgnoreCallbacks(bool value);
+ // Defers invoking the callback for the given operation. Calling code should
+ // invoke ResumeDiskEntryOperation to resume.
+ void SetDefer(DeferOp defer_op) { defer_op_ = defer_op; }
+
+ // Resumes deferred cache operation by posting |resume_callback_| with
+ // |resume_return_code_|.
+ void ResumeDiskEntryOperation();
+
private:
friend class base::RefCounted<MockDiskEntry>;
struct CallbackInfo;
@@ -106,6 +120,12 @@ class MockDiskEntry : public disk_cache::Entry,
bool busy_;
bool delayed_;
bool cancel_;
+
+ // Used for pause and restart.
+ DeferOp defer_op_;
+ CompletionCallback resume_callback_;
+ int resume_return_code_;
+
static bool ignore_callbacks_;
};
@@ -161,8 +181,20 @@ class MockDiskCache : public disk_cache::Backend {
void ReleaseAll();
+ // Returns true if a doomed entry exists with this key.
bool IsDiskEntryDoomed(const std::string& key);
+ // Defers invoking the callback for the given operation. Calling code should
+ // invoke ResumeCacheOperation to resume.
+ void SetDefer(MockDiskEntry::DeferOp defer_op) { defer_op_ = defer_op; }
+
+ // Resume deferred cache operation by posting |resume_callback_| with
+ // |resume_return_code_|.
+ void ResumeCacheOperation();
+
+ // Returns a reference to the disk entry with the given |key|.
+ scoped_refptr<MockDiskEntry> GetDiskEntryRef(const std::string& key);
+
private:
using EntryMap = std::unordered_map<std::string, MockDiskEntry*>;
class NotImplementedIterator;
@@ -177,6 +209,11 @@ class MockDiskCache : public disk_cache::Backend {
bool soft_failures_;
bool double_create_check_;
bool fail_sparse_requests_;
+
+ // Used for pause and restart.
+ MockDiskEntry::DeferOp defer_op_;
+ CompletionCallback resume_callback_;
+ int resume_return_code_;
};
class MockBackendFactory : public HttpCache::BackendFactory {
@@ -244,7 +281,6 @@ class MockHttpCache {
static void SetTestMode(int test_mode);
// Functions to test the state of ActiveEntry.
-
bool IsWriterPresent(const std::string& key);
bool IsHeadersTransactionPresent(const std::string& key);
int GetCountReaders(const std::string& key);
« no previous file with comments | « net/http/http_cache_unittest.cc ('k') | net/http/mock_http_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698