Index: net/http/mock_http_cache.cc |
diff --git a/net/http/mock_http_cache.cc b/net/http/mock_http_cache.cc |
index 85ffa74584efe289123c9f7d8da4691427d60e12..8ecfbce99041b73a042b0c14bfa0ee12c02580e9 100644 |
--- a/net/http/mock_http_cache.cc |
+++ b/net/http/mock_http_cache.cc |
@@ -50,15 +50,11 @@ struct MockDiskEntry::CallbackInfo { |
int result; |
}; |
-MockDiskEntry::MockDiskEntry() |
- : test_mode_(0), doomed_(false), sparse_(false), |
- fail_requests_(false), busy_(false), delayed_(false) { |
-} |
- |
-MockDiskEntry::MockDiskEntry(const std::string& key) |
+MockDiskEntry::MockDiskEntry(MockDiskCache* backend, const std::string& key) |
: key_(key), doomed_(false), sparse_(false), |
- fail_requests_(false), busy_(false), delayed_(false) { |
+ fail_requests_(false), busy_(false), delayed_(false), backend_(backend) { |
test_mode_ = GetTestModeForEntry(key); |
+ DCHECK(backend); |
} |
void MockDiskEntry::Doom() { |
@@ -139,6 +135,9 @@ int MockDiskEntry::WriteData( |
int MockDiskEntry::ReadSparseData(int64 offset, net::IOBuffer* buf, int buf_len, |
const net::CompletionCallback& callback) { |
DCHECK(!callback.is_null()); |
+ backend_->NotifySparseIO(); |
rvargas (doing something else)
2013/08/28 21:35:47
This is slightly problematic because the contract
pasko
2013/08/28 21:56:28
I did not quite understand this sentence, can you
rvargas (doing something else)
2013/08/28 22:33:40
The thing is that it is possible (valid, and used)
|
+ if (fail_sparse_requests_) |
+ return net::ERR_NOT_IMPLEMENTED; |
if (!sparse_ || busy_) |
return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
if (offset < 0) |
@@ -169,6 +168,9 @@ int MockDiskEntry::WriteSparseData(int64 offset, net::IOBuffer* buf, |
int buf_len, |
const net::CompletionCallback& callback) { |
DCHECK(!callback.is_null()); |
+ backend_->NotifySparseIO(); |
+ if (fail_sparse_requests_) |
+ return net::ERR_NOT_IMPLEMENTED; |
if (busy_) |
return net::ERR_CACHE_OPERATION_NOT_SUPPORTED; |
if (!sparse_) { |
@@ -237,14 +239,21 @@ int MockDiskEntry::GetAvailableRange(int64 offset, int len, int64* start, |
} |
bool MockDiskEntry::CouldBeSparse() const { |
+ backend_->NotifySparseIO(); |
+ if (fail_sparse_requests_) |
+ return false; |
return sparse_; |
} |
void MockDiskEntry::CancelSparseIO() { |
+ backend_->NotifySparseIO(); |
cancel_ = true; |
} |
int MockDiskEntry::ReadyForSparseIO(const net::CompletionCallback& callback) { |
+ backend_->NotifySparseIO(); |
+ if (fail_sparse_requests_) |
+ return net::ERR_NOT_IMPLEMENTED; |
if (!cancel_) |
return net::OK; |
@@ -332,8 +341,9 @@ bool MockDiskEntry::ignore_callbacks_ = false; |
//----------------------------------------------------------------------------- |
MockDiskCache::MockDiskCache() |
- : open_count_(0), create_count_(0), fail_requests_(false), |
- soft_failures_(false), double_create_check_(true) { |
+ : open_count_(0), create_count_(0), sparse_count_(0), fail_requests_(false), |
+ soft_failures_(false), double_create_check_(true), |
+ fail_sparse_requests_(false) { |
} |
MockDiskCache::~MockDiskCache() { |
@@ -400,7 +410,7 @@ int MockDiskCache::CreateEntry(const std::string& key, |
create_count_++; |
- MockDiskEntry* new_entry = new MockDiskEntry(key); |
+ MockDiskEntry* new_entry = new MockDiskEntry(this, key); |
new_entry->AddRef(); |
entries_[key] = new_entry; |
@@ -411,6 +421,9 @@ int MockDiskCache::CreateEntry(const std::string& key, |
if (soft_failures_) |
new_entry->set_fail_requests(); |
+ if (fail_sparse_requests_) |
+ new_entry->set_fail_sparse_requests(); |
+ |
if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START) |
return net::OK; |