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

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

Issue 2767593003: Handle early pause, cancel for parallel requests. (Closed)
Patch Set: Move is_canceled_ to subclass. 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
« no previous file with comments | « content/browser/download/download_worker.h ('k') | content/browser/download/parallel_download_job.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..35639b5738c9b34a7e5321dee68033ae981fb836 100644
--- a/content/browser/download/download_worker.cc
+++ b/content/browser/download/download_worker.cc
@@ -38,6 +38,8 @@ DownloadWorker::DownloadWorker(DownloadWorker::Delegate* delegate,
: delegate_(delegate),
offset_(offset),
length_(length),
+ is_paused_(false),
+ is_canceled_(false),
weak_factory_(this) {
DCHECK(delegate_);
}
@@ -56,16 +58,19 @@ void DownloadWorker::SendRequest(
}
void DownloadWorker::Pause() {
+ is_paused_ = true;
if (request_handle_)
request_handle_->PauseRequest();
}
void DownloadWorker::Resume() {
+ is_paused_ = false;
if (request_handle_)
request_handle_->ResumeRequest();
}
void DownloadWorker::Cancel() {
+ is_canceled_ = true;
if (request_handle_)
request_handle_->CancelRequest();
}
@@ -77,6 +82,13 @@ void DownloadWorker::OnUrlDownloaderStarted(
// |callback| is not used in subsequent requests.
DCHECK(callback.is_null());
+ // Destroy the request if user canceled.
+ if (is_canceled_) {
+ 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 +102,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 (is_paused_) {
+ VLOG(kVerboseLevel) << "Byte stream arrived after user pause the request.";
+ Pause();
+ }
+
+ delegate_->OnByteStreamReady(this, std::move(stream_reader));
}
void DownloadWorker::OnUrlDownloaderStopped(UrlDownloader* downloader) {
« no previous file with comments | « content/browser/download/download_worker.h ('k') | content/browser/download/parallel_download_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698