1 // Copyright 2017 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 metrics logs to a server. 6 7 #ifndef COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_ 8 #define COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_ 9 10 #include <stdint.h> 11 12 #include <string> 13 14 #include "components/metrics/metrics_log_store.h" 15 #include "components/metrics/reporting_service.h" 16 17 class PrefService; 18 class PrefRegistrySimple; 19 20 namespace metrics { 21 22 class MetricsServiceClient; 23 24 // MetricsReportingService is concrete implementation of ReportingService for 25 // UMA logs. It uses a MetricsLogStore as its LogStore, reports to the UMA 26 // endpoint, and logs some histograms with the UMA prefix. 27 class MetricsReportingService : public ReportingService { 28 public: 29 // Creates a ReportingService with the given |client|, |local_state|, and 30 // |logs_event_manager_|. Does not take ownership of the parameters; instead 31 // it stores a weak pointer to each. Caller should ensure that the parameters 32 // are valid for the lifetime of this class. |logs_event_manager| is used to 33 // notify observers of log events. Can be set to null if observing the events 34 // is not necessary. 35 MetricsReportingService(MetricsServiceClient* client, 36 PrefService* local_state, 37 MetricsLogsEventManager* logs_event_manager_); 38 39 MetricsReportingService(const MetricsReportingService&) = delete; 40 MetricsReportingService& operator=(const MetricsReportingService&) = delete; 41 42 ~MetricsReportingService() override; 43 metrics_log_store()44 MetricsLogStore* metrics_log_store() { return &metrics_log_store_; } metrics_log_store()45 const MetricsLogStore* metrics_log_store() const { 46 return &metrics_log_store_; 47 } 48 49 // Registers local state prefs used by this class. 50 static void RegisterPrefs(PrefRegistrySimple* registry); 51 52 private: 53 // ReportingService: 54 LogStore* log_store() override; 55 GURL GetUploadUrl() const override; 56 GURL GetInsecureUploadUrl() const override; 57 base::StringPiece upload_mime_type() const override; 58 MetricsLogUploader::MetricServiceType service_type() const override; 59 void LogActualUploadInterval(base::TimeDelta interval) override; 60 void LogCellularConstraint(bool upload_canceled) override; 61 void LogResponseOrErrorCode(int response_code, 62 int error_code, 63 bool was_https) override; 64 void LogSuccessLogSize(size_t log_size) override; 65 void LogSuccessMetadata(const std::string& staged_log) override; 66 void LogLargeRejection(size_t log_size) override; 67 68 MetricsLogStore metrics_log_store_; 69 }; 70 71 } // namespace metrics 72 73 #endif // COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_ 74