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

Side by Side Diff: components/download/internal/config.cc

Issue 2895953004: Add initial Controller to DownloadService (Closed)
Patch Set: Rebased Created 3 years, 6 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 | « components/download/internal/config.h ('k') | components/download/internal/controller.h » ('j') | 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 "components/download/internal/config.h" 5 #include "components/download/internal/config.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/metrics/field_trial_params.h" 10 #include "base/metrics/field_trial_params.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "components/download/public/features.h" 12 #include "components/download/public/features.h"
13 13
14 namespace download { 14 namespace download {
15 15
16 namespace { 16 namespace {
17 17
18 // Default value for max concurrent downloads configuration. 18 // Default value for max concurrent downloads configuration.
19 const int kDefaultMaxConcurrentDownloads = 4; 19 const uint32_t kDefaultMaxConcurrentDownloads = 4;
20 20
21 // Default value for maximum running downloads of the download service. 21 // Default value for maximum running downloads of the download service.
22 const int kDefaultMaxRunningDownloads = 1; 22 const uint32_t kDefaultMaxRunningDownloads = 1;
23 23
24 // Default value for maximum scheduled downloads. 24 // Default value for maximum scheduled downloads.
25 const int kDefaultMaxScheduledDownloads = 15; 25 const uint32_t kDefaultMaxScheduledDownloads = 15;
26 26
27 // Default value for maximum retry count. 27 // Default value for maximum retry count.
28 const int kDefaultMaxRetryCount = 5; 28 const uint32_t kDefaultMaxRetryCount = 5;
29 29
30 // Default value for file keep alive time in minutes, keep the file alive for 30 // Default value for file keep alive time in minutes, keep the file alive for
31 // 12 hours by default. 31 // 12 hours by default.
32 const int kDefaultFileKeepAliveTimeMinutes = 12 * 60; 32 const uint32_t kDefaultFileKeepAliveTimeMinutes = 12 * 60;
33 33
34 // Helper routine to get Finch experiment parameter. If no Finch seed was found, 34 // Helper routine to get Finch experiment parameter. If no Finch seed was found,
35 // use the |default_value|. The |name| should match an experiment 35 // use the |default_value|. The |name| should match an experiment
36 // parameter in Finch server configuration. 36 // parameter in Finch server configuration.
37 int GetFinchConfigInt(const std::string& name, int default_value) { 37 uint32_t GetFinchConfigUInt(const std::string& name, uint32_t default_value) {
38 std::string finch_value = 38 std::string finch_value =
39 base::GetFieldTrialParamValueByFeature(kDownloadServiceFeature, name); 39 base::GetFieldTrialParamValueByFeature(kDownloadServiceFeature, name);
40 int result; 40 uint32_t result;
41 return base::StringToInt(finch_value, &result) ? result : default_value; 41 return base::StringToUint(finch_value, &result) ? result : default_value;
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46 // static 46 // static
47 std::unique_ptr<Configuration> Configuration::CreateFromFinch() { 47 std::unique_ptr<Configuration> Configuration::CreateFromFinch() {
48 std::unique_ptr<Configuration> config(new Configuration()); 48 std::unique_ptr<Configuration> config(new Configuration());
49 config->max_concurrent_downloads = GetFinchConfigInt( 49 config->max_concurrent_downloads = GetFinchConfigUInt(
50 kMaxConcurrentDownloadsConfig, kDefaultMaxConcurrentDownloads); 50 kMaxConcurrentDownloadsConfig, kDefaultMaxConcurrentDownloads);
51 config->max_running_downloads = GetFinchConfigInt( 51 config->max_running_downloads = GetFinchConfigUInt(
52 kMaxRunningDownloadsConfig, kDefaultMaxRunningDownloads); 52 kMaxRunningDownloadsConfig, kDefaultMaxRunningDownloads);
53 config->max_scheduled_downloads = GetFinchConfigInt( 53 config->max_scheduled_downloads = GetFinchConfigUInt(
54 kMaxScheduledDownloadsConfig, kDefaultMaxScheduledDownloads); 54 kMaxScheduledDownloadsConfig, kDefaultMaxScheduledDownloads);
55 config->max_retry_count = 55 config->max_retry_count =
56 GetFinchConfigInt(kMaxRetryCountConfig, kDefaultMaxRetryCount); 56 GetFinchConfigUInt(kMaxRetryCountConfig, kDefaultMaxRetryCount);
57 config->file_keep_alive_time = base::TimeDelta::FromMinutes(GetFinchConfigInt( 57 config->file_keep_alive_time =
58 kFileKeepAliveTimeMinutesConfig, kDefaultFileKeepAliveTimeMinutes)); 58 base::TimeDelta::FromMinutes(base::saturated_cast<int>(GetFinchConfigUInt(
59 kFileKeepAliveTimeMinutesConfig, kDefaultFileKeepAliveTimeMinutes)));
59 return config; 60 return config;
60 } 61 }
61 62
62 Configuration::Configuration() 63 Configuration::Configuration()
63 : max_concurrent_downloads(kDefaultMaxConcurrentDownloads), 64 : max_concurrent_downloads(kDefaultMaxConcurrentDownloads),
64 max_running_downloads(kDefaultMaxRunningDownloads), 65 max_running_downloads(kDefaultMaxRunningDownloads),
65 max_scheduled_downloads(kDefaultMaxScheduledDownloads), 66 max_scheduled_downloads(kDefaultMaxScheduledDownloads),
66 max_retry_count(kDefaultMaxRetryCount), 67 max_retry_count(kDefaultMaxRetryCount),
67 file_keep_alive_time( 68 file_keep_alive_time(base::TimeDelta::FromMinutes(
68 base::TimeDelta::FromMinutes(kDefaultFileKeepAliveTimeMinutes)) {} 69 base::saturated_cast<int>(kDefaultFileKeepAliveTimeMinutes))) {}
69 70
70 } // namespace download 71 } // namespace download
OLDNEW
« no previous file with comments | « components/download/internal/config.h ('k') | components/download/internal/controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698