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; // Five 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 upload_interval_.InMicroseconds())); | 188 upload_interval_.InMicroseconds())); |
188 | 189 |
189 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); | 190 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); |
190 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { | 191 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { |
191 upload_interval_ = max_interval; | 192 upload_interval_ = max_interval; |
192 } | 193 } |
193 } | 194 } |
194 | 195 |
195 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { | 196 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { |
196 #if defined(OS_ANDROID) | 197 #if defined(OS_ANDROID) |
197 return GetUploadIntervalFromExperiment(); | 198 if (IsCellularEnabledByExperiment() && IsCellularConnection()) |
198 #else | 199 return TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds); |
| 200 #endif |
199 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | 201 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); |
200 #endif | 202 } |
| 203 |
| 204 void MetricsReportingScheduler::SetNetworkMetricsProvider( |
| 205 const metrics::NetworkMetricsProvider* network_metrics_provider) { |
| 206 network_metrics_provider_= network_metrics_provider; |
| 207 } |
| 208 |
| 209 bool MetricsReportingScheduler::IsCellularConnection() { |
| 210 SystemProfileProto::Network::ConnectionType connection_type = |
| 211 network_metrics_provider_->GetConnectionType(); |
| 212 |
| 213 switch (connection_type) { |
| 214 case SystemProfileProto_Network_ConnectionType_CONNECTION_2G: |
| 215 case SystemProfileProto_Network_ConnectionType_CONNECTION_3G: |
| 216 case SystemProfileProto_Network_ConnectionType_CONNECTION_4G: |
| 217 return true; |
| 218 default: |
| 219 return false; |
| 220 } |
| 221 } |
| 222 |
| 223 bool MetricsReportingScheduler::IsCellularEnabledByExperiment() { |
| 224 const std::string group_name = |
| 225 base::FieldTrialList::FindFullName("UMA_EnableCellularLogUpload"); |
| 226 return group_name == "Enabled"; |
201 } | 227 } |
202 | 228 |
203 } // namespace metrics | 229 } // namespace metrics |
OLD | NEW |