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

Side by Side Diff: content/browser/download/parallel_download_utils.cc

Issue 2783473002: Fix issues and feature polishing for parallel download. (Closed)
Patch Set: Rebase. Created 3 years, 8 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 unified diff | Download patch
OLDNEW
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_utils.h" 5 #include "content/browser/download/parallel_download_utils.h"
6 6
7 #include "base/metrics/field_trial_params.h" 7 #include "base/metrics/field_trial_params.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/public/browser/download_save_info.h" 10 #include "content/public/browser/download_save_info.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 !create_info.etag.empty() || !create_info.last_modified.empty(); 56 !create_info.etag.empty() || !create_info.last_modified.empty();
57 57
58 return has_strong_validator && create_info.accept_range && 58 return has_strong_validator && create_info.accept_range &&
59 create_info.total_bytes >= GetMinSliceSizeConfig() && 59 create_info.total_bytes >= GetMinSliceSizeConfig() &&
60 create_info.connection_info == 60 create_info.connection_info ==
61 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1 && 61 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1 &&
62 base::FeatureList::IsEnabled(features::kParallelDownloading); 62 base::FeatureList::IsEnabled(features::kParallelDownloading);
63 } 63 }
64 64
65 std::vector<DownloadItem::ReceivedSlice> FindSlicesForRemainingContent( 65 std::vector<DownloadItem::ReceivedSlice> FindSlicesForRemainingContent(
66 int64_t bytes_received, 66 int64_t current_offset,
67 int64_t content_length, 67 int64_t total_length,
68 int request_count) { 68 int request_count,
69 std::vector<DownloadItem::ReceivedSlice> slices_to_download; 69 int64_t min_slice_size) {
70 if (request_count <= 0) 70 std::vector<DownloadItem::ReceivedSlice> new_slices;
71 return slices_to_download;
72 71
73 // TODO(xingliu): Consider to use minimum size of a slice. 72 if (request_count > 0) {
74 int64_t slice_size = content_length / request_count; 73 int64_t slice_size =
75 slice_size = slice_size > 0 ? slice_size : 1; 74 std::max<int64_t>(total_length / request_count, min_slice_size);
76 int64_t current_offset = bytes_received; 75 slice_size = slice_size > 0 ? slice_size : 1;
77 for (int i = 0, num_requests = content_length / slice_size; 76 for (int i = 0, num_requests = total_length / slice_size;
78 i < num_requests - 1; ++i) { 77 i < num_requests - 1; ++i) {
79 slices_to_download.emplace_back(current_offset, slice_size); 78 new_slices.emplace_back(current_offset, slice_size);
80 current_offset += slice_size; 79 current_offset += slice_size;
80 }
81 } 81 }
82 82
83 // Last slice is a half open slice, which results in sending range request 83 // Last slice is a half open slice, which results in sending range request
84 // like "Range:50-" to fetch from 50 bytes to the end of the file. 84 // like "Range:50-" to fetch from 50 bytes to the end of the file.
85 slices_to_download.emplace_back(current_offset, 85 new_slices.emplace_back(current_offset, DownloadSaveInfo::kLengthFullContent);
86 DownloadSaveInfo::kLengthFullContent); 86 return new_slices;
87 return slices_to_download;
88 } 87 }
89 88
90 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload( 89 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload(
91 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { 90 const std::vector<DownloadItem::ReceivedSlice>& received_slices) {
92 std::vector<DownloadItem::ReceivedSlice> result; 91 std::vector<DownloadItem::ReceivedSlice> result;
93 if (received_slices.empty()) { 92 if (received_slices.empty()) {
94 result.emplace_back(0, DownloadSaveInfo::kLengthFullContent); 93 result.emplace_back(0, DownloadSaveInfo::kLengthFullContent);
95 return result; 94 return result;
96 } 95 }
97 96
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 163
165 void DebugSlicesInfo(const DownloadItem::ReceivedSlices& slices) { 164 void DebugSlicesInfo(const DownloadItem::ReceivedSlices& slices) {
166 DVLOG(1) << "Received slices size : " << slices.size(); 165 DVLOG(1) << "Received slices size : " << slices.size();
167 for (const auto& it : slices) { 166 for (const auto& it : slices) {
168 DVLOG(1) << "Slice offset = " << it.offset 167 DVLOG(1) << "Slice offset = " << it.offset
169 << " , received_bytes = " << it.received_bytes; 168 << " , received_bytes = " << it.received_bytes;
170 } 169 }
171 } 170 }
172 171
173 } // namespace content 172 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698