1 // Copyright 2024 The Chromium Authors
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 DWA metrics.
6
7 #include "components/metrics/dwa/dwa_reporting_service.h"
8
9 #include <memory>
10 #include <string_view>
11
12 #include "components/metrics/dwa/dwa_pref_names.h"
13 #include "components/metrics/metrics_service_client.h"
14 #include "components/metrics/unsent_log_store.h"
15 #include "components/metrics/unsent_log_store_metrics.h"
16 #include "components/metrics/url_constants.h"
17 #include "components/prefs/pref_registry_simple.h"
18
19 namespace metrics::dwa {
20
DwaReportingService(metrics::MetricsServiceClient * client,PrefService * local_state,const UnsentLogStore::UnsentLogStoreLimits & storage_limits)21 DwaReportingService::DwaReportingService(
22 metrics::MetricsServiceClient* client,
23 PrefService* local_state,
24 const UnsentLogStore::UnsentLogStoreLimits& storage_limits)
25 : ReportingService(client,
26 local_state,
27 storage_limits.max_log_size_bytes,
28 /*logs_event_manager=*/nullptr),
29 unsent_log_store_(std::make_unique<UnsentLogStoreMetrics>(),
30 local_state,
31 prefs::kUnsentLogStoreName,
32 /*metadata_pref_name=*/nullptr,
33 storage_limits,
34 client->GetUploadSigningKey(),
35 /*logs_event_manager=*/nullptr) {}
36
37 DwaReportingService::~DwaReportingService() = default;
38
unsent_log_store()39 metrics::UnsentLogStore* DwaReportingService::unsent_log_store() {
40 return &unsent_log_store_;
41 }
42
43 // static
RegisterPrefs(PrefRegistrySimple * registry)44 void DwaReportingService::RegisterPrefs(PrefRegistrySimple* registry) {
45 registry->RegisterListPref(prefs::kUnsentLogStoreName);
46 }
47
log_store()48 metrics::LogStore* DwaReportingService::log_store() {
49 return &unsent_log_store_;
50 }
51
GetUploadUrl() const52 GURL DwaReportingService::GetUploadUrl() const {
53 return GURL(metrics::kDefaultDwaServerUrl);
54 }
55
GetInsecureUploadUrl() const56 GURL DwaReportingService::GetInsecureUploadUrl() const {
57 // Returns an empty string since retrying over HTTP is not enabled for DWA.
58 return GURL();
59 }
60
upload_mime_type() const61 std::string_view DwaReportingService::upload_mime_type() const {
62 return kDefaultMetricsMimeType;
63 }
64
65 metrics::MetricsLogUploader::MetricServiceType
service_type() const66 DwaReportingService::service_type() const {
67 return MetricsLogUploader::DWA;
68 }
69
70 } // namespace metrics::dwa
71