diff options
author | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-16 18:34:55 +0000 |
---|---|---|
committer | davidben@chromium.org <davidben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-16 18:34:55 +0000 |
commit | 218d9d37d7b5c68c63c978dfe971385cc610f2ca (patch) | |
tree | f70202d0eb796fad26fd3eecc513aa00c1b2c7e1 /content | |
parent | 5698964d610f2ade49e696bdc3f4a9f10803f2d5 (diff) | |
download | chromium_src-218d9d37d7b5c68c63c978dfe971385cc610f2ca.zip chromium_src-218d9d37d7b5c68c63c978dfe971385cc610f2ca.tar.gz chromium_src-218d9d37d7b5c68c63c978dfe971385cc610f2ca.tar.bz2 |
Fix AwContentsTest#testDownload.
The handler could cause the request to be cancelled out-of-band in
OnReadCompleted without returning false.
BUG=363563
Review URL: https://codereview.chromium.org/238933005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@264258 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
-rw-r--r-- | content/browser/loader/resource_loader.cc | 16 | ||||
-rw-r--r-- | content/browser/loader/resource_loader.h | 5 |
2 files changed, 11 insertions, 10 deletions
diff --git a/content/browser/loader/resource_loader.cc b/content/browser/loader/resource_loader.cc index fde1697..251fc2e 100644 --- a/content/browser/loader/resource_loader.cc +++ b/content/browser/loader/resource_loader.cc @@ -355,6 +355,8 @@ void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { return; } + CompleteRead(bytes_read); + // If the handler cancelled or deferred the request, do not continue // processing the read. If cancelled, the URLRequest has already been // cancelled and will schedule an erroring OnReadCompleted later. If deferred, @@ -362,11 +364,9 @@ void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { // // Note: if bytes_read is 0 (EOF) and the handler defers, resumption will call // Read() on the URLRequest again and get a second EOF. - if (!CompleteRead(bytes_read)) + if (is_deferred() || !request_->status().is_success()) return; - DCHECK(request_->status().is_success()); - DCHECK(!is_deferred()); if (bytes_read > 0) { StartReading(true); // Read the next chunk. } else { @@ -612,7 +612,7 @@ void ResourceLoader::ReadMore(int* bytes_read) { // inspecting the URLRequest's status. } -bool ResourceLoader::CompleteRead(int bytes_read) { +void ResourceLoader::CompleteRead(int bytes_read) { DCHECK(bytes_read >= 0); DCHECK(request_->status().is_success()); @@ -621,12 +621,14 @@ bool ResourceLoader::CompleteRead(int bytes_read) { bool defer = false; if (!handler_->OnReadCompleted(info->GetRequestID(), bytes_read, &defer)) { Cancel(); - return false; } else if (defer) { deferred_stage_ = DEFERRED_READ; // Read next chunk when resumed. - return false; } - return true; + + // Note: the request may still have been cancelled while OnReadCompleted + // returns true if OnReadCompleted caused request to get cancelled + // out-of-band. (In AwResourceDispatcherHostDelegate::DownloadStarting, for + // instance.) } void ResourceLoader::ResponseCompleted() { diff --git a/content/browser/loader/resource_loader.h b/content/browser/loader/resource_loader.h index 806b526..79dcf609 100644 --- a/content/browser/loader/resource_loader.h +++ b/content/browser/loader/resource_loader.h @@ -98,9 +98,8 @@ class CONTENT_EXPORT ResourceLoader : public net::URLRequest::Delegate, void StartReading(bool is_continuation); void ResumeReading(); void ReadMore(int* bytes_read); - // Passes a read result to the handler. Returns true to continue processing - // and false if the handler deferred or cancelled the request. - bool CompleteRead(int bytes_read); + // Passes a read result to the handler. + void CompleteRead(int bytes_read); void ResponseCompleted(); void CallDidFinishLoading(); void RecordHistograms(); |