blob: a3ace9e62746443e07ed65103276d7ca05d03808 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2021 The Chromium Authors
Ahmed Nasrf8079c032021-10-30 01:35:192// 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_METRIC_REPORT_QUEUE_H_
6#define COMPONENTS_REPORTING_METRICS_METRIC_REPORT_QUEUE_H_
7
8#include <memory>
9#include <string>
10
Ahmed Nasr7ba217d2022-11-11 21:27:3311#include "base/functional/callback_helpers.h"
Ahmed Nasrf8079c032021-10-30 01:35:1912#include "base/task/sequenced_task_runner.h"
13#include "base/time/time.h"
14#include "components/reporting/client/report_queue.h"
15#include "components/reporting/proto/synced/record_constants.pb.h"
16
17namespace reporting {
18
19class MetricData;
20class MetricRateController;
21class ReportingSettings;
22
23// Simple wrapper for `::reporting::ReportQueue` that can be set for periodic
24// upload.
25class MetricReportQueue {
26 public:
27 MetricReportQueue(
28 std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue,
29 Priority priority);
30
31 // Constructor used if the reporter is needed to upload records periodically.
32 MetricReportQueue(
33 std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue,
34 Priority priority,
35 ReportingSettings* reporting_settings,
36 const std::string& rate_setting_path,
37 base::TimeDelta default_rate,
38 int rate_unit_to_ms = 1);
39
40 MetricReportQueue() = delete;
41 MetricReportQueue(const MetricReportQueue& other) = delete;
42 MetricReportQueue& operator=(const MetricReportQueue& other) = delete;
43
44 virtual ~MetricReportQueue();
45
46 // Enqueue the metric data.
Ahmed Nasr7ba217d2022-11-11 21:27:3347 virtual void Enqueue(
48 MetricData metric_data,
49 ReportQueue::EnqueueCallback callback = base::DoNothing());
Ahmed Nasrf8079c032021-10-30 01:35:1950
Ahmed Nasr7fab5292022-01-19 23:57:2851 // Initiate manual upload of records with `priority_` and restart timer if
52 // exists.
53 void Upload();
54
Vignesh Shenvi17227fa2023-11-17 19:07:2855 // Retrieves the reporting destination configured with the `report_queue_`.
Vignesh Shenvi51b90be2023-12-01 01:15:5256 virtual Destination GetDestination() const;
Vignesh Shenvi17227fa2023-11-17 19:07:2857
Ahmed Nasr7fab5292022-01-19 23:57:2858 private:
Ahmed Nasrf8079c032021-10-30 01:35:1959 // Initiate upload of records with `priority_`.
60 virtual void Flush();
61
Ahmed Nasrf8079c032021-10-30 01:35:1962 const std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue_;
63
64 const Priority priority_;
65
66 std::unique_ptr<MetricRateController> rate_controller_;
67};
68} // namespace reporting
69
70#endif // COMPONENTS_REPORTING_METRICS_METRIC_REPORT_QUEUE_H_