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

Side by Side Diff: components/rappor/log_uploader.cc

Issue 188103004: C++ Readability review for holte (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix struct/class declaration Created 6 years, 9 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
« no previous file with comments | « components/rappor/log_uploader.h ('k') | components/rappor/log_uploader_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/rappor/log_uploader.h" 5 #include "components/rappor/log_uploader.h"
6 6
7 #include "base/metrics/histogram.h" 7 #include "base/metrics/histogram.h"
8 #include "base/metrics/sparse_histogram.h" 8 #include "base/metrics/sparse_histogram.h"
9 #include "net/base/load_flags.h" 9 #include "net/base/load_flags.h"
10 #include "net/url_request/url_fetcher.h" 10 #include "net/url_request/url_fetcher.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 return interval > max_interval ? max_interval : interval; 95 return interval > max_interval ? max_interval : interval;
96 } 96 }
97 97
98 void LogUploader::OnURLFetchComplete(const net::URLFetcher* source) { 98 void LogUploader::OnURLFetchComplete(const net::URLFetcher* source) {
99 // We're not allowed to re-use the existing |URLFetcher|s, so free them here. 99 // We're not allowed to re-use the existing |URLFetcher|s, so free them here.
100 // Note however that |source| is aliased to the fetcher, so we should be 100 // Note however that |source| is aliased to the fetcher, so we should be
101 // careful not to delete it too early. 101 // careful not to delete it too early.
102 DCHECK_EQ(current_fetch_.get(), source); 102 DCHECK_EQ(current_fetch_.get(), source);
103 scoped_ptr<net::URLFetcher> fetch(current_fetch_.Pass()); 103 scoped_ptr<net::URLFetcher> fetch(current_fetch_.Pass());
104 104
105 int response_code = source->GetResponseCode(); 105 const int response_code = source->GetResponseCode();
106 106
107 // Log a histogram to track response success vs. failure rates. 107 // Log a histogram to track response success vs. failure rates.
108 UMA_HISTOGRAM_SPARSE_SLOWLY("Rappor.UploadResponseCode", response_code); 108 UMA_HISTOGRAM_SPARSE_SLOWLY("Rappor.UploadResponseCode", response_code);
109 109
110 bool upload_succeeded = response_code == 200; 110 const bool upload_succeeded = response_code == 200;
111 111
112 // Determine whether this log should be retransmitted. 112 // Determine whether this log should be retransmitted.
113 DiscardReason reason = NUM_DISCARD_REASONS; 113 DiscardReason reason = NUM_DISCARD_REASONS;
114 if (upload_succeeded) { 114 if (upload_succeeded) {
115 reason = UPLOAD_SUCCESS; 115 reason = UPLOAD_SUCCESS;
116 } else if (response_code == 400) { 116 } else if (response_code == 400) {
117 reason = UPLOAD_REJECTED; 117 reason = UPLOAD_REJECTED;
118 } else if (queued_logs_.size() > kMaxQueuedLogs) { 118 } else if (queued_logs_.size() > kMaxQueuedLogs) {
119 reason = QUEUE_OVERFLOW; 119 reason = QUEUE_OVERFLOW;
120 } 120 }
121 121
122 if (reason != NUM_DISCARD_REASONS) { 122 if (reason != NUM_DISCARD_REASONS) {
123 UMA_HISTOGRAM_ENUMERATION("Rappor.DiscardReason", 123 UMA_HISTOGRAM_ENUMERATION("Rappor.DiscardReason",
124 reason, 124 reason,
125 NUM_DISCARD_REASONS); 125 NUM_DISCARD_REASONS);
126 queued_logs_.pop(); 126 queued_logs_.pop();
127 } 127 }
128 128
129 // Error 400 indicates a problem with the log, not with the server, so 129 // Error 400 indicates a problem with the log, not with the server, so
130 // don't consider that a sign that the server is in trouble. 130 // don't consider that a sign that the server is in trouble.
131 bool server_is_healthy = upload_succeeded || response_code == 400; 131 const bool server_is_healthy = upload_succeeded || response_code == 400;
132 OnUploadFinished(server_is_healthy, !queued_logs_.empty()); 132 OnUploadFinished(server_is_healthy, !queued_logs_.empty());
133 } 133 }
134 134
135 void LogUploader::OnUploadFinished(bool server_is_healthy, 135 void LogUploader::OnUploadFinished(bool server_is_healthy,
136 bool more_logs_remaining) { 136 bool more_logs_remaining) {
137 DCHECK(has_callback_pending_); 137 DCHECK(has_callback_pending_);
138 has_callback_pending_ = false; 138 has_callback_pending_ = false;
139 // If the server is having issues, back off. Otherwise, reset to default. 139 // If the server is having issues, back off. Otherwise, reset to default.
140 if (!server_is_healthy) 140 if (!server_is_healthy)
141 upload_interval_ = BackOffUploadInterval(upload_interval_); 141 upload_interval_ = BackOffUploadInterval(upload_interval_);
142 else 142 else
143 upload_interval_ = base::TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds); 143 upload_interval_ = base::TimeDelta::FromSeconds(kUnsentLogsIntervalSeconds);
144 144
145 if (more_logs_remaining) 145 if (more_logs_remaining)
146 ScheduleNextUpload(upload_interval_); 146 ScheduleNextUpload(upload_interval_);
147 } 147 }
148 148
149 } // namespace rappor 149 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/log_uploader.h ('k') | components/rappor/log_uploader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698