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

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

Issue 2750853004: Add a delay to send the parallel requests. (Closed)
Patch Set: Work on nits. 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 c8bba093fa4d9ed30d7e44329826058fa4f3727c..6b1681556e615f769580556c3567dbc841d99173 100644
--- a/content/browser/download/parallel_download_job.cc
+++ b/content/browser/download/parallel_download_job.cc
@@ -18,24 +18,37 @@ ParallelDownloadJob::ParallelDownloadJob(
const DownloadCreateInfo& create_info)
: DownloadJobImpl(download_item, std::move(request_handle)),
initial_request_offset_(create_info.save_info->offset),
- initial_request_length_(create_info.save_info->length) {}
+ initial_request_length_(create_info.save_info->length),
+ requests_sent_(false) {}
ParallelDownloadJob::~ParallelDownloadJob() = default;
void ParallelDownloadJob::Start() {
DownloadJobImpl::Start();
- BuildParallelRequests();
+ BuildParallelRequestAfterDelay();
}
void ParallelDownloadJob::Cancel(bool user_cancel) {
DownloadJobImpl::Cancel(user_cancel);
+
+ if (!requests_sent_) {
+ timer_.Stop();
+ return;
+ }
+
for (auto& worker : workers_)
worker->Cancel();
}
void ParallelDownloadJob::Pause() {
DownloadJobImpl::Pause();
+
+ if (!requests_sent_) {
+ timer_.Stop();
+ return;
+ }
+
for (auto& worker : workers_)
worker->Pause();
}
@@ -45,6 +58,13 @@ void ParallelDownloadJob::Resume(bool resume_request) {
if (!resume_request)
return;
+ // Send parallel requests if the download is paused previously.
+ if (!requests_sent_) {
+ if (!timer_.IsRunning())
+ BuildParallelRequestAfterDelay();
+ return;
+ }
+
for (auto& worker : workers_)
worker->Resume();
}
@@ -73,7 +93,18 @@ void ParallelDownloadJob::ForkRequestsForNewDownload(int64_t bytes_received,
}
}
+void ParallelDownloadJob::BuildParallelRequestAfterDelay() {
+ DCHECK(workers_.empty());
+ DCHECK(!requests_sent_);
+ DCHECK(!timer_.IsRunning());
+
+ timer_.Start(FROM_HERE, GetParallelRequestDelayConfig(), this,
+ &ParallelDownloadJob::BuildParallelRequests);
+}
+
void ParallelDownloadJob::BuildParallelRequests() {
+ DCHECK(!requests_sent_);
+
// Calculate the slices to download and fork parallel requests.
std::vector<DownloadItem::ReceivedSlice> slices_to_download =
FindSlicesToDownload(download_item_->GetReceivedSlices());
@@ -97,6 +128,8 @@ void ParallelDownloadJob::BuildParallelRequests() {
// split it into N pieces and pass the last N-1 pirces to different workers.
// Otherwise, just fork |slices_to_download.size()| number of workers.
}
+
+ requests_sent_ = true;
}
void ParallelDownloadJob::CreateRequest(int64_t offset, int64_t length) {
« no previous file with comments | « content/browser/download/parallel_download_job.h ('k') | content/browser/download/parallel_download_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698