| Index: content/browser/download/parallel_download_utils.cc
|
| diff --git a/content/browser/download/parallel_download_utils.cc b/content/browser/download/parallel_download_utils.cc
|
| index d21ea49f20c061e15a062e6fec4758ea0e905705..e49c4a9af65ba893ae85a9e9d362e07d5154295a 100644
|
| --- a/content/browser/download/parallel_download_utils.cc
|
| +++ b/content/browser/download/parallel_download_utils.cc
|
| @@ -30,6 +30,50 @@ const int kParallelRequestCount = 2;
|
|
|
| } // namespace
|
|
|
| +bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) {
|
| + // 1. Accept-Ranges, Content-Length and strong validators response headers.
|
| + // 2. Feature |kParallelDownloading| enabled.
|
| + // 3. Content-Length is no less than the minimum slice size configuration.
|
| + // 3. (Undetermined) Http/1.1 protocol.
|
| + // 4. (Undetermined) Not under http proxy, e.g. data saver.
|
| +
|
| + // Etag and last modified are stored into DownloadCreateInfo in
|
| + // DownloadRequestCore only if the response header complies to the strong
|
| + // validator rule.
|
| + bool has_strong_validator =
|
| + !create_info.etag.empty() || !create_info.last_modified.empty();
|
| +
|
| + return has_strong_validator && create_info.accept_range &&
|
| + create_info.total_bytes >= GetMinSliceSizeConfig() &&
|
| + base::FeatureList::IsEnabled(features::kParallelDownloading);
|
| +}
|
| +
|
| +std::vector<DownloadItem::ReceivedSlice> FindSlicesForRemainingContent(
|
| + int64_t bytes_received,
|
| + int64_t total_bytes,
|
| + int request_count) {
|
| + std::vector<DownloadItem::ReceivedSlice> slices_to_download;
|
| + if (bytes_received >= total_bytes || request_count <= 0)
|
| + return slices_to_download;
|
| +
|
| + // TODO(xingliu): Consider to use minimum size of a slice.
|
| + int64_t bytes_left = total_bytes - bytes_received;
|
| + int64_t slice_size = bytes_left / request_count;
|
| + slice_size = slice_size > 0 ? slice_size : 1;
|
| + int64_t current_offset = bytes_received;
|
| + for (int i = 0, num_requests = bytes_left / slice_size; i < num_requests - 1;
|
| + ++i) {
|
| + slices_to_download.emplace_back(current_offset, slice_size);
|
| + current_offset += slice_size;
|
| + }
|
| +
|
| + // Last slice is a half open slice, which results in sending range request
|
| + // like "Range:50-" to fetch from 50 bytes to the end of the file.
|
| + slices_to_download.emplace_back(current_offset,
|
| + DownloadSaveInfo::kLengthFullContent);
|
| + return slices_to_download;
|
| +}
|
| +
|
| std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload(
|
| const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
|
| std::vector<DownloadItem::ReceivedSlice> result;
|
|
|