From 06e62baf611d6fca8698d50765bca81989155845 Mon Sep 17 00:00:00 2001 From: "rvargas@google.com" Date: Thu, 8 Oct 2009 23:07:39 +0000 Subject: Disk cache: Add a method to cancel pending sparse operations. The sparse IO methods require exclusive use of the cache entry and they complain when that requirement is violated. When the user cancels a request and reissues another one to the same entry, we may be waiting for the previous operation to finish when we receive a new IO request, so we fail. This CL add a way for the HTTP cache to cancel IO operations and get a notification when the disk cache is able to operate on that entry again. BUG=23862 TEST=unittests Review URL: http://codereview.chromium.org/256090 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28475 0039d316-1c4b-4281-b951-d872f2087c98 --- net/http/http_cache.cc | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) (limited to 'net/http/http_cache.cc') diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 7fb9703..7985992 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -161,7 +161,10 @@ class HttpCache::Transaction : public HttpTransaction { network_read_callback_(this, &Transaction::OnNetworkReadCompleted)), ALLOW_THIS_IN_INITIALIZER_LIST( cache_read_callback_(new CancelableCompletionCallback( - this, &Transaction::OnCacheReadCompleted))) { + this, &Transaction::OnCacheReadCompleted))), + ALLOW_THIS_IN_INITIALIZER_LIST( + entry_ready_callback_(new CancelableCompletionCallback( + this, &Transaction::OnCacheEntryReady))) { } // Clean up the transaction. @@ -251,6 +254,10 @@ class HttpCache::Transaction : public HttpTransaction { // 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. @@ -345,6 +352,9 @@ class HttpCache::Transaction : public HttpTransaction { // 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 load_log_; const HttpRequestInfo* request_; scoped_ptr custom_request_; @@ -373,14 +383,21 @@ class HttpCache::Transaction : public HttpTransaction { CompletionCallbackImpl network_read_callback_; scoped_refptr > cache_read_callback_; + scoped_refptr > + 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 { @@ -928,7 +945,10 @@ int HttpCache::Transaction::BeginPartialCacheValidation() { 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()) { @@ -937,6 +957,13 @@ int HttpCache::Transaction::BeginPartialCacheValidation() { } } + 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. @@ -1552,6 +1579,11 @@ void HttpCache::Transaction::OnCacheReadCompleted(int result) { DoCacheReadCompleted(result); } +void HttpCache::Transaction::OnCacheEntryReady(int result) { + DCHECK_EQ(OK, result); + ValidateEntryHeadersAndContinue(true); +} + //----------------------------------------------------------------------------- HttpCache::HttpCache(HostResolver* host_resolver, -- cgit v1.1