File: config.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (177 lines) | stat: -rw-r--r-- 8,361 bytes parent folder | download | duplicates (11)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/download/internal/background_service/config.h"

#include <string>

#include "base/metrics/field_trial_params.h"
#include "base/numerics/clamped_math.h"
#include "base/strings/string_number_conversions.h"
#include "build/build_config.h"
#include "components/download/public/background_service/features.h"

namespace download {

namespace {

// Default value for battery query interval.
const base::TimeDelta kDefaultBatteryQueryInterval = base::Seconds(120);

// Default minimum battery percentage to start download or background task when
// battery requirement is sensitive.
const uint32_t kDefaultDownloadBatteryPercentage = 50;

// Default value for max concurrent downloads configuration.
const uint32_t kDefaultMaxConcurrentDownloads = 4;

// Default value for maximum running downloads of the download service.
const uint32_t kDefaultMaxRunningDownloads = 2;

// Default value for maximum scheduled downloads.
const uint32_t kDefaultMaxScheduledDownloads = 15;

// Default value for maximum retry count.
const uint32_t kDefaultMaxRetryCount = 5;

// Default value for maximum resumption count.
const uint32_t kDefaultMaxResumptionCount = 15;

// Default value for file keep alive time, keep the file alive for 12 hours by
// default.
const base::TimeDelta kDefaultFileKeepAliveTime = base::Hours(12);

// Default value for maximum duration that the file can be kept alive time,
// default is 7 days.
const base::TimeDelta kDefaultMaxFileKeepAliveTime = base::Days(7);

// Default value for file cleanup window, the system will schedule a cleanup
// task within this window.
const base::TimeDelta kDefaultFileCleanupWindow = base::Hours(24);

// Default value for the start window time for OS to schedule background task.
const base::TimeDelta kDefaultWindowStartTime = base::Minutes(5);

// Default value for the end window time for OS to schedule background task.
const base::TimeDelta kDefaultWindowEndTime = base::Hours(8);

// Default value for start up delay to wait for network stack ready.
const base::TimeDelta kDefaultNetworkStartupDelay = base::Seconds(2);

// Default value for start up delay to wait for network stack ready when
// triggered from a background task.
const base::TimeDelta kDefaultNetworkStartupDelayBackgroundTask =
    base::Seconds(5);

// The default delay to notify the observer when network changes from
// disconnected to connected.
const base::TimeDelta kDefaultNetworkChangeDelay = base::Seconds(5);

// The default delay to notify the observer after a navigation completes.
const base::TimeDelta kDefaultNavigationCompletionDelay = base::Seconds(30);

// The default timeout for a navigation.
const base::TimeDelta kDefaultNavigationTimeoutDelay = base::Seconds(300);

// The default timeout for a pending upload.
const base::TimeDelta kDefaultPendingUploadTimeoutDelay = base::Seconds(30);

// The default value of download retry delay when the download is failed.
const base::TimeDelta kDefaultDownloadRetryDelay = base::Seconds(20);

// 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.
uint32_t GetFinchConfigUInt(const std::string& name, uint32_t default_value) {
  std::string finch_value =
      base::GetFieldTrialParamValueByFeature(kDownloadServiceFeature, name);
  uint32_t result;
  return base::StringToUint(finch_value, &result) ? result : default_value;
}

}  // namespace

// static
std::unique_ptr<Configuration> Configuration::CreateFromFinch() {
  std::unique_ptr<Configuration> config(new Configuration());
  config->battery_query_interval = base::Seconds(base::saturated_cast<int>(
      GetFinchConfigUInt(kBatteryQueryIntervalConfig,
                         kDefaultBatteryQueryInterval.InSeconds())));
  config->download_battery_percentage =
      base::saturated_cast<int>(GetFinchConfigUInt(
          kDownloadBatteryPercentageConfig, kDefaultDownloadBatteryPercentage));
  config->max_concurrent_downloads = GetFinchConfigUInt(
      kMaxConcurrentDownloadsConfig, kDefaultMaxConcurrentDownloads);
  config->max_running_downloads = GetFinchConfigUInt(
      kMaxRunningDownloadsConfig, kDefaultMaxRunningDownloads);
  config->max_scheduled_downloads = GetFinchConfigUInt(
      kMaxScheduledDownloadsConfig, kDefaultMaxScheduledDownloads);
  config->max_retry_count =
      GetFinchConfigUInt(kMaxRetryCountConfig, kDefaultMaxRetryCount);
  config->max_resumption_count =
      GetFinchConfigUInt(kMaxResumptionCountConfig, kDefaultMaxResumptionCount);
  config->file_keep_alive_time = base::Minutes(base::saturated_cast<int>(
      GetFinchConfigUInt(kFileKeepAliveTimeMinutesConfig,
                         kDefaultFileKeepAliveTime.InMinutes())));
  config->max_file_keep_alive_time = base::Minutes(base::saturated_cast<int>(
      GetFinchConfigUInt(kMaxFileKeepAliveTimeMinutesConfig,
                         kDefaultMaxFileKeepAliveTime.InMinutes())));
  config->file_cleanup_window = base::Minutes(base::saturated_cast<int>(
      GetFinchConfigUInt(kFileCleanupWindowMinutesConfig,
                         kDefaultFileCleanupWindow.InMinutes())));
  config->window_start_time =
      base::Seconds(base::saturated_cast<int>(GetFinchConfigUInt(
          kWindowStartTimeSecondsConfig, kDefaultWindowStartTime.InSeconds())));
  config->window_end_time =
      base::Seconds(base::saturated_cast<int>(GetFinchConfigUInt(
          kWindowEndTimeSecondsConfig, kDefaultWindowEndTime.InSeconds())));
  config->network_startup_delay = base::Milliseconds(base::saturated_cast<int>(
      GetFinchConfigUInt(kNetworkStartupDelayMsConfig,
                         kDefaultNetworkStartupDelay.InMilliseconds())));
  config->network_startup_delay_backgroud_task =
      base::Milliseconds(base::saturated_cast<int>(GetFinchConfigUInt(
          kNetworkStartupDelayBackgroundTaskMsConfig,
          kDefaultNetworkStartupDelayBackgroundTask.InMilliseconds())));

  config->network_change_delay = base::Milliseconds(base::saturated_cast<int>(
      GetFinchConfigUInt(kNetworkChangeDelayMsConfig,
                         kDefaultNetworkChangeDelay.InMilliseconds())));
  config->navigation_completion_delay = base::Seconds(base::saturated_cast<int>(
      GetFinchConfigUInt(kNavigationCompletionDelaySecondsConfig,
                         kDefaultNavigationCompletionDelay.InSeconds())));
  config->navigation_timeout_delay = base::Seconds(base::saturated_cast<int>(
      GetFinchConfigUInt(kNavigationTimeoutDelaySecondsConfig,
                         kDefaultNavigationTimeoutDelay.InSeconds())));
  config->pending_upload_timeout_delay =
      base::Seconds(base::saturated_cast<int>(
          GetFinchConfigUInt(kPendingUploadTimeoutDelaySecondsConfig,
                             kDefaultPendingUploadTimeoutDelay.InSeconds())));

  config->download_retry_delay = base::Milliseconds(base::saturated_cast<int>(
      GetFinchConfigUInt(kDownloadRetryDelayMsConfig,
                         kDefaultDownloadRetryDelay.InMilliseconds())));
  return config;
}

Configuration::Configuration()
    : battery_query_interval(kDefaultBatteryQueryInterval),
      download_battery_percentage(kDefaultDownloadBatteryPercentage),
      max_concurrent_downloads(kDefaultMaxConcurrentDownloads),
      max_running_downloads(kDefaultMaxRunningDownloads),
      max_scheduled_downloads(kDefaultMaxScheduledDownloads),
      max_retry_count(kDefaultMaxRetryCount),
      max_resumption_count(kDefaultMaxResumptionCount),
      file_keep_alive_time(kDefaultFileKeepAliveTime),
      max_file_keep_alive_time(kDefaultMaxFileKeepAliveTime),
      file_cleanup_window(kDefaultFileCleanupWindow),
      window_start_time(kDefaultWindowStartTime),
      window_end_time(kDefaultWindowEndTime),
      network_startup_delay(kDefaultNetworkStartupDelay),
      network_change_delay(kDefaultNetworkChangeDelay),
      navigation_completion_delay(kDefaultNavigationCompletionDelay),
      navigation_timeout_delay(kDefaultNavigationTimeoutDelay),
      pending_upload_timeout_delay(kDefaultPendingUploadTimeoutDelay),
      download_retry_delay(kDefaultDownloadRetryDelay) {}

}  // namespace download