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/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
10 #include "components/variations/variations_associated_data.h" | 10 #include "components/variations/variations_associated_data.h" |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 running_(false), | 72 running_(false), |
73 callback_pending_(false), | 73 callback_pending_(false), |
74 init_task_complete_(false), | 74 init_task_complete_(false), |
75 waiting_for_init_task_complete_(false), | 75 waiting_for_init_task_complete_(false), |
76 upload_interval_callback_(upload_interval_callback) { | 76 upload_interval_callback_(upload_interval_callback) { |
77 } | 77 } |
78 | 78 |
79 MetricsReportingScheduler::~MetricsReportingScheduler() {} | 79 MetricsReportingScheduler::~MetricsReportingScheduler() {} |
80 | 80 |
81 void MetricsReportingScheduler::Start() { | 81 void MetricsReportingScheduler::Start() { |
| 82 LOG(WARNING) << "metrix MetricsReportingScheduler::Start"; |
82 running_ = true; | 83 running_ = true; |
83 ScheduleNextUpload(); | 84 ScheduleNextUpload(); |
84 } | 85 } |
85 | 86 |
86 void MetricsReportingScheduler::Stop() { | 87 void MetricsReportingScheduler::Stop() { |
| 88 LOG(WARNING) << "metrix MetricsReportingScheduler::Stop"; |
87 running_ = false; | 89 running_ = false; |
88 if (upload_timer_.IsRunning()) | 90 if (upload_timer_.IsRunning()) |
89 upload_timer_.Stop(); | 91 upload_timer_.Stop(); |
90 } | 92 } |
91 | 93 |
92 // Callback from MetricsService when the startup init task has completed. | 94 // Callback from MetricsService when the startup init task has completed. |
93 void MetricsReportingScheduler::InitTaskComplete() { | 95 void MetricsReportingScheduler::InitTaskComplete() { |
94 DCHECK(!init_task_complete_); | 96 DCHECK(!init_task_complete_); |
95 init_task_complete_ = true; | 97 init_task_complete_ = true; |
96 if (waiting_for_init_task_complete_) { | 98 if (waiting_for_init_task_complete_) { |
(...skipping 30 matching lines...) Expand all Loading... |
127 if (running_) | 129 if (running_) |
128 ScheduleNextUpload(); | 130 ScheduleNextUpload(); |
129 } | 131 } |
130 | 132 |
131 void MetricsReportingScheduler::SetUploadIntervalForTesting( | 133 void MetricsReportingScheduler::SetUploadIntervalForTesting( |
132 base::TimeDelta interval) { | 134 base::TimeDelta interval) { |
133 upload_interval_ = interval; | 135 upload_interval_ = interval; |
134 } | 136 } |
135 | 137 |
136 void MetricsReportingScheduler::TriggerUpload() { | 138 void MetricsReportingScheduler::TriggerUpload() { |
| 139 LOG(WARNING) << "metrix TriggerUpload " << init_task_complete_ << " " << last_
upload_finish_time_; |
137 // If the timer fired before the init task has completed, don't trigger the | 140 // If the timer fired before the init task has completed, don't trigger the |
138 // upload yet - wait for the init task to complete and do it then. | 141 // upload yet - wait for the init task to complete and do it then. |
139 if (!init_task_complete_) { | 142 if (!init_task_complete_) { |
140 LogMetricsInitSequence(TIMER_FIRED_FIRST); | 143 LogMetricsInitSequence(TIMER_FIRED_FIRST); |
141 waiting_for_init_task_complete_ = true; | 144 waiting_for_init_task_complete_ = true; |
142 return; | 145 return; |
143 } | 146 } |
144 | 147 |
145 if (!last_upload_finish_time_.is_null()) { | 148 if (!last_upload_finish_time_.is_null()) { |
146 LogActualUploadInterval(base::TimeTicks::Now() - last_upload_finish_time_); | 149 LogActualUploadInterval(base::TimeTicks::Now() - last_upload_finish_time_); |
147 last_upload_finish_time_ = base::TimeTicks(); | 150 last_upload_finish_time_ = base::TimeTicks(); |
148 } | 151 } |
149 | 152 |
150 callback_pending_ = true; | 153 callback_pending_ = true; |
151 upload_callback_.Run(); | 154 upload_callback_.Run(); |
152 } | 155 } |
153 | 156 |
154 void MetricsReportingScheduler::ScheduleNextUpload() { | 157 void MetricsReportingScheduler::ScheduleNextUpload() { |
155 DCHECK(running_); | 158 DCHECK(running_); |
| 159 LOG(WARNING) << "metrix ScheduleNextUpload" << " " << upload_timer_.IsRunning(
) |
| 160 << " " << callback_pending_ << " interval:" << upload_interval_; |
156 if (upload_timer_.IsRunning() || callback_pending_) | 161 if (upload_timer_.IsRunning() || callback_pending_) |
157 return; | 162 return; |
158 | 163 |
159 upload_timer_.Start(FROM_HERE, upload_interval_, this, | 164 upload_timer_.Start(FROM_HERE, upload_interval_, this, |
160 &MetricsReportingScheduler::TriggerUpload); | 165 &MetricsReportingScheduler::TriggerUpload); |
161 } | 166 } |
162 | 167 |
163 void MetricsReportingScheduler::BackOffUploadInterval() { | 168 void MetricsReportingScheduler::BackOffUploadInterval() { |
164 DCHECK_GT(kBackoffMultiplier, 1.0); | 169 DCHECK_GT(kBackoffMultiplier, 1.0); |
165 upload_interval_ = TimeDelta::FromMicroseconds( | 170 upload_interval_ = TimeDelta::FromMicroseconds( |
166 static_cast<int64>(kBackoffMultiplier * | 171 static_cast<int64>(kBackoffMultiplier * |
167 upload_interval_.InMicroseconds())); | 172 upload_interval_.InMicroseconds())); |
168 | 173 |
169 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); | 174 TimeDelta max_interval = kMaxBackoffMultiplier * GetStandardUploadInterval(); |
170 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { | 175 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { |
171 upload_interval_ = max_interval; | 176 upload_interval_ = max_interval; |
172 } | 177 } |
173 } | 178 } |
174 | 179 |
175 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { | 180 base::TimeDelta MetricsReportingScheduler::GetStandardUploadInterval() { |
176 return upload_interval_callback_.Run(); | 181 return upload_interval_callback_.Run(); |
177 } | 182 } |
178 | 183 |
179 } // namespace metrics | 184 } // namespace metrics |
OLD | NEW |