Chromium Code Reviews| 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 } | 265 } |
| 266 | 266 |
| 267 void UkmService::StartScheduledUpload() { | 267 void UkmService::StartScheduledUpload() { |
| 268 DCHECK(thread_checker_.CalledOnValidThread()); | 268 DCHECK(thread_checker_.CalledOnValidThread()); |
| 269 DCHECK(!log_upload_in_progress_); | 269 DCHECK(!log_upload_in_progress_); |
| 270 if (!persisted_logs_.has_unsent_logs()) { | 270 if (!persisted_logs_.has_unsent_logs()) { |
| 271 // No logs to send, so early out and schedule the next rotation. | 271 // No logs to send, so early out and schedule the next rotation. |
| 272 scheduler_->UploadFinished(true, /* has_unsent_logs */ false); | 272 scheduler_->UploadFinished(true, /* has_unsent_logs */ false); |
| 273 return; | 273 return; |
| 274 } | 274 } |
| 275 if (!persisted_logs_.has_staged_log()) | 275 if (!persisted_logs_.has_staged_log()) |
|
Alexei Svitkine (slow)
2017/03/07 22:02:10
One other thing I noticed is this logic.
If Start
Steven Holte
2017/03/07 22:26:18
StartScheduledUpload should not be called while up
| |
| 276 persisted_logs_.StageNextLog(); | 276 persisted_logs_.StageNextLog(); |
| 277 // TODO(holte): Handle data usage on cellular, etc. | 277 // TODO(holte): Handle data usage on cellular, etc. |
| 278 if (!log_uploader_) { | 278 if (!log_uploader_) { |
| 279 log_uploader_ = client_->CreateUploader( | 279 log_uploader_ = client_->CreateUploader( |
| 280 GetServerUrl(), kMimeType, metrics::MetricsLogUploader::UKM, | 280 GetServerUrl(), kMimeType, metrics::MetricsLogUploader::UKM, |
| 281 base::Bind(&UkmService::OnLogUploadComplete, | 281 base::Bind(&UkmService::OnLogUploadComplete, |
| 282 self_ptr_factory_.GetWeakPtr())); | 282 self_ptr_factory_.GetWeakPtr())); |
| 283 } | 283 } |
| 284 log_upload_in_progress_ = true; | 284 log_upload_in_progress_ = true; |
| 285 | 285 |
| 286 const std::string hash = | 286 const std::string hash = |
| 287 base::HexEncode(persisted_logs_.staged_log_hash().data(), | 287 base::HexEncode(persisted_logs_.staged_log_hash().data(), |
| 288 persisted_logs_.staged_log_hash().size()); | 288 persisted_logs_.staged_log_hash().size()); |
| 289 log_uploader_->UploadLog(persisted_logs_.staged_log(), hash); | 289 log_uploader_->UploadLog(persisted_logs_.staged_log(), hash); |
| 290 } | 290 } |
| 291 | 291 |
| 292 void UkmService::OnLogUploadComplete(int response_code) { | 292 void UkmService::OnLogUploadComplete(int response_code) { |
| 293 DCHECK(thread_checker_.CalledOnValidThread()); | 293 DCHECK(thread_checker_.CalledOnValidThread()); |
| 294 DCHECK(log_upload_in_progress_); | 294 DCHECK(log_upload_in_progress_); |
| 295 DVLOG(1) << "UkmService::OnLogUploadComplete"; | 295 DVLOG(1) << "UkmService::OnLogUploadComplete"; |
| 296 log_upload_in_progress_ = false; | 296 log_upload_in_progress_ = false; |
| 297 | 297 |
| 298 UMA_HISTOGRAM_SPARSE_SLOWLY("UKM.Upload.ResponseCode", response_code); | 298 UMA_HISTOGRAM_SPARSE_SLOWLY("UKM.Upload.ResponseCode", response_code); |
| 299 | 299 |
| 300 bool upload_succeeded = response_code == 200; | 300 bool upload_succeeded = response_code == 200; |
| 301 if (persisted_logs_.has_staged_log()) { | |
| 302 // Provide boolean for error recovery (allow us to ignore response_code). | |
| 303 bool discard_log = false; | |
| 304 const size_t log_size_bytes = persisted_logs_.staged_log().length(); | |
| 305 if (upload_succeeded) { | |
| 306 UMA_HISTOGRAM_COUNTS_10000("UKM.LogSize.OnSuccess", | |
| 307 log_size_bytes / 1024); | |
| 308 } else if (response_code == 400) { | |
| 309 // Bad syntax. Retransmission won't work. | |
| 310 discard_log = true; | |
| 311 } | |
| 301 | 312 |
| 302 // Provide boolean for error recovery (allow us to ignore response_code). | 313 if (upload_succeeded || discard_log) { |
| 303 bool discard_log = false; | 314 persisted_logs_.DiscardStagedLog(); |
| 304 const size_t log_size_bytes = persisted_logs_.staged_log().length(); | 315 // Store the updated list to disk now that the removed log is uploaded. |
| 305 if (upload_succeeded) { | 316 persisted_logs_.PersistUnsentLogs(); |
| 306 UMA_HISTOGRAM_COUNTS_10000("UKM.LogSize.OnSuccess", log_size_bytes / 1024); | 317 } |
| 307 } else if (response_code == 400) { | 318 } else { |
| 308 // Bad syntax. Retransmission won't work. | 319 // Staged log may have been deleted by Purge already. |
| 309 discard_log = true; | 320 UMA_HISTOGRAM_SPARSE_SLOWLY("UKM.Upload.Purged.ResponseCode", |
|
Alexei Svitkine (slow)
2017/03/07 22:02:10
I don't understand why we should do a separate cod
Steven Holte
2017/03/07 22:26:18
Was just adding this to record how often it actual
| |
| 310 } | 321 response_code); |
| 311 | |
| 312 if (upload_succeeded || discard_log) { | |
| 313 persisted_logs_.DiscardStagedLog(); | |
|
Alexei Svitkine (slow)
2017/03/07 22:02:10
You'll need to rebase on my change.
Steven Holte
2017/03/07 22:26:18
Done.
| |
| 314 // Store the updated list to disk now that the removed log is uploaded. | |
| 315 persisted_logs_.PersistUnsentLogs(); | |
| 316 } | 322 } |
| 317 | 323 |
| 318 // Error 400 indicates a problem with the log, not with the server, so | 324 // Error 400 indicates a problem with the log, not with the server, so |
| 319 // don't consider that a sign that the server is in trouble. | 325 // don't consider that a sign that the server is in trouble. |
| 320 bool server_is_healthy = upload_succeeded || response_code == 400; | 326 bool server_is_healthy = upload_succeeded || response_code == 400; |
| 321 scheduler_->UploadFinished(server_is_healthy, | 327 scheduler_->UploadFinished(server_is_healthy, |
| 322 persisted_logs_.has_unsent_logs()); | 328 persisted_logs_.has_unsent_logs()); |
| 323 } | 329 } |
| 324 | 330 |
| 325 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) { | 331 void UkmService::RecordSource(std::unique_ptr<UkmSource> source) { |
| 326 if (!recording_enabled_) { | 332 if (!recording_enabled_) { |
| 327 RecordDroppedSource(DroppedSourceReason::RECORDING_DISABLED); | 333 RecordDroppedSource(DroppedSourceReason::RECORDING_DISABLED); |
| 328 return; | 334 return; |
| 329 } | 335 } |
| 330 if (sources_.size() >= kMaxSources) { | 336 if (sources_.size() >= kMaxSources) { |
| 331 RecordDroppedSource(DroppedSourceReason::MAX_SOURCES_HIT); | 337 RecordDroppedSource(DroppedSourceReason::MAX_SOURCES_HIT); |
| 332 return; | 338 return; |
| 333 } | 339 } |
| 334 | 340 |
| 335 sources_.push_back(std::move(source)); | 341 sources_.push_back(std::move(source)); |
| 336 } | 342 } |
| 337 | 343 |
| 338 } // namespace ukm | 344 } // namespace ukm |
| OLD | NEW |