Chromium Code Reviews| 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..6e444a28e2bbbc4681b60e360f51c1635a149c68 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,19 @@ 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() { |
| + if (requests_sent_) |
|
qinmin
2017/03/16 17:40:36
nit: DCHECK_FALSE(request_sent);
xingliu
2017/03/16 18:18:35
Done.
|
| + return; |
| + |
| // Calculate the slices to download and fork parallel requests. |
| std::vector<DownloadItem::ReceivedSlice> slices_to_download = |
| FindSlicesToDownload(download_item_->GetReceivedSlices()); |
| @@ -97,6 +129,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) { |