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" | |
| 9 #include "content/browser/download/parallel_download_utils.h" | |
| 8 #include "content/public/browser/browser_context.h" | 10 #include "content/public/browser/browser_context.h" |
| 9 #include "content/public/browser/storage_partition.h" | 11 #include "content/public/browser/storage_partition.h" |
| 10 | 12 |
| 11 namespace content { | 13 namespace content { |
| 12 | 14 |
| 13 namespace { | 15 namespace { |
| 14 | 16 |
| 15 // TODO(xingliu): Use finch parameters to configure constants. | 17 // TODO(xingliu): Use finch parameters to configure constants. |
| 16 // Default number of requests in a parallel download, including the original | 18 // Default number of requests in a parallel download, including the original |
| 17 // request. | 19 // request. |
| 18 const int kParallelRequestCount = 2; | 20 const int kParallelRequestCount = 2; |
| 19 | 21 |
| 20 } // namespace | 22 } // namespace |
| 21 | 23 |
| 22 ParallelDownloadJob::ParallelDownloadJob( | 24 ParallelDownloadJob::ParallelDownloadJob( |
| 23 DownloadItemImpl* download_item, | 25 DownloadItemImpl* download_item, |
| 24 std::unique_ptr<DownloadRequestHandleInterface> request_handle) | 26 std::unique_ptr<DownloadRequestHandleInterface> request_handle, |
| 27 const DownloadCreateInfo& create_info) | |
| 25 : DownloadJobImpl(download_item, std::move(request_handle)), | 28 : DownloadJobImpl(download_item, std::move(request_handle)), |
| 26 request_num_(kParallelRequestCount) {} | 29 request_num_(kParallelRequestCount), |
| 30 initial_request_offset_(create_info.save_info->offset), | |
| 31 initial_request_length_(create_info.save_info->length) {} | |
| 27 | 32 |
| 28 ParallelDownloadJob::~ParallelDownloadJob() = default; | 33 ParallelDownloadJob::~ParallelDownloadJob() = default; |
| 29 | 34 |
| 35 void ParallelDownloadJob::Start() { | |
| 36 DownloadJobImpl::Start(); | |
| 37 | |
| 38 std::vector<DownloadItem::ReceivedSlice> slices_to_download = | |
|
xingliu
2017/03/03 18:44:15
There is already a function to build requests for
qinmin
2017/03/03 19:32:35
Start() is called on both resumption and new downl
qinmin
2017/03/03 19:44:33
To clarify, Start() is called when Resuming an int
xingliu
2017/03/03 21:37:44
sgtm.
| |
| 39 FindSlicesToDownload(download_item_->GetReceivedSlices()); | |
| 40 // The initial request should cover the first slice. | |
| 41 DCHECK_GE(slices_to_download[0].offset, initial_request_offset_); | |
| 42 DCHECK(initial_request_length_ == DownloadSaveInfo::kLengthFullContent || | |
| 43 initial_request_offset_ + initial_request_length_ >= | |
| 44 slices_to_download[0].offset + | |
| 45 slices_to_download[0].received_bytes); | |
| 46 if (slices_to_download.size() >= kParallelRequestCount) { | |
|
xingliu
2017/03/03 18:44:15
Maybe we can keep the mechanism simple for the fir
qinmin
2017/03/03 19:32:35
For resumption, there could be less than N slices.
xingliu
2017/03/03 21:37:44
In general sgtm if the slices are written to db af
qinmin
2017/03/03 22:09:43
what do you mean by "write slice info"?
You mean
| |
| 47 // Get the next |kParallelRequestCount - 1| slices and fork new requests. | |
| 48 } else { | |
| 49 // Split the last slice and assign it to different workers. | |
| 50 } | |
| 51 } | |
| 52 | |
| 30 void ParallelDownloadJob::Cancel(bool user_cancel) { | 53 void ParallelDownloadJob::Cancel(bool user_cancel) { |
| 31 DownloadJobImpl::Cancel(user_cancel); | 54 DownloadJobImpl::Cancel(user_cancel); |
| 32 for (auto& worker : workers_) | 55 for (auto& worker : workers_) |
| 33 worker->Cancel(); | 56 worker->Cancel(); |
| 34 } | 57 } |
| 35 | 58 |
| 36 void ParallelDownloadJob::Pause() { | 59 void ParallelDownloadJob::Pause() { |
| 37 DownloadJobImpl::Pause(); | 60 DownloadJobImpl::Pause(); |
| 38 for (auto& worker : workers_) | 61 for (auto& worker : workers_) |
| 39 worker->Pause(); | 62 worker->Pause(); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 // Subsequent range requests have the same referrer URL as the original | 117 // Subsequent range requests have the same referrer URL as the original |
| 95 // download request. | 118 // download request. |
| 96 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), | 119 download_params->set_referrer(Referrer(download_item_->GetReferrerUrl(), |
| 97 blink::WebReferrerPolicyAlways)); | 120 blink::WebReferrerPolicyAlways)); |
| 98 // Send the request. | 121 // Send the request. |
| 99 worker->SendRequest(std::move(download_params)); | 122 worker->SendRequest(std::move(download_params)); |
| 100 workers_.push_back(std::move(worker)); | 123 workers_.push_back(std::move(worker)); |
| 101 } | 124 } |
| 102 | 125 |
| 103 } // namespace content | 126 } // namespace content |
| OLD | NEW |