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 25 matching lines...) Expand all Loading... |
76 base::TimeDelta GetUploadIntervalFromExperiment() { | 77 base::TimeDelta GetUploadIntervalFromExperiment() { |
77 std::string interval_str = variations::GetVariationParamValue( | 78 std::string interval_str = variations::GetVariationParamValue( |
78 "UMALogUploadInterval", "interval"); | 79 "UMALogUploadInterval", "interval"); |
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 |
| 87 // Returns true if the user is assigned to the experiment group for enabled |
| 88 // cellular uploads. |
| 89 bool IsCellularEnabledByExperiment() { |
| 90 const std::string group_name = |
| 91 base::FieldTrialList::FindFullName("UMA_EnableCellularLogUpload"); |
| 92 return group_name == "Enabled"; |
| 93 } |
| 94 |
86 } // anonymous namespace | 95 } // anonymous namespace |
87 | 96 |
88 MetricsReportingScheduler::MetricsReportingScheduler( | 97 MetricsReportingScheduler::MetricsReportingScheduler( |
89 const base::Closure& upload_callback) | 98 const base::Closure& upload_callback, |
| 99 const base::Callback<void(bool*)>& cellular_callback) |
90 : upload_callback_(upload_callback), | 100 : upload_callback_(upload_callback), |
91 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), | 101 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), |
92 running_(false), | 102 running_(false), |
93 callback_pending_(false), | 103 callback_pending_(false), |
94 init_task_complete_(false), | 104 init_task_complete_(false), |
95 waiting_for_init_task_complete_(false) { | 105 waiting_for_init_task_complete_(false), |
| 106 cellular_callback_(cellular_callback) { |
96 } | 107 } |
97 | 108 |
98 MetricsReportingScheduler::~MetricsReportingScheduler() {} | 109 MetricsReportingScheduler::~MetricsReportingScheduler() {} |
99 | 110 |
100 void MetricsReportingScheduler::Start() { | 111 void MetricsReportingScheduler::Start() { |
101 GetUploadIntervalFromExperiment(); | 112 GetUploadIntervalFromExperiment(); |
102 running_ = true; | 113 running_ = true; |
103 ScheduleNextUpload(); | 114 ScheduleNextUpload(); |
104 } | 115 } |
105 | 116 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 upload_interval_.InMicroseconds())); | 198 upload_interval_.InMicroseconds())); |
188 | 199 |
189 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); | 200 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); |
190 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { | 201 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { |
191 upload_interval_ = max_interval; | 202 upload_interval_ = max_interval; |
192 } | 203 } |
193 } | 204 } |
194 | 205 |
195 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { | 206 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { |
196 #if defined(OS_ANDROID) | 207 #if defined(OS_ANDROID) |
197 return GetUploadIntervalFromExperiment(); | 208 bool is_cellular = false; |
198 #else | 209 cellular_callback_.Run(&is_cellular); |
| 210 if (is_cellular && IsCellularEnabledByExperiment()) |
| 211 return TimeDelta::FromSeconds(kStandardUploadIntervalCellularSeconds); |
| 212 #endif |
199 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); | 213 return TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); |
200 #endif | 214 } |
| 215 |
| 216 void MetricsReportingScheduler::SetConnectionType(bool is_cellular) { |
| 217 is_cellular_connection_ = is_cellular; |
201 } | 218 } |
202 | 219 |
203 } // namespace metrics | 220 } // namespace metrics |
OLD | NEW |