| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/download/parallel_download_job.h" | 5 #include "content/browser/download/parallel_download_job.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "content/browser/download/download_create_info.h" | 8 #include "content/browser/download/download_create_info.h" |
| 9 #include "content/browser/download/parallel_download_utils.h" | 9 #include "content/browser/download/parallel_download_utils.h" |
| 10 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 11 #include "content/public/browser/storage_partition.h" | 11 #include "content/public/browser/storage_partition.h" |
| 12 | 12 |
| 13 namespace content { | 13 namespace content { |
| 14 | 14 |
| 15 ParallelDownloadJob::ParallelDownloadJob( | 15 ParallelDownloadJob::ParallelDownloadJob( |
| 16 DownloadItemImpl* download_item, | 16 DownloadItemImpl* download_item, |
| 17 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 17 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
| 18 const DownloadCreateInfo& create_info) | 18 const DownloadCreateInfo& create_info) |
| 19 : DownloadJobImpl(download_item, std::move(request_handle)), | 19 : DownloadJobImpl(download_item, std::move(request_handle)), |
| 20 initial_request_offset_(create_info.save_info->offset), | 20 initial_request_offset_(create_info.save_info->offset), |
| 21 initial_request_length_(create_info.save_info->length) {} | 21 initial_request_length_(create_info.save_info->length) {} |
| 22 | 22 |
| 23 ParallelDownloadJob::~ParallelDownloadJob() = default; | 23 ParallelDownloadJob::~ParallelDownloadJob() = default; |
| 24 | 24 |
| 25 void ParallelDownloadJob::Start() { | 25 void ParallelDownloadJob::Start() { |
| 26 DownloadJobImpl::Start(); | 26 DownloadJobImpl::Start(); |
| 27 | 27 |
| 28 BuildParallelRequests(); | 28 timer_ = base::MakeUnique<base::OneShotTimer>(); |
| 29 timer_->Start(FROM_HERE, GetParallelRequestDelayConfig(), this, |
| 30 &ParallelDownloadJob::BuildParallelRequests); |
| 29 } | 31 } |
| 30 | 32 |
| 31 void ParallelDownloadJob::Cancel(bool user_cancel) { | 33 void ParallelDownloadJob::Cancel(bool user_cancel) { |
| 32 DownloadJobImpl::Cancel(user_cancel); | 34 DownloadJobImpl::Cancel(user_cancel); |
| 33 for (auto& worker : workers_) | 35 for (auto& worker : workers_) |
| 34 worker->Cancel(); | 36 worker->Cancel(); |
| 35 } | 37 } |
| 36 | 38 |
| 37 void ParallelDownloadJob::Pause() { | 39 void ParallelDownloadJob::Pause() { |
| 38 DownloadJobImpl::Pause(); | 40 DownloadJobImpl::Pause(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 // Subsequent range requests have the same referrer URL as the original | 124 // Subsequent range requests have the same referrer URL as the original |
| 123 // download request. | 125 // download request. |
| 124 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 126 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 125 blink::WebReferrerPolicyAlways)); | 127 blink::WebReferrerPolicyAlways)); |
| 126 // Send the request. | 128 // Send the request. |
| 127 worker->SendRequest(std::move(download_params)); | 129 worker->SendRequest(std::move(download_params)); |
| 128 workers_.push_back(std::move(worker)); | 130 workers_.push_back(std::move(worker)); |
| 129 } | 131 } |
| 130 | 132 |
| 131 } // namespace content | 133 } // namespace content |
| OLD | NEW |