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..ac4ba72b5b860a28e93ce89885288260895f6ed3 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,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,21 @@ 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. |
| + void SetDefer(MockDiskEntry::DeferOp defer_op) { defer_op_ = defer_op; } |
| + |
| + // Resume deferred cache operation by posting |resume_callback_| with |
| + // |resume_return_code_|. Returns ERR_IO_PENDING. |
| + int ResumeCacheOperation(); |
|
jkarlin
2017/07/13 17:27:24
It's unclear when you should get the entry and cal
shivanisha
2017/07/13 18:53:19
Renaming this ResumeDiskEntryOperation to let it b
|
| + |
| + // Returns a reference to the disk entry with the given |key|. Also adds a |
| + // reference for that entry, so the test should invoke Close() on it to |
| + // release the reference count. |
| + MockDiskEntry* GetDiskEntryRef(const std::string& key); |
|
jkarlin
2017/07/13 17:27:25
scoped_refptr<MockDiskEntry> GetDiskEntryRef(const
shivanisha
2017/07/13 18:53:45
done
|
| + |
| private: |
| using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; |
| class NotImplementedIterator; |
| @@ -177,6 +208,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 +280,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); |