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::Callback<void(bool*)>& cellular_callback) | |
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 cellular_callback_(cellular_callback) { | |
96 } | 99 } |
97 | 100 |
98 MetricsReportingScheduler::~MetricsReportingScheduler() {} | 101 MetricsReportingScheduler::~MetricsReportingScheduler() {} |
99 | 102 |
100 void MetricsReportingScheduler::Start() { | 103 void MetricsReportingScheduler::Start() { |
101 GetUploadIntervalFromExperiment(); | 104 GetUploadIntervalFromExperiment(); |
102 running_ = true; | 105 running_ = true; |
103 ScheduleNextUpload(); | 106 ScheduleNextUpload(); |
104 } | 107 } |
105 | 108 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 upload_interval_.InMicroseconds())); | 190 upload_interval_.InMicroseconds())); |
188 | 191 |
189 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); | 192 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); |
190 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { | 193 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { |
191 upload_interval_ = max_interval; | 194 upload_interval_ = max_interval; |
192 } | 195 } |
193 } | 196 } |
194 | 197 |
195 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { | 198 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { |
196 #if defined(OS_ANDROID) | 199 #if defined(OS_ANDROID) |
197 return GetUploadIntervalFromExperiment(); | 200 bool is_cellular = false; |
198 #else | 201 cellular_callback_.Run(&is_cellular); |
202 if (IsCellularEnabledByExperiment() && is_cellular) | |
Alexei Svitkine (slow)
2015/02/18 03:26:23
Nit: Reverse the order in the if, so we don't need
gayane -on leave until 09-2017
2015/02/18 21:38:23
Done.
| |
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 |