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

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: Anonymous namespace 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
12 namespace {
13
13 // The delay, in seconds, after startup before sending the first log message. 14 // The delay, in seconds, after startup before sending the first log message.
14 static const int kInitialUploadIntervalSeconds = 60; 15 const int kInitialUploadIntervalSeconds = 60;
15 16
16 // The delay, in seconds, between uploading when there are queued logs from 17 // The delay, in seconds, between uploading when there are queued logs from
17 // previous sessions to send. 18 // previous sessions to send.
18 static const int kUnsentLogsIntervalSeconds = 15; 19 const int kUnsentLogsIntervalSeconds = 15;
19 20
20 // Standard interval between log uploads, in seconds. 21 // Standard interval between log uploads, in seconds.
21 static const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes. 22 const int kStandardUploadIntervalSeconds = 30 * 60; // Thirty minutes.
22 23
23 // When uploading metrics to the server fails, we progressively wait longer and 24 // 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 25 // longer before sending the next log. This backoff process helps reduce load
25 // on a server that is having issues. 26 // on a server that is having issues.
26 // The following is the multiplier we use to expand that inter-log duration. 27 // The following is the multiplier we use to expand that inter-log duration.
27 static const double kBackoffMultiplier = 1.1; 28 const double kBackoffMultiplier = 1.1;
28 29
29 // The maximum backoff multiplier. 30 // The maximum backoff multiplier.
30 static const int kMaxBackoffMultiplier = 10; 31 const int kMaxBackoffMultiplier = 10;
31 32
33 } // anonymous namespace
32 34
33 MetricsReportingScheduler::MetricsReportingScheduler( 35 MetricsReportingScheduler::MetricsReportingScheduler(
34 const base::Closure& upload_callback) 36 const base::Closure& upload_callback)
35 : upload_callback_(upload_callback), 37 : upload_callback_(upload_callback),
36 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)), 38 upload_interval_(TimeDelta::FromSeconds(kInitialUploadIntervalSeconds)),
37 running_(false), 39 running_(false),
38 callback_pending_(false) { 40 callback_pending_(false) {
39 } 41 }
40 42
41 MetricsReportingScheduler::~MetricsReportingScheduler() {} 43 MetricsReportingScheduler::~MetricsReportingScheduler() {}
42 44
43 void MetricsReportingScheduler::Start() { 45 void MetricsReportingScheduler::Start() {
44 running_ = true; 46 running_ = true;
45 ScheduleNextCallback(); 47 ScheduleNextUpload();
46 } 48 }
47 49
48 void MetricsReportingScheduler::Stop() { 50 void MetricsReportingScheduler::Stop() {
49 running_ = false; 51 running_ = false;
50 if (upload_timer_.IsRunning()) 52 if (upload_timer_.IsRunning())
51 upload_timer_.Stop(); 53 upload_timer_.Stop();
52 } 54 }
53 55
54 void MetricsReportingScheduler::UploadFinished(bool server_is_healthy, 56 void MetricsReportingScheduler::UploadFinished(bool server_is_healthy,
55 bool more_logs_remaining) { 57 bool more_logs_remaining) {
56 DCHECK(callback_pending_); 58 DCHECK(callback_pending_);
57 callback_pending_ = false; 59 callback_pending_ = false;
58 // If the server is having issues, back off. Otherwise, reset to default 60 // 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 61 // (unless there are more logs to send, in which case the next upload should
60 // happen sooner). 62 // happen sooner).
61 if (!server_is_healthy) { 63 if (!server_is_healthy) {
62 BackOffUploadInterval(); 64 BackOffUploadInterval();
63 } else if (more_logs_remaining) { 65 } else if (more_logs_remaining) {
64 upload_interval_ = TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds); 66 upload_interval_ = TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds);
65 } else { 67 } else {
66 upload_interval_ = TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); 68 upload_interval_ = TimeDelta::FromSeconds(kStandardUploadIntervalSeconds);
67 } 69 }
68 70
69 if (running_) 71 if (running_)
70 ScheduleNextCallback(); 72 ScheduleNextUpload();
71 } 73 }
72 74
73 void MetricsReportingScheduler::UploadCancelled() { 75 void MetricsReportingScheduler::UploadCancelled() {
74 DCHECK(callback_pending_); 76 DCHECK(callback_pending_);
75 callback_pending_ = false; 77 callback_pending_ = false;
76 if (running_) 78 if (running_)
77 ScheduleNextCallback(); 79 ScheduleNextUpload();
78 } 80 }
79 81
80 void MetricsReportingScheduler::TriggerUpload() { 82 void MetricsReportingScheduler::TriggerUpload() {
81 callback_pending_ = true; 83 callback_pending_ = true;
82 upload_callback_.Run(); 84 upload_callback_.Run();
83 } 85 }
84 86
85 void MetricsReportingScheduler::ScheduleNextCallback() { 87 void MetricsReportingScheduler::ScheduleNextUpload() {
86 DCHECK(running_); 88 DCHECK(running_);
87 if (upload_timer_.IsRunning() || callback_pending_) 89 if (upload_timer_.IsRunning() || callback_pending_)
88 return; 90 return;
89 91
90 upload_timer_.Start(FROM_HERE, upload_interval_, this, 92 upload_timer_.Start(FROM_HERE, upload_interval_, this,
91 &MetricsReportingScheduler::TriggerUpload); 93 &MetricsReportingScheduler::TriggerUpload);
92 } 94 }
93 95
94 void MetricsReportingScheduler::BackOffUploadInterval() { 96 void MetricsReportingScheduler::BackOffUploadInterval() {
95 DCHECK(kBackoffMultiplier > 1.0); 97 DCHECK_GT(kBackoffMultiplier, 1.0);
96 upload_interval_ = TimeDelta::FromMicroseconds( 98 upload_interval_ = TimeDelta::FromMicroseconds(
97 static_cast<int64>(kBackoffMultiplier * 99 static_cast<int64>(kBackoffMultiplier *
98 upload_interval_.InMicroseconds())); 100 upload_interval_.InMicroseconds()));
99 101
100 TimeDelta max_interval = kMaxBackoffMultiplier * 102 TimeDelta max_interval = kMaxBackoffMultiplier *
101 TimeDelta::FromSeconds(kStandardUploadIntervalSeconds); 103 TimeDelta::FromSeconds(kStandardUploadIntervalSeconds);
102 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) { 104 if (upload_interval_ > max_interval || upload_interval_.InSeconds() < 0) {
103 upload_interval_ = max_interval; 105 upload_interval_ = max_interval;
104 } 106 }
105 } 107 }
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