metrics_reporting_service.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. // This file defines a service that sends metrics logs to a server.
  5. #ifndef COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_
  6. #define COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_
  7. #include <stdint.h>
  8. #include <string>
  9. #include "components/metrics/metrics_log_store.h"
  10. #include "components/metrics/reporting_service.h"
  11. class PrefService;
  12. class PrefRegistrySimple;
  13. namespace metrics {
  14. class MetricsServiceClient;
  15. // MetricsReportingService is concrete implementation of ReportingService for
  16. // UMA logs. It uses a MetricsLogStore as its LogStore, reports to the UMA
  17. // endpoint, and logs some histograms with the UMA prefix.
  18. class MetricsReportingService : public ReportingService {
  19. public:
  20. // Creates a ReportingService with the given |client|, |local_state|.
  21. // Does not take ownership of the parameters; instead it stores a weak
  22. // pointer to each. Caller should ensure that the parameters are valid for
  23. // the lifetime of this class.
  24. MetricsReportingService(MetricsServiceClient* client,
  25. PrefService* local_state);
  26. MetricsReportingService(const MetricsReportingService&) = delete;
  27. MetricsReportingService& operator=(const MetricsReportingService&) = delete;
  28. ~MetricsReportingService() override;
  29. MetricsLogStore* metrics_log_store() { return &metrics_log_store_; }
  30. const MetricsLogStore* metrics_log_store() const {
  31. return &metrics_log_store_;
  32. }
  33. // Registers local state prefs used by this class.
  34. static void RegisterPrefs(PrefRegistrySimple* registry);
  35. private:
  36. // ReportingService:
  37. LogStore* log_store() override;
  38. GURL GetUploadUrl() const override;
  39. GURL GetInsecureUploadUrl() const override;
  40. base::StringPiece upload_mime_type() const override;
  41. MetricsLogUploader::MetricServiceType service_type() const override;
  42. void LogActualUploadInterval(base::TimeDelta interval) override;
  43. void LogCellularConstraint(bool upload_canceled) override;
  44. void LogResponseOrErrorCode(int response_code,
  45. int error_code,
  46. bool was_https) override;
  47. void LogSuccessLogSize(size_t log_size) override;
  48. void LogSuccessMetadata(const std::string& staged_log) override;
  49. void LogLargeRejection(size_t log_size) override;
  50. MetricsLogStore metrics_log_store_;
  51. };
  52. } // namespace metrics
  53. #endif // COMPONENTS_METRICS_METRICS_REPORTING_SERVICE_H_