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 UKM metrics. |
| 6 |
| 7 #include "components/ukm/ukm_reporting_service.h" |
| 8 |
| 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/metrics/field_trial_params.h" |
| 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "components/prefs/pref_registry_simple.h" |
| 13 #include "components/ukm/persisted_logs_metrics_impl.h" |
| 14 #include "components/ukm/ukm_pref_names.h" |
| 15 #include "components/ukm/ukm_service.h" |
| 16 |
| 17 namespace ukm { |
| 18 |
| 19 namespace { |
| 20 |
| 21 // The UKM server's URL. |
| 22 constexpr char kMimeType[] = "application/vnd.chrome.ukm"; |
| 23 |
| 24 // The number of UKM logs that will be stored in PersistedLogs before logs |
| 25 // start being dropped. |
| 26 constexpr int kMinPersistedLogs = 8; |
| 27 |
| 28 // The number of bytes UKM logs that will be stored in PersistedLogs before |
| 29 // logs start being dropped. |
| 30 // This ensures that a reasonable amount of history will be stored even if there |
| 31 // is a long series of very small logs. |
| 32 constexpr int kMinPersistedBytes = 300000; |
| 33 |
| 34 // If an upload fails, and the transmission was over this byte count, then we |
| 35 // will discard the log, and not try to retransmit it. We also don't persist |
| 36 // the log to the prefs for transmission during the next chrome session if this |
| 37 // limit is exceeded. |
| 38 constexpr size_t kMaxLogRetransmitSize = 100 * 1024; |
| 39 |
| 40 std::string GetServerUrl() { |
| 41 constexpr char kDefaultServerUrl[] = "https://clients4.google.com/ukm"; |
| 42 std::string server_url = |
| 43 base::GetFieldTrialParamValueByFeature(kUkmFeature, "ServerUrl"); |
| 44 if (!server_url.empty()) |
| 45 return server_url; |
| 46 return kDefaultServerUrl; |
| 47 } |
| 48 |
| 49 } // namespace |
| 50 |
| 51 // static |
| 52 void UkmReportingService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 53 registry->RegisterListPref(prefs::kUkmPersistedLogs); |
| 54 // Base class already registered by MetricsReportingService::RegisterPrefs |
| 55 // ReportingService::RegisterPrefs(registry); |
| 56 } |
| 57 |
| 58 UkmReportingService::UkmReportingService(metrics::MetricsServiceClient* client, |
| 59 PrefService* local_state) |
| 60 : ReportingService(client, local_state, kMaxLogRetransmitSize), |
| 61 persisted_logs_(base::MakeUnique<ukm::PersistedLogsMetricsImpl>(), |
| 62 local_state, |
| 63 prefs::kUkmPersistedLogs, |
| 64 kMinPersistedLogs, |
| 65 kMinPersistedBytes, |
| 66 kMaxLogRetransmitSize) {} |
| 67 |
| 68 UkmReportingService::~UkmReportingService() {} |
| 69 |
| 70 metrics::LogStore* UkmReportingService::log_store() { |
| 71 return &persisted_logs_; |
| 72 } |
| 73 |
| 74 std::string UkmReportingService::GetUploadUrl() const { |
| 75 return GetServerUrl(); |
| 76 } |
| 77 |
| 78 base::StringPiece UkmReportingService::upload_mime_type() const { |
| 79 return kMimeType; |
| 80 } |
| 81 |
| 82 metrics::MetricsLogUploader::MetricServiceType |
| 83 UkmReportingService::service_type() const { |
| 84 return metrics::MetricsLogUploader::UKM; |
| 85 } |
| 86 |
| 87 void UkmReportingService::LogCellularConstraint(bool upload_canceled) { |
| 88 UMA_HISTOGRAM_BOOLEAN("UKM.LogUpload.Canceled.CellularConstraint", |
| 89 upload_canceled); |
| 90 } |
| 91 |
| 92 void UkmReportingService::LogResponseCode(int response_code) { |
| 93 UMA_HISTOGRAM_SPARSE_SLOWLY("UKM.Upload.ResponseCode", response_code); |
| 94 } |
| 95 |
| 96 void UkmReportingService::LogSuccess(size_t log_size) { |
| 97 UMA_HISTOGRAM_COUNTS_10000("UKM.LogSize.OnSuccess", log_size / 1024); |
| 98 } |
| 99 |
| 100 void UkmReportingService::LogLargeRejection(size_t log_size) {} |
| 101 |
| 102 } // namespace metrics |
OLD | NEW |