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

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

Issue 2767593003: Handle early pause, cancel for parallel requests. (Closed)
Patch Set: Rebase. 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 1a8b93059b30f1c12f7d4801becd6a38bda5c651..0bc92bdc07ffb69bd7732715aaa7e8c7e81a8eab 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,
@@ -85,8 +90,28 @@ void ParallelDownloadJob::BuildParallelRequestAfterDelay() {
void ParallelDownloadJob::OnByteStreamReady(
DownloadWorker* worker,
std::unique_ptr<ByteStreamReader> stream_reader) {
- DownloadJob::AddByteStream(std::move(stream_reader), worker->offset(),
- worker->length());
+ // Destroy the request if user canceled.
+ if (DownloadJob::is_canceled()) {
+ VLOG(kVerboseLevel) << "Byte stream arrived after user cancel the request.";
+ worker->Cancel();
qinmin 2017/03/21 22:53:55 do you need to do this? If cancel is called before
xingliu 2017/03/21 23:19:14 At that time the request handle is not set into th
xingliu 2017/03/21 23:27:59 I'm also fine with let worker defer the cancel cal
qinmin 2017/03/21 23:48:33 Yes, it should be worker's responsibility to handl
xingliu 2017/03/22 01:25:59 Make sense, done.
+ return;
+ }
+
+ // Pause the stream if user paused, still push the stream reader to the sink.
+ if (DownloadJob::is_paused()) {
+ VLOG(kVerboseLevel) << "Byte stream arrived after user pause the request.";
+ worker->Pause();
qinmin 2017/03/21 22:53:55 same here.
xingliu 2017/03/21 23:19:14 We still need to add the stream to DownloadFileImp
qinmin 2017/03/21 23:48:33 Yes. what i mean is that you don't need to call Pa
xingliu 2017/03/22 01:25:59 Done. Moved to worker.
+ }
+
+ 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(
« 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