chromium/third_party/blink/public/mojom/chromeos/diagnostics/cros_diagnostics.mojom

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

module blink.mojom;

// ChromeOS Diagnostics API.
//
// Prototype API used to retrieve diagnostics information from the system, e.g.
// CPU/memory usage statistics and OS information.
//
// This interface is used in blink by blink::CrosDiagnostics which is enabled
// when `BlinkExtensionChromeOSDiagnostics` is enabled. On the browser side this
// interface is implemented by CrosDiagnosticsImpl whose lifetime is tied to the
// document. There's a 1:1 relationship between CrosDiagnosticsImpl and the
// document. This interface is only bound if `CrosDiagnosticsApi` is enabled.
interface CrosDiagnostics {
  // Retrieves diagnostics information of the CPU.
  //
  // The response:
  // * |result| - union containing diagnostics information of the CPU, e.g.
  //   model name, utilization and temperature, or error.
  GetCpuInfo() => (GetCpuInfoResult result);

  // Retrieves diagnostics information on network interfaces.
  //
  // The response:
  // * |result| - union containing diagnostics information on each network
  //   interface attached to the system, e.g. network name and the associated IP
  //   address.
  GetNetworkInterfaces() => (GetNetworkInterfacesResult network_interfaces);
};

// Error codes used by the getCpuInfo() method.
enum GetCpuInfoError {
  // TelemetryProbeService is unavailable.
  kTelemetryProbeServiceUnavailable,

  // TelemetryProbeService returned an error when retrieving CPU telemetry info.
  kCpuTelemetryInfoUnavailable,
};

// Error codes used by the getNetworkInterfaces() method.
enum GetNetworkInterfacesError {
  // Network interface lookup failed or unsupported.
  kNetworkInterfaceLookupFailed,
};

// An enumeration of CPU architectures.
enum CrosCpuArchitecture {
  kUnknown,
  kX86_64,
  kArm,
  kArm64,
};

// Diagnostics information of the CPU, e.g. model name, utilization and
// temperature.
struct CrosCpuInfo {
  // The architecture of the CPU, represented by the CrosCpuArchitecture enumeration.
  CrosCpuArchitecture architecture;

  // The model name of the CPU, e.g. "AMD Ryzen 7 7840U", "Intel Core i7-1370P".
  string model_name;

  // Information on each logical processor available to the system.
  array<CrosLogicalCpuInfo> logical_cpus;
};


// Diagnostics information of a logical processor, e.g. core ID, current clock speed
// and max clock speed.
struct CrosLogicalCpuInfo {
  // The core number this logical processor corresponds to.
  uint32? core_id;

  // Idle time since last boot, in milliseconds.
  uint64? idle_time_ms;

  // The max processor clock speed in kHz.
  uint32? max_clock_speed_khz;

  // Current frequency the processor is running at.
  uint32? scaling_current_frequency_khz;

  // Maximum frequency the processor is allowed to run at, by policy.
  uint32? scaling_max_frequency_khz;
};

// Diagnostics information of a network interface, e.g. network name and
// the associated IP address.
struct CrosNetworkInterface {
  // The associated IPv4/6 address.
  string address;

  // The name of the network interface, e.g. "eth0", "wlan0".
  string name;

  // The prefix length of the network.
  uint32 prefix_length;
};

// The response from the getCpuInfo() method.
union GetCpuInfoResult {
  // Returned on success.
  CrosCpuInfo cpu_info;

  // Returned on encountering an error.
  GetCpuInfoError error;
};

// The response from the getNetworkInterfaces() method.
union GetNetworkInterfacesResult {
  // Returned on success.
  array<CrosNetworkInterface> network_interfaces;

  // Returned on encountering an error.
  GetNetworkInterfacesError error;
};