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