diff options
Diffstat (limited to 'content/browser/loader/resource_loader.cc')
-rw-r--r-- | content/browser/loader/resource_loader.cc | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/content/browser/loader/resource_loader.cc b/content/browser/loader/resource_loader.cc index 6bab366..fde1697 100644 --- a/content/browser/loader/resource_loader.cc +++ b/content/browser/loader/resource_loader.cc @@ -355,14 +355,23 @@ void ResourceLoader::OnReadCompleted(net::URLRequest* unused, int bytes_read) { return; } - CompleteRead(bytes_read); - - if (is_deferred()) + // 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, + // do nothing until resumed. + // + // 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)) return; - if (request_->status().is_success() && bytes_read > 0) { + DCHECK(request_->status().is_success()); + DCHECK(!is_deferred()); + if (bytes_read > 0) { StartReading(true); // Read the next chunk. } else { + // URLRequest reported an EOF. Call ResponseCompleted. + DCHECK_EQ(0, bytes_read); ResponseCompleted(); } } @@ -603,7 +612,7 @@ void ResourceLoader::ReadMore(int* bytes_read) { // inspecting the URLRequest's status. } -void ResourceLoader::CompleteRead(int bytes_read) { +bool ResourceLoader::CompleteRead(int bytes_read) { DCHECK(bytes_read >= 0); DCHECK(request_->status().is_success()); @@ -612,9 +621,12 @@ void 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; } void ResourceLoader::ResponseCompleted() { |