| // Copyright 2025 The Chromium Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| import '//resources/js/cr.js'; |
| |
| import {PageCallbackRouter, PageHandlerFactory, PageHandlerRemote} from './reload_button.mojom-webui.js'; |
| import type {PageHandlerInterface} from './reload_button.mojom-webui.js'; |
| |
| export interface BrowserProxy { |
| callbackRouter: PageCallbackRouter; |
| handler: PageHandlerInterface; |
| |
| /** |
| * Records a value in a histogram. |
| * @param histogramName The name of the histogram. |
| * @param value The value to record. |
| * @param maxValue The maximum value of the histogram. |
| */ |
| recordInHistogram(histogramName: string, value: number, maxValue: number): |
| void; |
| } |
| |
| export class BrowserProxyImpl implements BrowserProxy { |
| callbackRouter: PageCallbackRouter; |
| handler: PageHandlerInterface; |
| |
| private constructor() { |
| this.callbackRouter = new PageCallbackRouter(); |
| this.handler = new PageHandlerRemote(); |
| PageHandlerFactory.getRemote().createPageHandler( |
| this.callbackRouter.$.bindNewPipeAndPassRemote(), |
| (this.handler as PageHandlerRemote).$.bindNewPipeAndPassReceiver()); |
| } |
| |
| /** |
| * Records a value in a histogram. |
| * @param histogramName The name of the histogram. |
| * @param value The value to record. |
| * @param maxValue The maximum value of the histogram. |
| */ |
| recordInHistogram(histogramName: string, value: number, maxValue: number) { |
| chrome.send( |
| 'metricsHandler:recordInHistogram', [histogramName, value, maxValue]); |
| } |
| |
| static getInstance(): BrowserProxy { |
| return instance || (instance = new BrowserProxyImpl()); |
| } |
| |
| static setInstance(proxy: BrowserProxy) { |
| instance = proxy; |
| } |
| } |
| |
| let instance: BrowserProxy|null = null; |