Index: net/http/mock_http_cache.h |
diff --git a/net/http/mock_http_cache.h b/net/http/mock_http_cache.h |
index ca0730429f7b401e18987acdf31a3859991b62f0..6f8ed65744e5466fc0d82ddce0098f2b1c975d43 100644 |
--- a/net/http/mock_http_cache.h |
+++ b/net/http/mock_http_cache.h |
@@ -27,6 +27,10 @@ namespace net { |
class MockDiskEntry : public disk_cache::Entry, |
public base::RefCounted<MockDiskEntry> { |
public: |
+ // If |*defer| is set to true, the transaction will wait until |
+ // ResumeCacheOperation is called before accessing the cache. |
+ typedef base::Callback<void(bool* defer)> BeforeCacheOperationCallback; |
jkarlin
2017/07/07 19:12:39
Using instead of typedef
jkarlin
2017/07/07 19:12:39
Instead of passing back a bool* defer (we always s
shivanisha
2017/07/10 18:51:27
MockHttpCache needs to keep track of doomed entrie
|
+ |
explicit MockDiskEntry(const std::string& key); |
bool is_doomed() const { return doomed_; } |
@@ -74,6 +78,14 @@ class MockDiskEntry : public disk_cache::Entry, |
// again or all subsequent tests will fail. |
static void IgnoreCallbacks(bool value); |
+ // Sets the callback to be invoked before cache operation. |
+ void SetBeforeCacheOperationCallback( |
jkarlin
2017/07/07 19:12:39
Name is too general, specifically this is for Read
shivanisha
2017/07/10 18:51:27
Removed this for simplicity and using a DeferOp en
|
+ const BeforeCacheOperationCallback& callback); |
+ |
+ // Resume deferred cache operation by posting |resume_callback_| with |
+ // |resume_return_code_|. Returns ERR_IO_PENDING. |
+ int ResumeCacheOperation(); |
jkarlin
2017/07/07 19:12:39
BeforeCacheOperationCallback could be passed a cal
shivanisha
2017/07/10 18:51:27
The latest changes probably make this not applicab
|
+ |
private: |
friend class base::RefCounted<MockDiskEntry>; |
struct CallbackInfo; |
@@ -106,6 +118,13 @@ class MockDiskEntry : public disk_cache::Entry, |
bool busy_; |
bool delayed_; |
bool cancel_; |
+ |
+ // TODO(shivanisha): Currently this is only used for ReadData. Extend to |
+ // other cache operations as well. |
+ BeforeCacheOperationCallback before_cache_callback_; |
+ CompletionCallback resume_callback_; // used for pause and restart. |
+ int resume_return_code_; |
+ |
static bool ignore_callbacks_; |
}; |
@@ -160,6 +179,15 @@ class MockDiskCache : public disk_cache::Backend { |
bool IsDiskEntryDoomed(const std::string& key); |
+ // Add the cache operation callback to the entry. |
+ void SetBeforeCacheOperationCallback( |
+ const std::string& key, |
+ const MockDiskEntry::BeforeCacheOperationCallback& callback); |
+ |
+ // Resume deferred cache operation on entry with |key|. |
+ int ResumeCacheOperation(const std::string& key); |
+ int ResumeDoomedEntryCacheOperation(const std::string& key); |
+ |
private: |
using EntryMap = std::unordered_map<std::string, MockDiskEntry*>; |
class NotImplementedIterator; |
@@ -167,6 +195,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_; |
bool fail_requests_; |
@@ -240,7 +269,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); |