Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: chrome/browser/metrics/metrics_reporting_scheduler.cc

Issue 10539039: Minor style cleanup in metrics_reporting_scheduler.* (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: const Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/metrics/metrics_reporting_scheduler.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "chrome/browser/metrics/metrics_reporting_scheduler.h" 5 #include "chrome/browser/metrics/metrics_reporting_scheduler.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "chrome/browser/metrics/metrics_service.h" 8 #include "chrome/browser/metrics/metrics_service.h"
9 9
10 using base::Time;
11 using base::TimeDelta; 10 using base::TimeDelta;
12 11
13 // The delay, in seconds, after startup before sending the first log message. 12 // The delay, in seconds, after startup before sending the first log message.
14 static const int kInitialUploadIntervalSeconds = 60; 13 const int kInitialUploadIntervalSeconds = 60;
jar (doing other things) 2012/06/08 00:20:02 I'm surprised you pulled the static qualifier. Won
Ilya Sherman 2012/06/08 00:52:14 Numeric constants don't seem to require either, bu
jar (doing other things) 2012/06/11 18:54:28 If I had my druthers.... I'd suggest that Chromium
15 14
16 // The delay, in seconds, between uploading when there are queued logs from 15 // The delay, in seconds, between uploading when there are queued logs from
17 // previous sessions to send. 16 // previous sessions to send.
18 static const int kUnsentLogsIntervalSeconds = 15; 17 const int kUnsentLogsIntervalSeconds = 15;
19 18
20 // Standard interval between log uploads, in seconds. 19 // Standard interval between log uploads, in seconds.
21 static const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. 20 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes.
22 21
23 // When uploading metrics to the server fails, we progressively wait longer and 22 // When uploading metrics to the server fails, we progressively wait longer and
24 // longer before sending the next log. This backoff process helps reduce load 23 // longer before sending the next log. This backoff process helps reduce load
25 // on a server that is having issues. 24 // on a server that is having issues.
26 // The following is the multiplier we use to expand that inter-log duration. 25 // The following is the multiplier we use to expand that inter-log duration.
27 static const double kBackoffMultiplier = 1.1; 26 const double kBackoffMultiplier = 1.1;
28 27
29 // The maximum backoff multiplier. 28 // The maximum backoff multiplier.
30 static const int kMaxBackoffMultiplier = 10; 29 const int kMaxBackoffMultiplier = 10;
31 30
32 31
33 MetricsReportingScheduler::MetricsReportingScheduler( 32 MetricsReportingScheduler::MetricsReportingScheduler(
34 const base::Closure& upload_callback) 33 const base::Closure& upload_callback)
35 : upload_callback_(upload_callback), 34 : upload_callback_(upload_callback),
36 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), 35 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)),
37 running_(false), 36 running_(false),
38 callback_pending_(false) { 37 callback_pending_(false) {
39 } 38 }
40 39
41 MetricsReportingScheduler::~MetricsReportingScheduler() {} 40 MetricsReportingScheduler::~MetricsReportingScheduler() {}
42 41
43 void MetricsReportingScheduler::Start() { 42 void MetricsReportingScheduler::Start() {
44 running_ = true; 43 running_ = true;
45 ScheduleNextCallback(); 44 ScheduleNextUpload();
46 } 45 }
47 46
48 void MetricsReportingScheduler::Stop() { 47 void MetricsReportingScheduler::Stop() {
49 running_ = false; 48 running_ = false;
50 if (upload_timer_.IsRunning()) 49 if (upload_timer_.IsRunning())
51 upload_timer_.Stop(); 50 upload_timer_.Stop();
52 } 51 }
53 52
54 void MetricsReportingScheduler::UploadFinished(bool server_is_healthy, 53 void MetricsReportingScheduler::UploadFinished(bool server_is_healthy,
55 bool more_logs_remaining) { 54 bool more_logs_remaining) {
56 DCHECK(callback_pending_); 55 DCHECK(callback_pending_);
57 callback_pending_ = false; 56 callback_pending_ = false;
58 // If the server is having issues, back off. Otherwise, reset to default 57 // If the server is having issues, back off. Otherwise, reset to default
59 // (unless there are more logs to send, in which case the next upload should 58 // (unless there are more logs to send, in which case the next upload should
60 // happen sooner). 59 // happen sooner).
61 if (!server_is_healthy) { 60 if (!server_is_healthy) {
62 BackOffUploadInterval(); 61 BackOffUploadInterval();
63 } else if (more_logs_remaining) { 62 } else if (more_logs_remaining) {
64 upload_interval_ = TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds); 63 upload_interval_ = TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds);
65 } else { 64 } else {
66 upload_interval_ = TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); 65 upload_interval_ = TimeDelta::FromSeconds(kStandardUploadIntervalSeconds);
67 } 66 }
68 67
69 if (running_) 68 if (running_)
70 ScheduleNextCallback(); 69 ScheduleNextUpload();
71 } 70 }
72 71
73 void MetricsReportingScheduler::UploadCancelled() { 72 void MetricsReportingScheduler::UploadCancelled() {
74 DCHECK(callback_pending_); 73 DCHECK(callback_pending_);
75 callback_pending_ = false; 74 callback_pending_ = false;
76 if (running_) 75 if (running_)
77 ScheduleNextCallback(); 76 ScheduleNextUpload();
78 } 77 }
79 78
80 void MetricsReportingScheduler::TriggerUpload() { 79 void MetricsReportingScheduler::TriggerUpload() {
81 callback_pending_ = true; 80 callback_pending_ = true;
82 upload_callback_.Run(); 81 upload_callback_.Run();
83 } 82 }
84 83
85 void MetricsReportingScheduler::ScheduleNextCallback() { 84 void MetricsReportingScheduler::ScheduleNextUpload() {
86 DCHECK(running_); 85 DCHECK(running_);
87 if (upload_timer_.IsRunning() || callback_pending_) 86 if (upload_timer_.IsRunning() || callback_pending_)
88 return; 87 return;
89 88
90 upload_timer_.Start(FROM_HERE, upload_interval_, this, 89 upload_timer_.Start(FROM_HERE, upload_interval_, this,
91 &MetricsReportingScheduler::TriggerUpload); 90 &MetricsReportingScheduler::TriggerUpload);
92 } 91 }
93 92
94 void MetricsReportingScheduler::BackOffUploadInterval() { 93 void MetricsReportingScheduler::BackOffUploadInterval() {
95 DCHECK(kBackoffMultiplier > 1.0); 94 DCHECK_GT(kBackoffMultiplier, 1.0);
96 upload_interval_ = TimeDelta::FromMicroseconds( 95 upload_interval_ = TimeDelta::FromMicroseconds(
97 static_cast<int64>(kBackoffMultiplier * 96 static_cast<int64>(kBackoffMultiplier *
98 upload_interval_.InMicroseconds())); 97 upload_interval_.InMicroseconds()));
99 98
100 TimeDelta max_interval = kMaxBackoffMultiplier * 99 TimeDelta max_interval = kMaxBackoffMultiplier *
101 TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); 100 TimeDelta::FromSeconds(kStandardUploadIntervalSeconds);
102 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { 101 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) {
103 upload_interval_ = max_interval; 102 upload_interval_ = max_interval;
104 } 103 }
105 } 104 }
OLDNEW
« no previous file with comments | « chrome/browser/metrics/metrics_reporting_scheduler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698