xref: /aosp_15_r20/external/cronet/components/metrics/debug/structured/structured_metrics_browser_proxy.ts (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1// Copyright 2024 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/**
6 * @fileoverview A helper object used by the
7 * chrome://metrics-internals/structured page to interact with the browser.
8 */
9
10import {sendWithPromise} from 'chrome://resources/js/cr.js';
11
12import type {StructuredMetricEvent, StructuredMetricsSummary} from './structured_utils.js';
13
14export interface StructuredMetricsBrowserProxy {
15  /**
16   * Fetches recorded events from Structured Metrics Service.
17   */
18  fetchStructuredMetricsEvents(): Promise<StructuredMetricEvent[]>;
19
20  /**
21   * Fetches a summary of the Structured Metrics Service.
22   */
23  fetchStructuredMetricsSummary(): Promise<StructuredMetricsSummary>;
24}
25
26export class StructuredMetricsBrowserProxyImpl implements
27    StructuredMetricsBrowserProxy {
28  fetchStructuredMetricsEvents() {
29    return sendWithPromise('fetchStructuredMetricsEvents');
30  }
31
32  fetchStructuredMetricsSummary() {
33    return sendWithPromise('fetchStructuredMetricsSummary');
34  }
35
36  static getInstance() {
37    return instance || (instance = new StructuredMetricsBrowserProxyImpl());
38  }
39}
40
41let instance: StructuredMetricsBrowserProxy|null = null;
42