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

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

Issue 2750853004: Add a delay to send the parallel requests. (Closed)
Patch Set: Work on nits. 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 unified diff | Download patch
« no previous file with comments | « content/browser/download/parallel_download_utils.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "content/public/browser/download_save_info.h" 10 #include "content/public/browser/download_save_info.h"
10 #include "content/public/common/content_features.h" 11 #include "content/public/common/content_features.h"
11 12
12 namespace content { 13 namespace content {
13 14
14 namespace { 15 namespace {
15 16
16 // Finch parameter key value for minimum slice size in bytes to use parallel 17 // Finch parameter key value for minimum slice size in bytes to use parallel
17 // download. 18 // download.
18 const char kMinSliceSizeFinchKey[] = "min_slice_size"; 19 const char kMinSliceSizeFinchKey[] = "min_slice_size";
19 20
20 // Default value for |kMinSliceSizeFinchKey|, when no parameter is specified. 21 // Default value for |kMinSliceSizeFinchKey|, when no parameter is specified.
21 const int64_t kMinSliceSizeParallelDownload = 2097152; 22 const int64_t kMinSliceSizeParallelDownload = 2097152;
22 23
23 // Finch parameter key value for number of parallel requests in a parallel 24 // Finch parameter key value for number of parallel requests in a parallel
24 // download, including the original request. 25 // download, including the original request.
25 const char kParallelRequestCountFinchKey[] = "request_count"; 26 const char kParallelRequestCountFinchKey[] = "request_count";
26 27
27 // Default value for |kParallelRequestCountFinchKey|, when no parameter is 28 // Default value for |kParallelRequestCountFinchKey|, when no parameter is
28 // specified. 29 // specified.
29 const int kParallelRequestCount = 2; 30 const int kParallelRequestCount = 2;
30 31
32 // Finch parameter key value for the delay time in milliseconds to send
33 // parallel requests after response of the original request is handled.
34 const char kParallelRequestDelayFinchKey[] = "parallel_request_delay";
35
31 // TODO(qinmin): replace this with a comparator operator in 36 // TODO(qinmin): replace this with a comparator operator in
32 // DownloadItem::ReceivedSlice. 37 // DownloadItem::ReceivedSlice.
33 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs, 38 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs,
34 const DownloadItem::ReceivedSlice& rhs) { 39 const DownloadItem::ReceivedSlice& rhs) {
35 return lhs.offset < rhs.offset; 40 return lhs.offset < rhs.offset;
36 } 41 }
37 42
38 } // namespace 43 } // namespace
39 44
40 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload( 45 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 88 }
84 89
85 it = received_slices.emplace(it, new_slice); 90 it = received_slices.emplace(it, new_slice);
86 return static_cast<size_t>(std::distance(received_slices.begin(), it)); 91 return static_cast<size_t>(std::distance(received_slices.begin(), it));
87 } 92 }
88 93
89 int64_t GetMinSliceSizeConfig() { 94 int64_t GetMinSliceSizeConfig() {
90 std::string finch_value = base::GetFieldTrialParamValueByFeature( 95 std::string finch_value = base::GetFieldTrialParamValueByFeature(
91 features::kParallelDownloading, kMinSliceSizeFinchKey); 96 features::kParallelDownloading, kMinSliceSizeFinchKey);
92 int64_t result; 97 int64_t result;
93 return !finch_value.empty() && base::StringToInt64(finch_value, &result) 98 return base::StringToInt64(finch_value, &result)
94 ? result 99 ? result
95 : kMinSliceSizeParallelDownload; 100 : kMinSliceSizeParallelDownload;
96 } 101 }
97 102
98 int GetParallelRequestCountConfig() { 103 int GetParallelRequestCountConfig() {
99 std::string finch_value = base::GetFieldTrialParamValueByFeature( 104 std::string finch_value = base::GetFieldTrialParamValueByFeature(
100 features::kParallelDownloading, kParallelRequestCountFinchKey); 105 features::kParallelDownloading, kParallelRequestCountFinchKey);
101 int result; 106 int result;
102 return !finch_value.empty() && base::StringToInt(finch_value, &result) 107 return base::StringToInt(finch_value, &result) ? result
103 ? result 108 : kParallelRequestCount;
104 : kParallelRequestCount; 109 }
110
111 base::TimeDelta GetParallelRequestDelayConfig() {
112 std::string finch_value = base::GetFieldTrialParamValueByFeature(
113 features::kParallelDownloading, kParallelRequestDelayFinchKey);
114 int64_t time_ms = 0;
115 return base::StringToInt64(finch_value, &time_ms)
116 ? base::TimeDelta::FromMilliseconds(time_ms)
117 : base::TimeDelta::FromMilliseconds(0);
105 } 118 }
106 119
107 } // namespace content 120 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/download/parallel_download_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698