Index: components/download/internal/config.cc |
diff --git a/components/download/internal/config.cc b/components/download/internal/config.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..c1aa7fc78d87b51d286c3d12c957ae735b366a37 |
--- /dev/null |
+++ b/components/download/internal/config.cc |
@@ -0,0 +1,63 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/download/internal/config.h" |
+ |
+#include <string> |
+ |
+#include "base/metrics/field_trial_params.h" |
+#include "base/strings/string_number_conversions.h" |
+#include "components/download/public/features.h" |
+ |
+namespace download { |
+ |
+namespace { |
+ |
+// Default value for max concurrent downloads configuration. |
+const int kDefaultMaxConcurrentDownloads = 4; |
+ |
+// Default value for maximum running downloads of the download service. |
+const int kDefaultMaxRunningDownloads = 1; |
+ |
+// Default value for maximum scheduled downloads. |
+const int kDefaultMaxScheduledDownloads = 15; |
+ |
+// Default value for maximum retry count. |
+const int kDefaultMaxRetryCount = 5; |
+ |
+// Default value for file keep alive time in minutes, keep the file alive for |
+// 12 hours by default. |
+const int kDefaultFileKeepAliveTimeMinutes = 12 * 60; |
+ |
+// Helper routine to get Finch experiment parameter. If no Finch seed was found, |
+// use the |default_value|. The |name| should match an experiment |
+// parameter in Finch server configuration. |
+int GetFinchConfigInt(const std::string& name, int default_value) { |
+ std::string finch_value = |
+ base::GetFieldTrialParamValueByFeature(kDownloadServiceFeature, name); |
+ int result; |
+ return base::StringToInt(finch_value, &result) ? result : default_value; |
+} |
+ |
+// Helper routine to load Finch configurations. |
+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.
|
+ config->max_concurrent_downloads = GetFinchConfigInt( |
+ kMaxConcurrentDownloadsConfig, kDefaultMaxConcurrentDownloads); |
+ config->max_running_downloads = GetFinchConfigInt( |
+ kMaxRunningDownloadsConfig, kDefaultMaxRunningDownloads); |
+ config->max_scheduled_downloads = GetFinchConfigInt( |
+ kMaxScheduledDownloadsConfig, kDefaultMaxScheduledDownloads); |
+ config->max_retry_count = |
+ GetFinchConfigInt(kMaxRetryCountConfig, kDefaultMaxRetryCount); |
+ config->file_keep_alive_time = base::TimeDelta::FromMinutes(GetFinchConfigInt( |
+ kFileKeepAliveTimeMinutesConfig, kDefaultFileKeepAliveTimeMinutes)); |
+} |
+ |
+} // namespace |
+ |
+Configuration::Configuration() { |
+ LoadFinchConfigs(this); |
+} |
+ |
+} // namespace download |