chromium/chrome/browser/resources/ash/settings/os_apps_page/app_management_page/plugin_vm_page/plugin_vm_browser_proxy.ts

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/**
 * @fileoverview A helper object used by the Plugin VM section
 * to manage the Plugin VM.
 */

import {sendWithPromise} from 'chrome://resources/js/cr.js';

export interface PluginVmBrowserProxy {
  isRelaunchNeededForNewPermissions(): Promise<boolean>;
  relaunchPluginVm(): void;
}

let instance: PluginVmBrowserProxy|null = null;

export class PluginVmBrowserProxyImpl implements PluginVmBrowserProxy {
  static getInstance(): PluginVmBrowserProxy {
    return instance || (instance = new PluginVmBrowserProxyImpl());
  }

  static setInstanceForTesting(obj: PluginVmBrowserProxy): void {
    instance = obj;
  }

  isRelaunchNeededForNewPermissions(): Promise<boolean> {
    return sendWithPromise('isRelaunchNeededForNewPermissions');
  }

  relaunchPluginVm(): void {
    chrome.send('relaunchPluginVm');
  }
}