| 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 25 matching lines...) Expand all Loading... |
| 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) { | 45 bool ShouldUseParallelDownload(const DownloadCreateInfo& create_info) { |
| 46 // To enable parallel download, following conditions need to be satisfied. |
| 46 // 1. Accept-Ranges, Content-Length and strong validators response headers. | 47 // 1. Accept-Ranges, Content-Length and strong validators response headers. |
| 47 // 2. Feature |kParallelDownloading| enabled. | 48 // 2. Feature |kParallelDownloading| enabled. |
| 48 // 3. Content-Length is no less than the minimum slice size configuration. | 49 // 3. Content-Length is no less than the minimum slice size configuration. |
| 49 // 3. TODO(xingliu) HTTP/1.1 protocol, not QUIC or HTTP/2. | 50 // 3. HTTP/1.1 protocol, not QUIC nor HTTP/1.0. |
| 50 | 51 |
| 51 // Etag and last modified are stored into DownloadCreateInfo in | 52 // Etag and last modified are stored into DownloadCreateInfo in |
| 52 // DownloadRequestCore only if the response header complies to the strong | 53 // DownloadRequestCore only if the response header complies to the strong |
| 53 // validator rule. | 54 // validator rule. |
| 54 bool has_strong_validator = | 55 bool has_strong_validator = |
| 55 !create_info.etag.empty() || !create_info.last_modified.empty(); | 56 !create_info.etag.empty() || !create_info.last_modified.empty(); |
| 56 | 57 |
| 57 return has_strong_validator && create_info.accept_range && | 58 return has_strong_validator && create_info.accept_range && |
| 58 create_info.total_bytes >= GetMinSliceSizeConfig() && | 59 create_info.total_bytes >= GetMinSliceSizeConfig() && |
| 60 create_info.connection_info == |
| 61 net::HttpResponseInfo::CONNECTION_INFO_HTTP1_1 && |
| 59 base::FeatureList::IsEnabled(features::kParallelDownloading); | 62 base::FeatureList::IsEnabled(features::kParallelDownloading); |
| 60 } | 63 } |
| 61 | 64 |
| 62 std::vector<DownloadItem::ReceivedSlice> FindSlicesForRemainingContent( | 65 std::vector<DownloadItem::ReceivedSlice> FindSlicesForRemainingContent( |
| 63 int64_t bytes_received, | 66 int64_t bytes_received, |
| 64 int64_t content_length, | 67 int64_t content_length, |
| 65 int request_count) { | 68 int request_count) { |
| 66 std::vector<DownloadItem::ReceivedSlice> slices_to_download; | 69 std::vector<DownloadItem::ReceivedSlice> slices_to_download; |
| 67 if (request_count <= 0) | 70 if (request_count <= 0) |
| 68 return slices_to_download; | 71 return slices_to_download; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 base::TimeDelta GetParallelRequestDelayConfig() { | 156 base::TimeDelta GetParallelRequestDelayConfig() { |
| 154 std::string finch_value = base::GetFieldTrialParamValueByFeature( | 157 std::string finch_value = base::GetFieldTrialParamValueByFeature( |
| 155 features::kParallelDownloading, kParallelRequestDelayFinchKey); | 158 features::kParallelDownloading, kParallelRequestDelayFinchKey); |
| 156 int64_t time_ms = 0; | 159 int64_t time_ms = 0; |
| 157 return base::StringToInt64(finch_value, &time_ms) | 160 return base::StringToInt64(finch_value, &time_ms) |
| 158 ? base::TimeDelta::FromMilliseconds(time_ms) | 161 ? base::TimeDelta::FromMilliseconds(time_ms) |
| 159 : base::TimeDelta::FromMilliseconds(0); | 162 : base::TimeDelta::FromMilliseconds(0); |
| 160 } | 163 } |
| 161 | 164 |
| 162 } // namespace content | 165 } // namespace content |
| OLD | NEW |