Chromium Code Reviews| 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..759b13cfe746c2a41f8b6b6a631da5e809b5be6e 100644 |
| --- a/net/http/mock_http_cache.h |
| +++ b/net/http/mock_http_cache.h |
| @@ -21,6 +21,12 @@ |
| namespace net { |
| +enum DeferOp { |
|
jkarlin
2017/07/12 16:15:55
I don't think we want this enum in the net:: names
shivanisha
2017/07/13 14:47:26
Moved it to MockDiskEntry
|
| + DEFER_NONE, |
| + DEFER_CREATE, |
| + DEFER_READ, |
| +}; |
| + |
| //----------------------------------------------------------------------------- |
| // Mock disk cache (a very basic memory cache implementation). |
| @@ -74,6 +80,12 @@ class MockDiskEntry : public disk_cache::Entry, |
| // again or all subsequent tests will fail. |
| static void IgnoreCallbacks(bool value); |
| + void SetDefer(DeferOp defer_op) { defer_op_ = defer_op; } |
| + |
| + // Resumes deferred cache operation by posting |resume_callback_| with |
| + // |resume_return_code_|. Returns ERR_IO_PENDING. |
| + int ResumeCacheOperation(); |
| + |
| private: |
| friend class base::RefCounted<MockDiskEntry>; |
| struct CallbackInfo; |
| @@ -106,6 +118,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 +179,25 @@ class MockDiskCache : public disk_cache::Backend { |
| void ReleaseAll(); |
| + // Returns true if a doomed entry exists with this key. |
| bool IsDiskEntryDoomed(const std::string& key); |
| + // Returns true if a non-doomed entry exists with this key. |
| + bool IsDiskEntryNotDoomed(const std::string& key); |
| + |
| + // Invokes ResumeCacheOperation on the corresponding MockDiskEntry with |key|. |
| + int ResumeCacheOperation(const std::string& key); |
| + int ResumeDoomedEntryCacheOperation(const std::string& key); |
| + |
| + // Resume deferred cache operation by posting |resume_callback_| with |
| + // |resume_return_code_|. Returns ERR_IO_PENDING. |
| + int ResumeCacheOperation(); |
| + |
| + void SetDefer(DeferOp defer_op) { defer_op_ = defer_op; } |
| + |
| + // Invokes SetDefer on the corresponding MockDiskEntry with |key|. |
| + void SetDefer(const std::string& key, DeferOp defer_op); |
| + |
| private: |
| using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; |
| class NotImplementedIterator; |
| @@ -170,6 +205,7 @@ class MockDiskCache : public disk_cache::Backend { |
| void CallbackLater(const CompletionCallback& callback, int result); |
| EntryMap entries_; |
| + EntryMap doomed_entries_; |
| int open_count_; |
| int create_count_; |
| int doomed_count_; |
| @@ -177,6 +213,11 @@ class MockDiskCache : public disk_cache::Backend { |
| bool soft_failures_; |
| bool double_create_check_; |
| bool fail_sparse_requests_; |
| + |
| + // Used for pause and restart. |
| + DeferOp defer_op_; |
| + CompletionCallback resume_callback_; |
| + int resume_return_code_; |
| }; |
| class MockBackendFactory : public HttpCache::BackendFactory { |
| @@ -244,7 +285,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); |