Index: net/http/http_cache.cc |
=================================================================== |
--- net/http/http_cache.cc (revision 28049) |
+++ net/http/http_cache.cc (working copy) |
@@ -190,7 +190,10 @@ |
network_read_callback_(this, &Transaction::OnNetworkReadCompleted)), |
ALLOW_THIS_IN_INITIALIZER_LIST( |
cache_read_callback_(new CancelableCompletionCallback<Transaction>( |
- this, &Transaction::OnCacheReadCompleted))) { |
+ this, &Transaction::OnCacheReadCompleted))), |
+ ALLOW_THIS_IN_INITIALIZER_LIST( |
+ entry_ready_callback_(new CancelableCompletionCallback<Transaction>( |
+ this, &Transaction::OnCacheEntryReady))) { |
} |
// Clean up the transaction. |
@@ -280,6 +283,10 @@ |
// a network error code. |
int BeginPartialCacheValidation(); |
+ // Validates the entry headers against the requested range and continues with |
+ // the validation of the rest of the entry. Returns a network error code. |
+ int ValidateEntryHeadersAndContinue(bool byte_range_requested); |
+ |
// Performs the cache validation for the next chunk of data stored by the |
// cache. If this chunk is not currently stored, starts the network request |
// to fetch it. Returns a network error code. |
@@ -374,6 +381,9 @@ |
// Called to signal completion of the cache's ReadData method: |
void OnCacheReadCompleted(int result); |
+ // Called to signal completion of the cache entry's ReadyForSparseIO method: |
+ void OnCacheEntryReady(int result); |
+ |
scoped_refptr<LoadLog> load_log_; |
const HttpRequestInfo* request_; |
scoped_ptr<HttpRequestInfo> custom_request_; |
@@ -402,14 +412,21 @@ |
CompletionCallbackImpl<Transaction> network_read_callback_; |
scoped_refptr<CancelableCompletionCallback<Transaction> > |
cache_read_callback_; |
+ scoped_refptr<CancelableCompletionCallback<Transaction> > |
+ entry_ready_callback_; |
}; |
HttpCache::Transaction::~Transaction() { |
if (cache_) { |
if (entry_) { |
bool cancel_request = reading_ && enable_range_support_; |
- if (cancel_request && !partial_.get()) |
- cancel_request &= (response_.headers->response_code() == 200); |
+ if (cancel_request) { |
+ if (partial_.get()) { |
+ entry_->disk_entry->CancelSparseIO(); |
+ } else { |
+ cancel_request &= (response_.headers->response_code() == 200); |
+ } |
+ } |
cache_->DoneWithEntry(entry_, this, cancel_request); |
} else { |
@@ -957,7 +974,10 @@ |
return BeginCacheValidation(); |
bool byte_range_requested = partial_.get() != NULL; |
- if (!byte_range_requested) { |
+ if (byte_range_requested) { |
+ if (OK != entry_->disk_entry->ReadyForSparseIO(entry_ready_callback_)) |
+ return ERR_IO_PENDING; |
+ } else { |
// The request is not for a range, but we have stored just ranges. |
partial_.reset(new PartialData()); |
if (!custom_request_.get()) { |
@@ -966,6 +986,13 @@ |
} |
} |
+ return ValidateEntryHeadersAndContinue(byte_range_requested); |
+} |
+ |
+int HttpCache::Transaction::ValidateEntryHeadersAndContinue( |
+ bool byte_range_requested) { |
+ DCHECK(mode_ == READ_WRITE); |
+ |
if (!partial_->UpdateFromStoredHeaders(response_.headers, entry_->disk_entry, |
truncated_)) { |
// The stored data cannot be used. Get rid of it and restart this request. |
@@ -1581,6 +1608,11 @@ |
DoCacheReadCompleted(result); |
} |
+void HttpCache::Transaction::OnCacheEntryReady(int result) { |
+ DCHECK_EQ(OK, result); |
+ ValidateEntryHeadersAndContinue(true); |
+} |
+ |
//----------------------------------------------------------------------------- |
HttpCache::HttpCache(HostResolver* host_resolver, |