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

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

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

Powered by Google App Engine
This is Rietveld 408576698