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

Side by Side Diff: components/metrics/reporting_service.cc

Issue 2770853002: Create Ukm ReportingService implementation. (Closed)
Patch Set: Also revert datatracker unittest change Created 3 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/metrics/metrics_service.cc ('k') | components/ukm/BUILD.gn » ('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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 // ReportingService handles uploading serialized logs to a server. 5 // ReportingService handles uploading serialized logs to a server.
6 6
7 #include "components/metrics/reporting_service.h" 7 #include "components/metrics/reporting_service.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 DVLOG(1) << "OnLogUploadComplete:" << response_code; 159 DVLOG(1) << "OnLogUploadComplete:" << response_code;
160 DCHECK(thread_checker_.CalledOnValidThread()); 160 DCHECK(thread_checker_.CalledOnValidThread());
161 DCHECK(log_upload_in_progress_); 161 DCHECK(log_upload_in_progress_);
162 log_upload_in_progress_ = false; 162 log_upload_in_progress_ = false;
163 163
164 // Log a histogram to track response success vs. failure rates. 164 // Log a histogram to track response success vs. failure rates.
165 LogResponseCode(response_code); 165 LogResponseCode(response_code);
166 166
167 bool upload_succeeded = response_code == 200; 167 bool upload_succeeded = response_code == 200;
168 168
169 // Provide boolean for error recovery (allow us to ignore response_code). 169 // Staged log could have been removed already (such as by Purge() in some
170 bool discard_log = false; 170 // implementations), otherwise we may remove it here.
171 const size_t log_size = log_store()->staged_log().length(); 171 if (log_store()->has_staged_log()) {
172 if (upload_succeeded) { 172 // Provide boolean for error recovery (allow us to ignore response_code).
173 LogSuccess(log_size); 173 bool discard_log = false;
174 } else if (log_size > max_retransmit_size_) { 174 const size_t log_size = log_store()->staged_log().length();
175 LogLargeRejection(log_size); 175 if (upload_succeeded) {
176 discard_log = true; 176 LogSuccess(log_size);
177 } else if (response_code == 400) { 177 } else if (log_size > max_retransmit_size_) {
178 // Bad syntax. Retransmission won't work. 178 LogLargeRejection(log_size);
179 discard_log = true; 179 discard_log = true;
180 } 180 } else if (response_code == 400) {
181 // Bad syntax. Retransmission won't work.
182 discard_log = true;
183 }
181 184
182 if (upload_succeeded || discard_log) { 185 if (upload_succeeded || discard_log) {
183 log_store()->DiscardStagedLog(); 186 log_store()->DiscardStagedLog();
184 // Store the updated list to disk now that the removed log is uploaded. 187 // Store the updated list to disk now that the removed log is uploaded.
185 log_store()->PersistUnsentLogs(); 188 log_store()->PersistUnsentLogs();
189 }
186 } 190 }
187 191
188 // Error 400 indicates a problem with the log, not with the server, so 192 // Error 400 indicates a problem with the log, not with the server, so
189 // don't consider that a sign that the server is in trouble. 193 // don't consider that a sign that the server is in trouble.
190 bool server_is_healthy = upload_succeeded || response_code == 400; 194 bool server_is_healthy = upload_succeeded || response_code == 400;
191 if (!log_store()->has_unsent_logs()) { 195 if (!log_store()->has_unsent_logs()) {
192 DVLOG(1) << "Stopping upload_scheduler_."; 196 DVLOG(1) << "Stopping upload_scheduler_.";
193 upload_scheduler_->Stop(); 197 upload_scheduler_->Stop();
194 } 198 }
195 upload_scheduler_->UploadFinished(server_is_healthy); 199 upload_scheduler_->UploadFinished(server_is_healthy);
196 } 200 }
197 201
198 } // namespace metrics 202 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_service.cc ('k') | components/ukm/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698