Chromium Code Reviews| 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/metrics/field_trial_params.h" | |
| 10 #include "base/metrics/histogram_macros.h" | |
| 11 #include "components/prefs/pref_registry_simple.h" | |
| 12 #include "components/ukm/persisted_logs_metrics_impl.h" | |
| 13 #include "components/ukm/ukm_pref_names.h" | |
| 14 #include "components/ukm/ukm_service.h" | |
| 15 | |
| 16 namespace ukm { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 // The UKM server's URL. | |
| 21 constexpr char kMimeType[] = "application/vnd.chrome.ukm"; | |
| 22 | |
| 23 // The number of UKM logs that will be stored in PersistedLogs before logs | |
| 24 // start being dropped. | |
| 25 constexpr int kMinPersistedLogs = 8; | |
| 26 | |
| 27 // The number of bytes UKM logs that will be stored in PersistedLogs before | |
| 28 // logs start being dropped. | |
| 29 // This ensures that a reasonable amount of history will be stored even if there | |
| 30 // is a long series of very small logs. | |
| 31 constexpr int kMinPersistedBytes = 300000; | |
| 32 | |
| 33 // If an upload fails, and the transmission was over this byte count, then we | |
| 34 // will discard the log, and not try to retransmit it. We also don't persist | |
| 35 // the log to the prefs for transmission during the next chrome session if this | |
| 36 // limit is exceeded. | |
| 37 constexpr size_t kMaxLogRetransmitSize = 100 * 1024; | |
| 38 | |
| 39 std::string GetServerUrl() { | |
| 40 constexpr char kDefaultServerUrl[] = "https://clients4.google.com/ukm"; | |
| 41 std::string server_url = | |
| 42 base::GetFieldTrialParamValueByFeature(kUkmFeature, "ServerUrl"); | |
| 43 if (!server_url.empty()) | |
| 44 return server_url; | |
| 45 return kDefaultServerUrl; | |
| 46 } | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 // static | |
| 51 void UkmReportingService::RegisterPrefs(PrefRegistrySimple* registry) { | |
| 52 registry->RegisterListPref(prefs::kUkmPersistedLogs); | |
| 53 // Base class already registered by MetricsReportingService::RegisterPrefs | |
| 54 // ReportingService::RegisterPrefs(registry); | |
| 55 } | |
| 56 | |
| 57 UkmReportingService::UkmReportingService(metrics::MetricsServiceClient* client, | |
| 58 PrefService* local_state) | |
| 59 : ReportingService(client, local_state, kMaxLogRetransmitSize), | |
| 60 persisted_logs_(std::unique_ptr<ukm::PersistedLogsMetricsImpl>( | |
| 61 new ukm::PersistedLogsMetricsImpl()), | |
|
Alexei Svitkine (slow)
2017/03/24 16:26:17
base::MakeUnique
Steven Holte
2017/03/24 18:13:29
Done.
| |
| 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); | |
|
Alexei Svitkine (slow)
2017/03/24 16:26:17
I guess this needs rebasing on your other cl.
Steven Holte
2017/03/24 18:13:29
That CL is based on this one.
| |
| 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 |