OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/metrics/metrics_reporting_scheduler.h" | 5 #include "components/metrics/metrics_reporting_scheduler.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/metrics/field_trial.h" | 8 #include "base/metrics/field_trial.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Sending in a burst is better on a mobile device, since keeping the radio on | 31 // Sending in a burst is better on a mobile device, since keeping the radio on |
32 // is very expensive. | 32 // is very expensive. |
33 const int kUnsentLogsIntervalSeconds = 3; | 33 const int kUnsentLogsIntervalSeconds = 3; |
34 #else | 34 #else |
35 const int kUnsentLogsIntervalSeconds = 15; | 35 const int kUnsentLogsIntervalSeconds = 15; |
36 #endif | 36 #endif |
37 | 37 |
38 // Standard interval between log uploads, in seconds. | 38 // Standard interval between log uploads, in seconds. |
39 #if defined(OS_ANDROID) || defined(OS_IOS) | 39 #if defined(OS_ANDROID) || defined(OS_IOS) |
40 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. | 40 const int kStandardUploadIntervalSeconds = 5 * 60; // Five minutes. |
| 41 const int kStandardUploadIntervalCellularSeconds = 15 * 60; // Fifteen minutes. |
41 #else | 42 #else |
42 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. | 43 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. |
43 #endif | 44 #endif |
44 | 45 |
45 // When uploading metrics to the server fails, we progressively wait longer and | 46 // When uploading metrics to the server fails, we progressively wait longer and |
46 // longer before sending the next log. This backoff process helps reduce load | 47 // longer before sending the next log. This backoff process helps reduce load |
47 // on a server that is having issues. | 48 // on a server that is having issues. |
48 // The following is the multiplier we use to expand that inter-log duration. | 49 // The following is the multiplier we use to expand that inter-log duration. |
49 const double kBackoffMultiplier = 1.1; | 50 const double kBackoffMultiplier = 1.1; |
50 | 51 |
(...skipping 28 matching lines...) Expand all Loading... |
79 int interval; | 80 int interval; |
80 if (interval_str.empty() || !base::StringToInt(interval_str, &interval)) | 81 if (interval_str.empty() || !base::StringToInt(interval_str, &interval)) |
81 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | 82 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); |
82 | 83 |
83 return TimeDelta::FromMinutes(interval); | 84 return TimeDelta::FromMinutes(interval); |
84 } | 85 } |
85 | 86 |
86 } // anonymous namespace | 87 } // anonymous namespace |
87 | 88 |
88 MetricsReportingScheduler::MetricsReportingScheduler( | 89 MetricsReportingScheduler::MetricsReportingScheduler( |
89 const base::Closure& upload_callback) | 90 const base::Closure& upload_callback, |
| 91 const base::Closure& update_connection_type_func) |
90 : upload_callback_(upload_callback), | 92 : upload_callback_(upload_callback), |
91 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), | 93 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), |
92 running_(false), | 94 running_(false), |
93 callback_pending_(false), | 95 callback_pending_(false), |
94 init_task_complete_(false), | 96 init_task_complete_(false), |
95 waiting_for_init_task_complete_(false) { | 97 waiting_for_init_task_complete_(false), |
| 98 update_connection_type_func_(update_connection_type_func), |
| 99 is_cellular_connection_(true) { |
96 } | 100 } |
97 | 101 |
98 MetricsReportingScheduler::~MetricsReportingScheduler() {} | 102 MetricsReportingScheduler::~MetricsReportingScheduler() {} |
99 | 103 |
100 void MetricsReportingScheduler::Start() { | 104 void MetricsReportingScheduler::Start() { |
101 GetUploadIntervalFromExperiment(); | 105 GetUploadIntervalFromExperiment(); |
102 running_ = true; | 106 running_ = true; |
103 ScheduleNextUpload(); | 107 ScheduleNextUpload(); |
104 } | 108 } |
105 | 109 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 upload_interval_.InMicroseconds())); | 191 upload_interval_.InMicroseconds())); |
188 | 192 |
189 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); | 193 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); |
190 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { | 194 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { |
191 upload_interval_ = max_interval; | 195 upload_interval_ = max_interval; |
192 } | 196 } |
193 } | 197 } |
194 | 198 |
195 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { | 199 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { |
196 #if defined(OS_ANDROID) | 200 #if defined(OS_ANDROID) |
197 return GetUploadIntervalFromExperiment(); | 201 update_connection_type_func_.Run(); |
198 #else | 202 if (IsCellularEnabledByExperiment() && is_cellular_connection_) |
| 203 return TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds); |
| 204 #endif |
199 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | 205 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); |
200 #endif | 206 } |
| 207 |
| 208 void MetricsReportingScheduler::SetConnectionType(bool is_cellular) { |
| 209 is_cellular_connection_ = is_cellular; |
| 210 } |
| 211 |
| 212 bool MetricsReportingScheduler::IsCellularEnabledByExperiment() { |
| 213 const std::string group_name = |
| 214 base::FieldTrialList::FindFullName("UMA_EnableCellularLogUpload"); |
| 215 return group_name == "Enabled"; |
201 } | 216 } |
202 | 217 |
203 } // namespace metrics | 218 } // namespace metrics |
OLD | NEW |