| 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" |
| 8 #include "base/strings/string_number_conversions.h" |
| 7 #include "content/public/browser/download_save_info.h" | 9 #include "content/public/browser/download_save_info.h" |
| 10 #include "content/public/common/content_features.h" |
| 8 | 11 |
| 9 namespace content { | 12 namespace content { |
| 10 | 13 |
| 14 namespace { |
| 15 |
| 16 // Finch parameter key value for minimum slice size in bytes to use parallel |
| 17 // download. |
| 18 const char kMinSliceSizeFinchKey[] = "min_slice_size"; |
| 19 |
| 20 // Default value for |kMinSliceSizeFinchKey|, when no parameter is specified. |
| 21 const int64_t kMinSliceSizeParallelDownload = 2097152; |
| 22 |
| 23 // Finch parameter key value for number of parallel requests in a parallel |
| 24 // download, including the original request. |
| 25 const char kParallelRequestCountFinchKey[] = "request_count"; |
| 26 |
| 27 // Default value for |kParallelRequestCountFinchKey|, when no parameter is |
| 28 // specified. |
| 29 const int kParallelRequestCount = 2; |
| 30 |
| 31 } // namespace |
| 32 |
| 11 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload( | 33 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload( |
| 12 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { | 34 const std::vector<DownloadItem::ReceivedSlice>& received_slices) { |
| 13 std::vector<DownloadItem::ReceivedSlice> result; | 35 std::vector<DownloadItem::ReceivedSlice> result; |
| 14 if (received_slices.empty()) { | 36 if (received_slices.empty()) { |
| 15 result.emplace_back(0, DownloadSaveInfo::kLengthFullContent); | 37 result.emplace_back(0, DownloadSaveInfo::kLengthFullContent); |
| 16 return result; | 38 return result; |
| 17 } | 39 } |
| 18 | 40 |
| 19 std::vector<DownloadItem::ReceivedSlice>::const_iterator iter = | 41 std::vector<DownloadItem::ReceivedSlice>::const_iterator iter = |
| 20 received_slices.begin(); | 42 received_slices.begin(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 } | 54 } |
| 33 | 55 |
| 34 DCHECK_GE(next->offset, offset); | 56 DCHECK_GE(next->offset, offset); |
| 35 if (next->offset > offset) | 57 if (next->offset > offset) |
| 36 result.emplace_back(offset, next->offset - offset); | 58 result.emplace_back(offset, next->offset - offset); |
| 37 iter = next; | 59 iter = next; |
| 38 } | 60 } |
| 39 return result; | 61 return result; |
| 40 } | 62 } |
| 41 | 63 |
| 64 int64_t GetMinSliceSizeConfig() { |
| 65 std::string finch_value = base::GetFieldTrialParamValueByFeature( |
| 66 features::kParallelDownloading, kMinSliceSizeFinchKey); |
| 67 int64_t result; |
| 68 return !finch_value.empty() && base::StringToInt64(finch_value, &result) |
| 69 ? result |
| 70 : kMinSliceSizeParallelDownload; |
| 71 } |
| 72 |
| 73 int GetParallelRequestCountConfig() { |
| 74 std::string finch_value = base::GetFieldTrialParamValueByFeature( |
| 75 features::kParallelDownloading, kParallelRequestCountFinchKey); |
| 76 int result; |
| 77 return !finch_value.empty() && base::StringToInt(finch_value, &result) |
| 78 ? result |
| 79 : kParallelRequestCount; |
| 80 } |
| 81 |
| 42 } // namespace content | 82 } // namespace content |
| OLD | NEW |