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