Telemetry: Introducing MetricReportQueue class
This class serves as a wrapper of ReportQueue, enable periodic
flush based on policy.
Bug: b:177847653
Change-Id: I40c05e15c5353a3ee3850c549cb5d1d63f9122a8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3247824
Commit-Queue: Ahmed Nasr <[email protected]>
Reviewed-by: Leonid Baraz <[email protected]>
Cr-Commit-Position: refs/heads/main@{#936642}
diff --git a/components/reporting/metrics/metric_report_queue.h b/components/reporting/metrics/metric_report_queue.h
new file mode 100644
index 0000000..b279fc8f
--- /dev/null
+++ b/components/reporting/metrics/metric_report_queue.h
@@ -0,0 +1,61 @@
+// Copyright 2021 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_REPORTING_METRICS_METRIC_REPORT_QUEUE_H_
+#define COMPONENTS_REPORTING_METRICS_METRIC_REPORT_QUEUE_H_
+
+#include <memory>
+#include <string>
+
+#include "base/task/sequenced_task_runner.h"
+#include "base/time/time.h"
+#include "components/reporting/client/report_queue.h"
+#include "components/reporting/proto/synced/record_constants.pb.h"
+
+namespace reporting {
+
+class MetricData;
+class MetricRateController;
+class ReportingSettings;
+
+// Simple wrapper for `::reporting::ReportQueue` that can be set for periodic
+// upload.
+class MetricReportQueue {
+ public:
+ MetricReportQueue(
+ std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue,
+ Priority priority);
+
+ // Constructor used if the reporter is needed to upload records periodically.
+ MetricReportQueue(
+ std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue,
+ Priority priority,
+ ReportingSettings* reporting_settings,
+ const std::string& rate_setting_path,
+ base::TimeDelta default_rate,
+ int rate_unit_to_ms = 1);
+
+ MetricReportQueue() = delete;
+ MetricReportQueue(const MetricReportQueue& other) = delete;
+ MetricReportQueue& operator=(const MetricReportQueue& other) = delete;
+
+ virtual ~MetricReportQueue();
+
+ // Enqueue the metric data.
+ virtual void Enqueue(const MetricData& metric_data,
+ ReportQueue::EnqueueCallback callback);
+
+ // Initiate upload of records with `priority_`.
+ virtual void Flush();
+
+ private:
+ const std::unique_ptr<ReportQueue, base::OnTaskRunnerDeleter> report_queue_;
+
+ const Priority priority_;
+
+ std::unique_ptr<MetricRateController> rate_controller_;
+};
+} // namespace reporting
+
+#endif // COMPONENTS_REPORTING_METRICS_METRIC_REPORT_QUEUE_H_