Chromium Code Reviews| 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/download_stats.h" | 9 #include "content/browser/download/download_stats.h" |
| 10 #include "content/browser/download/parallel_download_utils.h" | 10 #include "content/browser/download/parallel_download_utils.h" |
| 11 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
| 12 #include "content/public/browser/storage_partition.h" | 12 #include "content/public/browser/storage_partition.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const int kVerboseLevel = 1; | 17 const int kVerboseLevel = 1; |
| 18 | 18 |
| 19 // The minimum remaining download time for parallel request creation. | |
| 20 // TODO(qinmin): make this finch configurable. | |
| 21 const int kMinimumRemainingTimeInSecondsForParallelRequestCreation = 10; | |
| 22 | |
| 19 } // namespace | 23 } // namespace |
| 20 | 24 |
| 21 ParallelDownloadJob::ParallelDownloadJob( | 25 ParallelDownloadJob::ParallelDownloadJob( |
| 22 DownloadItemImpl* download_item, | 26 DownloadItemImpl* download_item, |
| 23 std::unique_ptr<DownloadRequestHandleInterface> request_handle, | 27 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
| 24 const DownloadCreateInfo& create_info) | 28 const DownloadCreateInfo& create_info) |
| 25 : DownloadJobImpl(download_item, std::move(request_handle)), | 29 : DownloadJobImpl(download_item, std::move(request_handle)), |
| 26 initial_request_offset_(create_info.offset), | 30 initial_request_offset_(create_info.offset), |
| 27 content_length_(create_info.total_bytes), | 31 content_length_(create_info.total_bytes), |
| 28 requests_sent_(false), | 32 requests_sent_(false), |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 // of the workers finish their job. | 146 // of the workers finish their job. |
| 143 DownloadItem::ReceivedSlices slices_to_download = | 147 DownloadItem::ReceivedSlices slices_to_download = |
| 144 FindSlicesToDownload(download_item_->GetReceivedSlices()); | 148 FindSlicesToDownload(download_item_->GetReceivedSlices()); |
| 145 | 149 |
| 146 DCHECK(!slices_to_download.empty()); | 150 DCHECK(!slices_to_download.empty()); |
| 147 int64_t first_slice_offset = slices_to_download[0].offset; | 151 int64_t first_slice_offset = slices_to_download[0].offset; |
| 148 DCHECK_LE(initial_request_offset_, first_slice_offset); | 152 DCHECK_LE(initial_request_offset_, first_slice_offset); |
| 149 | 153 |
| 150 // Create more slices for a new download. The initial request may generate | 154 // Create more slices for a new download. The initial request may generate |
| 151 // a received slice. | 155 // a received slice. |
| 152 if (slices_to_download.size() <= 1 && | 156 if (slices_to_download.size() <= 1 && download_item_->GetTotalBytes() > 0) { |
| 153 initial_request_offset_ <= first_slice_offset) { | 157 int64_t current_speed = download_item_->CurrentSpeed() == 0 |
|
David Trainor- moved to gerrit
2017/04/10 20:10:00
std::max(1, download_item_->CurrentSpeed())? Also
qinmin
2017/04/10 21:43:39
Done.
| |
| 154 // TODO(qinmin): Check the size of the last slice. If it is huge, we can | 158 ? 1 |
| 155 // split it into N pieces and pass the last N-1 pieces to different workers. | 159 : download_item_->CurrentSpeed(); |
| 156 // Otherwise, just fork |slices_to_download.size()| number of workers. | 160 int64_t remaining_bytes = |
| 157 slices_to_download = FindSlicesForRemainingContent( | 161 download_item_->GetTotalBytes() - download_item_->GetReceivedBytes(); |
| 158 first_slice_offset, | 162 if (remaining_bytes / current_speed > |
|
David Trainor- moved to gerrit
2017/04/10 20:10:00
Do we want an UMA stat for when we decide/don't de
qinmin
2017/04/10 21:43:39
will add the decion about parallel download creati
| |
| 159 content_length_ - first_slice_offset + initial_request_offset_, | 163 kMinimumRemainingTimeInSecondsForParallelRequestCreation) { |
| 160 GetParallelRequestCount(), GetMinSliceSize()); | 164 // TODO(qinmin): Check the size of the last slice. If it is huge, we can |
| 165 // split it into N pieces and pass the last N-1 pieces to different | |
| 166 // workers. Otherwise, just fork |slices_to_download.size()| number of | |
| 167 // workers. | |
| 168 slices_to_download = FindSlicesForRemainingContent( | |
| 169 first_slice_offset, | |
| 170 content_length_ - first_slice_offset + initial_request_offset_, | |
| 171 GetParallelRequestCount(), GetMinSliceSize()); | |
| 172 } | |
| 161 } | 173 } |
| 162 | 174 |
| 163 DCHECK(!slices_to_download.empty()); | 175 DCHECK(!slices_to_download.empty()); |
| 164 DCHECK_EQ(slices_to_download.back().received_bytes, | 176 DCHECK_EQ(slices_to_download.back().received_bytes, |
| 165 DownloadSaveInfo::kLengthFullContent); | 177 DownloadSaveInfo::kLengthFullContent); |
| 166 | 178 |
| 167 ForkSubRequests(slices_to_download); | 179 ForkSubRequests(slices_to_download); |
| 168 RecordParallelDownloadRequestCount( | 180 RecordParallelDownloadRequestCount( |
| 169 static_cast<int>(slices_to_download.size())); | 181 static_cast<int>(slices_to_download.size())); |
| 170 requests_sent_ = true; | 182 requests_sent_ = true; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 // download request. | 224 // download request. |
| 213 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 225 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 214 blink::WebReferrerPolicyAlways)); | 226 blink::WebReferrerPolicyAlways)); |
| 215 // Send the request. | 227 // Send the request. |
| 216 worker->SendRequest(std::move(download_params)); | 228 worker->SendRequest(std::move(download_params)); |
| 217 DCHECK(workers_.find(offset) == workers_.end()); | 229 DCHECK(workers_.find(offset) == workers_.end()); |
| 218 workers_[offset] = std::move(worker); | 230 workers_[offset] = std::move(worker); |
| 219 } | 231 } |
| 220 | 232 |
| 221 } // namespace content | 233 } // namespace content |
| OLD | NEW |