[fuchsia] Flush LegacyMetricsClient buffer for OnCloseSoon FIDL event.
Handles the fuchsia.legacymetrics.MetricsRecorder OnCloseSoon() event.
It is sent by the service to request that its clients deliver any
buffered metrics data prior to an impending orderly shutdown.
Bug: 1087971
Change-Id: I5eb76bb2362dc372890cdea32e4a56a77265951e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2225578
Commit-Queue: Kevin Marshall <[email protected]>
Reviewed-by: Sergey Ulanov <[email protected]>
Cr-Commit-Position: refs/heads/master@{#775342}
diff --git a/fuchsia/base/legacymetrics_client.h b/fuchsia/base/legacymetrics_client.h
index 98576a1..b9ec76a2 100644
--- a/fuchsia/base/legacymetrics_client.h
+++ b/fuchsia/base/legacymetrics_client.h
@@ -31,6 +31,8 @@
using ReportAdditionalMetricsCallback = base::RepeatingCallback<void(
base::OnceCallback<void(std::vector<fuchsia::legacymetrics::Event>)>)>;
+ using NotifyFlushCallback =
+ base::OnceCallback<void(base::OnceClosure completion_cb)>;
LegacyMetricsClient();
~LegacyMetricsClient();
@@ -50,18 +52,27 @@
void SetReportAdditionalMetricsCallback(
ReportAdditionalMetricsCallback callback);
+ // Sets a |callback| which is invoked to warn that the connection to the
+ // remote MetricsRecorder will be terminated. The completion closure passed to
+ // |callback| should be invoked to signal flush completion.
+ void SetNotifyFlushCallback(NotifyFlushCallback callback);
+
private:
void ScheduleNextReport();
void StartReport();
void Report(std::vector<fuchsia::legacymetrics::Event> additional_metrics);
void OnMetricsRecorderDisconnected(zx_status_t status);
+ void OnCloseSoon();
- // Incrementally sends the contents of |buffer| to |metrics_recorder|, and
- // invokes |done_cb| when finished.
- void DrainBuffer(std::vector<fuchsia::legacymetrics::Event> buffer);
+ // Incrementally sends the contents of |to_send_| to |metrics_recorder_|.
+ void DrainBuffer();
base::TimeDelta report_interval_;
ReportAdditionalMetricsCallback report_additional_callback_;
+ NotifyFlushCallback notify_flush_callback_;
+ bool is_flushing_ = false;
+ bool record_ack_pending_ = false;
+ std::vector<fuchsia::legacymetrics::Event> to_send_;
std::unique_ptr<LegacyMetricsUserActionRecorder> user_events_recorder_;
fuchsia::legacymetrics::MetricsRecorderPtr metrics_recorder_;