Josh Hilke | be691d75 | 2023-01-09 18:50:57 | [diff] [blame] | 1 | // Copyright 2023 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 | #ifndef COMPONENTS_REPORTING_METRICS_MANUAL_COLLECTOR_H_ |
| 6 | #define COMPONENTS_REPORTING_METRICS_MANUAL_COLLECTOR_H_ |
| 7 | |
| 8 | #include <memory> |
| 9 | #include <string> |
| 10 | |
| 11 | #include "components/reporting/metrics/collector_base.h" |
| 12 | #include "components/reporting/proto/synced/metric_data.pb.h" |
| 13 | |
| 14 | namespace reporting { |
| 15 | |
| 16 | class MetricReportQueue; |
| 17 | class MetricReportingController; |
| 18 | class ReportingSettings; |
Vignesh Shenvi | 51b90be | 2023-12-01 01:15:52 | [diff] [blame] | 19 | |
Josh Hilke | be691d75 | 2023-01-09 18:50:57 | [diff] [blame] | 20 | // Class to collect and report metric data when manually triggered. Does not |
| 21 | // automatically collect data. Necessary reporting settings must be set or |
| 22 | // `setting_enabled_default_value` must be set to True in order to trigger |
| 23 | // collection. |
| 24 | class ManualCollector : public CollectorBase { |
| 25 | public: |
Vignesh Shenvi | 51b90be | 2023-12-01 01:15:52 | [diff] [blame] | 26 | // Metrics name for reporting missing metric data to UMA. |
| 27 | static constexpr char kNoMetricDataMetricsName[] = |
| 28 | "Browser.ERP.MetricsReporting.ManualCollectorNoMetricData"; |
| 29 | |
Josh Hilke | be691d75 | 2023-01-09 18:50:57 | [diff] [blame] | 30 | ManualCollector(Sampler* sampler, |
| 31 | MetricReportQueue* metric_report_queue, |
| 32 | ReportingSettings* reporting_settings, |
| 33 | const std::string& setting_path, |
| 34 | bool setting_enabled_default_value); |
| 35 | |
| 36 | ManualCollector(const ManualCollector& other) = delete; |
| 37 | ManualCollector& operator=(const ManualCollector& other) = delete; |
| 38 | ~ManualCollector() override; |
| 39 | |
| 40 | protected: |
| 41 | // CollectorBase: |
| 42 | bool CanCollect() const override; |
| 43 | // CollectorBase: |
| 44 | void OnMetricDataCollected(bool is_event_driven, |
Arthur Sonzogni | c571efb | 2024-01-26 20:26:18 | [diff] [blame] | 45 | std::optional<MetricData> metric_data) override; |
Josh Hilke | be691d75 | 2023-01-09 18:50:57 | [diff] [blame] | 46 | |
| 47 | private: |
| 48 | const raw_ptr<MetricReportQueue> metric_report_queue_; |
| 49 | const std::unique_ptr<MetricReportingController> reporting_controller_; |
| 50 | }; |
| 51 | } // namespace reporting |
| 52 | |
shaochenguang | 61f8f1d8 | 2023-11-29 23:57:17 | [diff] [blame] | 53 | #endif // COMPONENTS_REPORTING_METRICS_MANUAL_COLLECTOR_H_ |