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