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

Unified Diff: content/browser/download/parallel_download_job.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
Index: content/browser/download/parallel_download_job.cc
diff --git a/content/browser/download/parallel_download_job.cc b/content/browser/download/parallel_download_job.cc
index 7e5221178b8f2bbb4285eb46cd1a40d748692210..2ba903e62670efcf061dac0a4ccde7ea622a6d59 100644
--- a/content/browser/download/parallel_download_job.cc
+++ b/content/browser/download/parallel_download_job.cc
@@ -11,6 +11,11 @@
#include "content/public/browser/storage_partition.h"
namespace content {
+namespace {
+
+const int kVerboseLevel = 1;
+
+} // namespace
ParallelDownloadJob::ParallelDownloadJob(
DownloadItemImpl* download_item,
@@ -19,7 +24,8 @@ ParallelDownloadJob::ParallelDownloadJob(
: DownloadJobImpl(download_item, std::move(request_handle)),
initial_request_offset_(create_info.offset),
content_length_(create_info.total_bytes),
- requests_sent_(false) {}
+ requests_sent_(false),
+ is_canceled_(false) {}
ParallelDownloadJob::~ParallelDownloadJob() = default;
@@ -30,6 +36,7 @@ void ParallelDownloadJob::Start() {
}
void ParallelDownloadJob::Cancel(bool user_cancel) {
+ is_canceled_ = true;
DownloadJobImpl::Cancel(user_cancel);
if (!requests_sent_) {
@@ -69,7 +76,6 @@ void ParallelDownloadJob::Resume(bool resume_request) {
worker.second->Resume();
}
-
int ParallelDownloadJob::GetParallelRequestCount() const {
return GetParallelRequestCountConfig();
}
@@ -90,8 +96,15 @@ void ParallelDownloadJob::BuildParallelRequestAfterDelay() {
void ParallelDownloadJob::OnByteStreamReady(
DownloadWorker* worker,
std::unique_ptr<ByteStreamReader> stream_reader) {
- DownloadJob::AddByteStream(std::move(stream_reader), worker->offset(),
- worker->length());
+ bool success = DownloadJob::AddByteStream(std::move(stream_reader),
+ worker->offset(), worker->length());
+
+ // Destroy the request if the sink is gone.
+ if (!success) {
+ VLOG(kVerboseLevel)
+ << "Byte stream arrived after download file is released.";
+ worker->Cancel();
+ }
}
void ParallelDownloadJob::OnServerResponseError(
@@ -105,6 +118,10 @@ void ParallelDownloadJob::OnServerResponseError(
void ParallelDownloadJob::BuildParallelRequests() {
DCHECK(!requests_sent_);
+ DCHECK(!is_paused());
+ if (is_canceled_)
+ return;
+
// TODO(qinmin): The size of |slices_to_download| should be no larger than
// |kParallelRequestCount| unless |kParallelRequestCount| is changed after
// a download is interrupted. This could happen if we use finch to config
« no previous file with comments | « content/browser/download/parallel_download_job.h ('k') | content/browser/download/parallel_download_job_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698