| OLD | NEW |
| 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 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 base::Bind(&ReportingService::OnLogUploadComplete, | 147 base::Bind(&ReportingService::OnLogUploadComplete, |
| 148 self_ptr_factory_.GetWeakPtr())); | 148 self_ptr_factory_.GetWeakPtr())); |
| 149 } | 149 } |
| 150 | 150 |
| 151 const std::string hash = | 151 const std::string hash = |
| 152 base::HexEncode(log_store()->staged_log_hash().data(), | 152 base::HexEncode(log_store()->staged_log_hash().data(), |
| 153 log_store()->staged_log_hash().size()); | 153 log_store()->staged_log_hash().size()); |
| 154 log_uploader_->UploadLog(log_store()->staged_log(), hash); | 154 log_uploader_->UploadLog(log_store()->staged_log(), hash); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void ReportingService::OnLogUploadComplete(int response_code) { | 157 void ReportingService::OnLogUploadComplete(int response_code, int error_code) { |
| 158 DVLOG(1) << "OnLogUploadComplete:" << response_code; | 158 DVLOG(1) << "OnLogUploadComplete:" << response_code; |
| 159 DCHECK(thread_checker_.CalledOnValidThread()); | 159 DCHECK(thread_checker_.CalledOnValidThread()); |
| 160 DCHECK(log_upload_in_progress_); | 160 DCHECK(log_upload_in_progress_); |
| 161 log_upload_in_progress_ = false; | 161 log_upload_in_progress_ = false; |
| 162 | 162 |
| 163 // Log a histogram to track response success vs. failure rates. | 163 // Log a histogram to track response success vs. failure rates. |
| 164 LogResponseCode(response_code); | 164 LogResponseCode(response_code); |
| 165 if (error_code) |
| 166 LogErrorCode(error_code); |
| 165 | 167 |
| 166 bool upload_succeeded = response_code == 200; | 168 bool upload_succeeded = response_code == 200; |
| 167 | 169 |
| 168 // Staged log could have been removed already (such as by Purge() in some | 170 // Staged log could have been removed already (such as by Purge() in some |
| 169 // implementations), otherwise we may remove it here. | 171 // implementations), otherwise we may remove it here. |
| 170 if (log_store()->has_staged_log()) { | 172 if (log_store()->has_staged_log()) { |
| 171 // Provide boolean for error recovery (allow us to ignore response_code). | 173 // Provide boolean for error recovery (allow us to ignore response_code). |
| 172 bool discard_log = false; | 174 bool discard_log = false; |
| 173 const size_t log_size = log_store()->staged_log().length(); | 175 const size_t log_size = log_store()->staged_log().length(); |
| 174 if (upload_succeeded) { | 176 if (upload_succeeded) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 192 // don't consider that a sign that the server is in trouble. | 194 // don't consider that a sign that the server is in trouble. |
| 193 bool server_is_healthy = upload_succeeded || response_code == 400; | 195 bool server_is_healthy = upload_succeeded || response_code == 400; |
| 194 if (!log_store()->has_unsent_logs()) { | 196 if (!log_store()->has_unsent_logs()) { |
| 195 DVLOG(1) << "Stopping upload_scheduler_."; | 197 DVLOG(1) << "Stopping upload_scheduler_."; |
| 196 upload_scheduler_->Stop(); | 198 upload_scheduler_->Stop(); |
| 197 } | 199 } |
| 198 upload_scheduler_->UploadFinished(server_is_healthy); | 200 upload_scheduler_->UploadFinished(server_is_healthy); |
| 199 } | 201 } |
| 200 | 202 |
| 201 } // namespace metrics | 203 } // namespace metrics |
| OLD | NEW |