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.
5 // This file defines a service that sends metrics logs to a server.
7 #ifndef COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_
8 #define COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_
14 #include "components/metrics/metrics_log_store.h"
15 #include "components/metrics/reporting_service.h"
18 class PrefRegistrySimple;
22 class MetricsServiceClient;
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 {
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
35 MetricsReportingService(MetricsServiceClient* client,
36 PrefService* local_state,
37 MetricsLogsEventManager* logs_event_manager_);
39 MetricsReportingService(const MetricsReportingService&) = delete;
40 MetricsReportingService& operator=(const MetricsReportingService&) = delete;
42 ~MetricsReportingService() override;
44 MetricsLogStore* metrics_log_store() { return &metrics_log_store_; }
45 const MetricsLogStore* metrics_log_store() const {
46 return &metrics_log_store_;
49 // Registers local state prefs used by this class.
50 static void RegisterPrefs(PrefRegistrySimple* registry);
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,
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;
68 MetricsLogStore metrics_log_store_;
71 } // namespace metrics
73 #endif // COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_