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

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

Issue 2750853004: Add a delay to send the parallel requests. (Closed)
Patch Set: 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
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
36 // Default value for parallel request delay.
37 const base::TimeDelta kParallelRequestDelay =
qinmin 2017/03/15 05:49:18 move this inside GetParallelRequestDelayConfig(),
xingliu 2017/03/15 17:48:52 Done.
38 base::TimeDelta::FromMilliseconds(0);
39
31 // TODO(qinmin): replace this with a comparator operator in 40 // TODO(qinmin): replace this with a comparator operator in
32 // DownloadItem::ReceivedSlice. 41 // DownloadItem::ReceivedSlice.
33 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs, 42 bool compareReceivedSlices(const DownloadItem::ReceivedSlice& lhs,
34 const DownloadItem::ReceivedSlice& rhs) { 43 const DownloadItem::ReceivedSlice& rhs) {
35 return lhs.offset < rhs.offset; 44 return lhs.offset < rhs.offset;
36 } 45 }
37 46
38 } // namespace 47 } // namespace
39 48
40 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload( 49 std::vector<DownloadItem::ReceivedSlice> FindSlicesToDownload(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 106
98 int GetParallelRequestCountConfig() { 107 int GetParallelRequestCountConfig() {
99 std::string finch_value = base::GetFieldTrialParamValueByFeature( 108 std::string finch_value = base::GetFieldTrialParamValueByFeature(
100 features::kParallelDownloading, kParallelRequestCountFinchKey); 109 features::kParallelDownloading, kParallelRequestCountFinchKey);
101 int result; 110 int result;
102 return !finch_value.empty() && base::StringToInt(finch_value, &result) 111 return !finch_value.empty() && base::StringToInt(finch_value, &result)
103 ? result 112 ? result
104 : kParallelRequestCount; 113 : kParallelRequestCount;
105 } 114 }
106 115
116 base::TimeDelta GetParallelRequestDelayConfig() {
117 std::string finch_value = base::GetFieldTrialParamValueByFeature(
118 features::kParallelDownloading, kParallelRequestDelayFinchKey);
119 int64_t time_ms = 0;
120 return !finch_value.empty() && base::StringToInt64(finch_value, &time_ms)
David Trainor- moved to gerrit 2017/03/15 03:47:38 base::StringToInt64 will return false if you pass
xingliu 2017/03/15 17:48:52 Done, oh, i see, removed !finch_value.empty().
121 ? base::TimeDelta::FromMilliseconds(time_ms)
122 : kParallelRequestDelay;
123 }
124
107 } // namespace content 125 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698