| 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 #include "components/ukm/ukm_service.h" | 5 #include "components/ukm/ukm_service.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 void UkmService::OnLogUploadComplete(int response_code) { | 390 void UkmService::OnLogUploadComplete(int response_code) { |
| 391 DCHECK(thread_checker_.CalledOnValidThread()); | 391 DCHECK(thread_checker_.CalledOnValidThread()); |
| 392 DCHECK(log_upload_in_progress_); | 392 DCHECK(log_upload_in_progress_); |
| 393 DVLOG(1) << "UkmService::OnLogUploadComplete"; | 393 DVLOG(1) << "UkmService::OnLogUploadComplete"; |
| 394 log_upload_in_progress_ = false; | 394 log_upload_in_progress_ = false; |
| 395 | 395 |
| 396 UMA_HISTOGRAM_SPARSE_SLOWLY("UKM.Upload.ResponseCode", response_code); | 396 UMA_HISTOGRAM_SPARSE_SLOWLY("UKM.Upload.ResponseCode", response_code); |
| 397 | 397 |
| 398 bool upload_succeeded = response_code == 200; | 398 bool upload_succeeded = response_code == 200; |
| 399 | 399 |
| 400 // Provide boolean for error recovery (allow us to ignore response_code). | 400 // Staged log may have been deleted by Purge already, otherwise we may |
| 401 bool discard_log = false; | 401 // remove it from the log store here. |
| 402 const size_t log_size_bytes = persisted_logs_.staged_log().length(); | 402 if (persisted_logs_.has_staged_log()) { |
| 403 if (upload_succeeded) { | 403 // Provide boolean for error recovery (allow us to ignore response_code). |
| 404 UMA_HISTOGRAM_COUNTS_10000("UKM.LogSize.OnSuccess", log_size_bytes / 1024); | 404 bool discard_log = false; |
| 405 } else if (response_code == 400) { | 405 const size_t log_size_bytes = persisted_logs_.staged_log().length(); |
| 406 // Bad syntax. Retransmission won't work. | 406 if (upload_succeeded) { |
| 407 discard_log = true; | 407 UMA_HISTOGRAM_COUNTS_10000("UKM.LogSize.OnSuccess", |
| 408 } | 408 log_size_bytes / 1024); |
| 409 } else if (response_code == 400) { |
| 410 // Bad syntax. Retransmission won't work. |
| 411 discard_log = true; |
| 412 } |
| 409 | 413 |
| 410 if (upload_succeeded || discard_log) { | 414 if (upload_succeeded || discard_log) { |
| 411 // TODO(holte): The if below is a temporary fix for a crash bug. We should | |
| 412 // revisit the logic and update it with a more correct fix. crbug.com/698819 | |
| 413 if (persisted_logs_.has_staged_log()) | |
| 414 persisted_logs_.DiscardStagedLog(); | 415 persisted_logs_.DiscardStagedLog(); |
| 415 // Store the updated list to disk now that the removed log is uploaded. | 416 // Store the updated list to disk now that the removed log is uploaded. |
| 416 persisted_logs_.PersistUnsentLogs(); | 417 persisted_logs_.PersistUnsentLogs(); |
| 418 } |
| 417 } | 419 } |
| 418 | 420 |
| 419 // Error 400 indicates a problem with the log, not with the server, so | 421 // Error 400 indicates a problem with the log, not with the server, so |
| 420 // don't consider that a sign that the server is in trouble. | 422 // don't consider that a sign that the server is in trouble. |
| 421 bool server_is_healthy = upload_succeeded || response_code == 400; | 423 bool server_is_healthy = upload_succeeded || response_code == 400; |
| 422 scheduler_->UploadFinished(server_is_healthy, | 424 scheduler_->UploadFinished(server_is_healthy, |
| 423 persisted_logs_.has_unsent_logs()); | 425 persisted_logs_.has_unsent_logs()); |
| 424 } | 426 } |
| 425 | 427 |
| 426 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) { | 428 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 } | 492 } |
| 491 if (entries_.size() >= GetMaxEntries()) { | 493 if (entries_.size() >= GetMaxEntries()) { |
| 492 RecordDroppedEntry(DroppedDataReason::MAX_HIT); | 494 RecordDroppedEntry(DroppedDataReason::MAX_HIT); |
| 493 return; | 495 return; |
| 494 } | 496 } |
| 495 | 497 |
| 496 entries_.push_back(std::move(entry)); | 498 entries_.push_back(std::move(entry)); |
| 497 } | 499 } |
| 498 | 500 |
| 499 } // namespace ukm | 501 } // namespace ukm |
| OLD | NEW |