blob: b279fc8fde8d324582ebc36feb2a3a8246ca0a9e [file] [log] [blame]
Ahmed Nasrf8079c032021-10-30 01:35:191// Copyright 2021 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
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
11#include "base/task/sequenced_task_runner.h"
12#include "base/time/time.h"
13#include "components/reporting/client/report_queue.h"
14#include "components/reporting/proto/synced/record_constants.pb.h"
15
16namespace reporting {
17
18class MetricData;
19class MetricRateController;
20class ReportingSettings;
21
22// Simple wrapper for `::reporting::ReportQueue` that can be set for periodic
23// upload.
24class MetricReportQueue {
25 public:
26 MetricReportQueue(
27 std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue,
28 Priority priority);
29
30 // Constructor used if the reporter is needed to upload records periodically.
31 MetricReportQueue(
32 std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue,
33 Priority priority,
34 ReportingSettings* reporting_settings,
35 const std::string& rate_setting_path,
36 base::TimeDelta default_rate,
37 int rate_unit_to_ms = 1);
38
39 MetricReportQueue() = delete;
40 MetricReportQueue(const MetricReportQueue& other) = delete;
41 MetricReportQueue& operator=(const MetricReportQueue& other) = delete;
42
43 virtual ~MetricReportQueue();
44
45 // Enqueue the metric data.
46 virtual void Enqueue(const MetricData& metric_data,
47 ReportQueue::EnqueueCallback callback);
48
49 // Initiate upload of records with `priority_`.
50 virtual void Flush();
51
52 private:
53 const std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue_;
54
55 const Priority priority_;
56
57 std::unique_ptr<MetricRateController> rate_controller_;
58};
59} // namespace reporting
60
61#endif // COMPONENTS_REPORTING_METRICS_METRIC_REPORT_QUEUE_H_