Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/download/internal/config.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/metrics/field_trial_params.h" | |
| 10 #include "base/strings/string_number_conversions.h" | |
| 11 #include "components/download/public/features.h" | |
| 12 | |
| 13 namespace download { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 // Default value for max concurrent downloads configuration. | |
| 18 const int kDefaultMaxConcurrentDownloads = 4; | |
| 19 | |
| 20 // Default value for maximum running downloads of the download service. | |
| 21 const int kDefaultMaxRunningDownloads = 1; | |
| 22 | |
| 23 // Default value for maximum scheduled downloads. | |
| 24 const int kDefaultMaxScheduledDownloads = 15; | |
| 25 | |
| 26 // Default value for maximum retry count. | |
| 27 const int kDefaultMaxRetryCount = 5; | |
| 28 | |
| 29 // Default value for file keep alive time in minutes, keep the file alive for | |
| 30 // 12 hours by default. | |
| 31 const int kDefaultFileKeepAliveTimeMinutes = 12 * 60; | |
| 32 | |
| 33 // Helper routine to get Finch experiment parameter. If no Finch seed was found, | |
| 34 // use the |default_value|. The |name| should match an experiment | |
| 35 // parameter in Finch server configuration. | |
| 36 int GetFinchConfigInt(const std::string& name, int default_value) { | |
| 37 std::string finch_value = | |
| 38 base::GetFieldTrialParamValueByFeature(kDownloadServiceFeature, name); | |
| 39 int result; | |
| 40 return base::StringToInt(finch_value, &result) ? result : default_value; | |
| 41 } | |
| 42 | |
| 43 // Helper routine to load Finch configurations. | |
| 44 void LoadFinchConfigs(Configuration* config) { | |
|
David Trainor- moved to gerrit
2017/05/05 20:10:52
Can we do something like make this static and make
xingliu
2017/05/05 22:55:03
Done.
| |
| 45 config->max_concurrent_downloads = GetFinchConfigInt( | |
| 46 kMaxConcurrentDownloadsConfig, kDefaultMaxConcurrentDownloads); | |
| 47 config->max_running_downloads = GetFinchConfigInt( | |
| 48 kMaxRunningDownloadsConfig, kDefaultMaxRunningDownloads); | |
| 49 config->max_scheduled_downloads = GetFinchConfigInt( | |
| 50 kMaxScheduledDownloadsConfig, kDefaultMaxScheduledDownloads); | |
| 51 config->max_retry_count = | |
| 52 GetFinchConfigInt(kMaxRetryCountConfig, kDefaultMaxRetryCount); | |
| 53 config->file_keep_alive_time = base::TimeDelta::FromMinutes(GetFinchConfigInt( | |
| 54 kFileKeepAliveTimeMinutesConfig, kDefaultFileKeepAliveTimeMinutes)); | |
| 55 } | |
| 56 | |
| 57 } // namespace | |
| 58 | |
| 59 Configuration::Configuration() { | |
| 60 LoadFinchConfigs(this); | |
| 61 } | |
| 62 | |
| 63 } // namespace download | |
| OLD | NEW |