| 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_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 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 // TODO(qinmin): replace this with a comparator operator in | 36 // TODO(qinmin): replace this with a comparator operator in |
| 37 // DownloadItem::ReceivedSlice. | 37 // DownloadItem::ReceivedSlice. |
| 38 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs, | 38 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs, |
| 39 const DownloadItem::ReceivedSlice& rhs) { | 39 const DownloadItem::ReceivedSlice& rhs) { |
| 40 return lhs.offset < rhs.offset; | 40 return lhs.offset < rhs.offset; |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) { | |
| 46 // To enable parallel download, following conditions need to be satisfied. | |
| 47 // 1. Accept-Ranges, Content-Length and strong validators response headers. | |
| 48 // 2. Feature |kParallelDownloading| enabled. | |
| 49 // 3. Content-Length is no less than the minimum slice size configuration. | |
| 50 // 3. HTTP/1.1 protocol, not QUIC nor HTTP/1.0. | |
| 51 | |
| 52 // Etag and last modified are stored into DownloadCreateInfo in | |
| 53 // DownloadRequestCore only if the response header complies to the strong | |
| 54 // validator rule. | |
| 55 bool has_strong_validator = | |
| 56 !create_info.etag.empty() || !create_info.last_modified.empty(); | |
| 57 | |
| 58 return has_strong_validator && create_info.accept_range && | |
| 59 create_info.total_bytes >= GetMinSliceSizeConfig() && | |
| 60 create_info.connection_info == | |
| 61 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1 && | |
| 62 base::FeatureList::IsEnabled(features::kParallelDownloading); | |
| 63 } | |
| 64 | |
| 65 std::vector<DownloadItem::ReceivedSlice> FindSlicesForRemainingContent( | 45 std::vector<DownloadItem::ReceivedSlice> FindSlicesForRemainingContent( |
| 66 int64_t current_offset, | 46 int64_t current_offset, |
| 67 int64_t total_length, | 47 int64_t total_length, |
| 68 int request_count, | 48 int request_count, |
| 69 int64_t min_slice_size) { | 49 int64_t min_slice_size) { |
| 70 std::vector<DownloadItem::ReceivedSlice> new_slices; | 50 std::vector<DownloadItem::ReceivedSlice> new_slices; |
| 71 | 51 |
| 72 if (request_count > 0) { | 52 if (request_count > 0) { |
| 73 int64_t slice_size = | 53 int64_t slice_size = |
| 74 std::max<int64_t>(total_length / request_count, min_slice_size); | 54 std::max<int64_t>(total_length / request_count, min_slice_size); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 143 |
| 164 void DebugSlicesInfo(const DownloadItem::ReceivedSlices& slices) { | 144 void DebugSlicesInfo(const DownloadItem::ReceivedSlices& slices) { |
| 165 DVLOG(1) << "Received slices size : " << slices.size(); | 145 DVLOG(1) << "Received slices size : " << slices.size(); |
| 166 for (const auto& it : slices) { | 146 for (const auto& it : slices) { |
| 167 DVLOG(1) << "Slice offset = " << it.offset | 147 DVLOG(1) << "Slice offset = " << it.offset |
| 168 << " , received_bytes = " << it.received_bytes; | 148 << " , received_bytes = " << it.received_bytes; |
| 169 } | 149 } |
| 170 } | 150 } |
| 171 | 151 |
| 172 } // namespace content | 152 } // namespace content |
| OLD | NEW |