Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Unified Diff: content/browser/download/parallel_download_utils.cc

Issue 2742093002: Glue parallel download job and download file together. (Closed)
Patch Set: Rebase, and adjust unittests with recent landed CLs. Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/download/parallel_download_utils.h ('k') | content/public/browser/download_item.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 5b719c3646f9a31198a0357f33c04dbba4b5ff0e..4327d8d909a4fa76802fcd63c7ecb543320a04fa 100644
--- a/content/browser/download/parallel_download_utils.cc
+++ b/content/browser/download/parallel_download_utils.cc
@@ -42,6 +42,48 @@ bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs,
} // 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. TODO(xingliu) HTTP/1.1 protocol, not QUIC or HTTP/2.
+
+ // 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 content_length,
+ int request_count) {
+ std::vector<DownloadItem::ReceivedSlice> slices_to_download;
+ if (request_count <= 0)
+ return slices_to_download;
+
+ // TODO(xingliu): Consider to use minimum size of a slice.
+ int64_t slice_size = content_length / request_count;
+ slice_size = slice_size > 0 ? slice_size : 1;
+ int64_t current_offset = bytes_received;
+ for (int i = 0, num_requests = content_length / 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;
« no previous file with comments | « content/browser/download/parallel_download_utils.h ('k') | content/public/browser/download_item.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698