| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 // ReportingService specialized to report UMA metrics. |
| 6 |
| 7 #include "components/metrics/metrics_reporting_service.h" |
| 8 |
| 9 #include "base/bind.h" |
| 10 #include "base/callback.h" |
| 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "components/metrics/metrics_pref_names.h" |
| 13 #include "components/metrics/persisted_logs_metrics_impl.h" |
| 14 #include "components/metrics/url_constants.h" |
| 15 #include "components/prefs/pref_registry_simple.h" |
| 16 |
| 17 namespace metrics { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // If an upload fails, and the transmission was over this byte count, then we |
| 22 // will discard the log, and not try to retransmit it. We also don't persist |
| 23 // the log to the prefs for transmission during the next chrome session if this |
| 24 // limit is exceeded. |
| 25 const size_t kUploadLogAvoidRetransmitSize = 100 * 1024; |
| 26 |
| 27 enum ResponseStatus { |
| 28 UNKNOWN_FAILURE, |
| 29 SUCCESS, |
| 30 BAD_REQUEST, // Invalid syntax or log too large. |
| 31 NO_RESPONSE, |
| 32 NUM_RESPONSE_STATUSES |
| 33 }; |
| 34 |
| 35 ResponseStatus ResponseCodeToStatus(int response_code) { |
| 36 switch (response_code) { |
| 37 case -1: |
| 38 return NO_RESPONSE; |
| 39 case 200: |
| 40 return SUCCESS; |
| 41 case 400: |
| 42 return BAD_REQUEST; |
| 43 default: |
| 44 return UNKNOWN_FAILURE; |
| 45 } |
| 46 } |
| 47 |
| 48 } // namespace |
| 49 |
| 50 // static |
| 51 void MetricsReportingService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 52 ReportingService::RegisterPrefs(registry); |
| 53 MetricsLogStore::RegisterPrefs(registry); |
| 54 } |
| 55 |
| 56 MetricsReportingService::MetricsReportingService(MetricsServiceClient* client, |
| 57 PrefService* local_state) |
| 58 : ReportingService(client, local_state, kUploadLogAvoidRetransmitSize), |
| 59 metrics_log_store_(local_state, kUploadLogAvoidRetransmitSize) {} |
| 60 |
| 61 MetricsReportingService::~MetricsReportingService() {} |
| 62 |
| 63 LogStore* MetricsReportingService::log_store() { |
| 64 return &metrics_log_store_; |
| 65 } |
| 66 |
| 67 std::string MetricsReportingService::GetUploadUrl() const { |
| 68 return client()->GetMetricsServerUrl(); |
| 69 } |
| 70 |
| 71 base::StringPiece MetricsReportingService::upload_mime_type() const { |
| 72 return kDefaultMetricsMimeType; |
| 73 } |
| 74 |
| 75 MetricsLogUploader::MetricServiceType MetricsReportingService::service_type() |
| 76 const { |
| 77 return MetricsLogUploader::UMA; |
| 78 } |
| 79 |
| 80 void MetricsReportingService::LogActualUploadInterval( |
| 81 base::TimeDelta interval) { |
| 82 UMA_HISTOGRAM_CUSTOM_COUNTS("UMA.ActualLogUploadInterval", |
| 83 interval.InMinutes(), 1, |
| 84 base::TimeDelta::FromHours(12).InMinutes(), 50); |
| 85 } |
| 86 |
| 87 void MetricsReportingService::LogCellularConstraint(bool upload_canceled) { |
| 88 UMA_HISTOGRAM_BOOLEAN("UMA.LogUpload.Canceled.CellularConstraint", |
| 89 upload_canceled); |
| 90 } |
| 91 |
| 92 void MetricsReportingService::LogResponseCode(int response_code) { |
| 93 // Log a histogram to track response success vs. failure rates. |
| 94 UMA_HISTOGRAM_ENUMERATION("UMA.UploadResponseStatus.Protobuf", |
| 95 ResponseCodeToStatus(response_code), |
| 96 NUM_RESPONSE_STATUSES); |
| 97 } |
| 98 |
| 99 void MetricsReportingService::LogSuccess(size_t log_size) { |
| 100 UMA_HISTOGRAM_COUNTS_10000("UMA.LogSize.OnSuccess", log_size / 1024); |
| 101 } |
| 102 |
| 103 void MetricsReportingService::LogLargeRejection(size_t log_size) { |
| 104 UMA_HISTOGRAM_COUNTS_1M("UMA.Large Rejected Log was Discarded", |
| 105 static_cast<int>(log_size)); |
| 106 } |
| 107 |
| 108 } // namespace metrics |
| OLD | NEW |