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 // This file defines a service that sends DWA logs to a server. 6 7 #ifndef COMPONENTS_METRICS_DWA_DWA_REPORTING_SERVICE_H_ 8 #define COMPONENTS_METRICS_DWA_DWA_REPORTING_SERVICE_H_ 9 10 #include <stdint.h> 11 12 #include <string> 13 #include <string_view> 14 15 #include "components/metrics/reporting_service.h" 16 #include "components/metrics/unsent_log_store.h" 17 18 class PrefService; 19 class PrefRegistrySimple; 20 21 namespace metrics { 22 class MetricsServiceClient; 23 24 namespace dwa { 25 26 // A service that uploads logs to the DWA server. 27 class DwaReportingService : public metrics::ReportingService { 28 public: 29 // Creates the DwaReportingService with the given |client|, |local_state|, and 30 // |storage_limits|. Does not take ownership of the parameters; instead stores 31 // a weak pointer to each. Caller should ensure that the parameters are valid 32 // for the lifetime of this class. 33 DwaReportingService( 34 metrics::MetricsServiceClient* client, 35 PrefService* local_state, 36 const UnsentLogStore::UnsentLogStoreLimits& storage_limits); 37 38 DwaReportingService(const DwaReportingService&) = delete; 39 DwaReportingService& operator=(const DwaReportingService&) = delete; 40 41 ~DwaReportingService() override; 42 43 metrics::UnsentLogStore* unsent_log_store(); 44 45 // At startup, prefs needs to be called with a list of all the pref names and 46 // types we'll be using. 47 static void RegisterPrefs(PrefRegistrySimple* registry); 48 49 private: 50 // metrics::ReportingService: 51 metrics::LogStore* log_store() override; 52 GURL GetUploadUrl() const override; 53 GURL GetInsecureUploadUrl() const override; 54 std::string_view upload_mime_type() const override; 55 metrics::MetricsLogUploader::MetricServiceType service_type() const override; 56 57 metrics::UnsentLogStore unsent_log_store_; 58 }; 59 60 } // namespace dwa 61 } // namespace metrics 62 63 #endif // COMPONENTS_METRICS_DWA_DWA_REPORTING_SERVICE_H_ 64