| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/histogram_macros.h" | 10 #include "base/metrics/histogram_macros.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "content/browser/download/download_create_info.h" | 12 #include "content/browser/download/download_create_info.h" |
| 13 #include "content/browser/download/download_stats.h" | 13 #include "content/browser/download/download_stats.h" |
| 14 #include "content/browser/download/parallel_download_utils.h" | 14 #include "content/browser/download/parallel_download_utils.h" |
| 15 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 16 #include "content/public/browser/storage_partition.h" | 16 #include "content/public/browser/storage_partition.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 const int kVerboseLevel = 1; | 21 const int kVerboseLevel = 1; |
| 22 | 22 |
| 23 } // namespace | 23 } // namespace |
| 24 | 24 |
| 25 ParallelDownloadJob::ParallelDownloadJob( | 25 ParallelDownloadJob::ParallelDownloadJob( |
| 26 DownloadItemImpl* download_item, | 26 DownloadItemImpl* download_item, |
| 27 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 27 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
| 28 const DownloadCreateInfo& create_info) | 28 const DownloadCreateInfo& create_info) |
| 29 : DownloadJobImpl(download_item, std::move(request_handle)), | 29 : DownloadJobImpl(download_item, std::move(request_handle), true), |
| 30 initial_request_offset_(create_info.offset), | 30 initial_request_offset_(create_info.offset), |
| 31 content_length_(create_info.total_bytes), | 31 content_length_(create_info.total_bytes), |
| 32 requests_sent_(false), | 32 requests_sent_(false), |
| 33 is_canceled_(false) {} | 33 is_canceled_(false) {} |
| 34 | 34 |
| 35 ParallelDownloadJob::~ParallelDownloadJob() = default; | 35 ParallelDownloadJob::~ParallelDownloadJob() = default; |
| 36 | 36 |
| 37 void ParallelDownloadJob::Start() { | 37 void ParallelDownloadJob::Start() { |
| 38 DownloadJobImpl::Start(); | 38 DownloadJobImpl::Start(); |
| 39 | 39 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 86 } |
| 87 | 87 |
| 88 int64_t ParallelDownloadJob::GetMinSliceSize() const { | 88 int64_t ParallelDownloadJob::GetMinSliceSize() const { |
| 89 return GetMinSliceSizeConfig(); | 89 return GetMinSliceSizeConfig(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 int ParallelDownloadJob::GetMinRemainingTimeInSeconds() const { | 92 int ParallelDownloadJob::GetMinRemainingTimeInSeconds() const { |
| 93 return GetParallelRequestRemainingTimeConfig().InSeconds(); | 93 return GetParallelRequestRemainingTimeConfig().InSeconds(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 bool ParallelDownloadJob::UsesParallelRequests() const { | |
| 97 return true; | |
| 98 } | |
| 99 | |
| 100 void ParallelDownloadJob::CancelRequestWithOffset(int64_t offset) { | 96 void ParallelDownloadJob::CancelRequestWithOffset(int64_t offset) { |
| 101 if (initial_request_offset_ == offset) { | 97 if (initial_request_offset_ == offset) { |
| 102 DownloadJobImpl::Cancel(false); | 98 DownloadJobImpl::Cancel(false); |
| 103 return; | 99 return; |
| 104 } | 100 } |
| 105 | 101 |
| 106 auto it = workers_.find(offset); | 102 auto it = workers_.find(offset); |
| 107 if (it != workers_.end()) | 103 if (it != workers_.end()) |
| 108 it->second->Cancel(); | 104 it->second->Cancel(); |
| 109 } | 105 } |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // download request. | 243 // download request. |
| 248 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 244 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 249 blink::kWebReferrerPolicyAlways)); | 245 blink::kWebReferrerPolicyAlways)); |
| 250 // Send the request. | 246 // Send the request. |
| 251 worker->SendRequest(std::move(download_params)); | 247 worker->SendRequest(std::move(download_params)); |
| 252 DCHECK(workers_.find(offset) == workers_.end()); | 248 DCHECK(workers_.find(offset) == workers_.end()); |
| 253 workers_[offset] = std::move(worker); | 249 workers_[offset] = std::move(worker); |
| 254 } | 250 } |
| 255 | 251 |
| 256 } // namespace content | 252 } // namespace content |
| OLD | NEW |