Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Unified Diff: content/browser/download/download_worker.cc

Issue 2767593003: Handle early pause, cancel for parallel requests. (Closed)
Patch Set: Work on feedback. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/download/download_worker.cc
diff --git a/content/browser/download/download_worker.cc b/content/browser/download/download_worker.cc
index 5f65d9eb82c2e9882b905e5f284fbdd41d8f667d..e677352ebd0709d9abb82936bec7d60f8daffdd6 100644
--- a/content/browser/download/download_worker.cc
+++ b/content/browser/download/download_worker.cc
@@ -77,6 +77,13 @@ void DownloadWorker::OnUrlDownloaderStarted(
// |callback| is not used in subsequent requests.
DCHECK(callback.is_null());
+ // Destroy the request if user canceled.
+ if (delegate_->IsCanceled()) {
+ VLOG(kVerboseLevel) << "Byte stream arrived after user cancel the request.";
+ create_info->request_handle->CancelRequest();
+ return;
+ }
+
// TODO(xingliu): Add the interrupt reason and metric data for precondition
// failure. Make DownloadRequestCore know if it should return error if the
// the server gives a different part of the content, e.g. "If-Match" return
@@ -90,8 +97,14 @@ void DownloadWorker::OnUrlDownloaderStarted(
}
request_handle_ = std::move(create_info->request_handle);
- if (delegate_)
- delegate_->OnByteStreamReady(this, std::move(stream_reader));
+
+ // Pause the stream if user paused, still push the stream reader to the sink.
+ if (delegate_->IsPaused()) {
+ VLOG(kVerboseLevel) << "Byte stream arrived after user pause the request.";
+ Pause();
+ }
+
+ delegate_->OnByteStreamReady(this, std::move(stream_reader));
}
void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) {

Powered by Google App Engine
This is Rietveld 408576698