chromium/chromeos/crosapi/mojom/task_manager.mojom

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

module crosapi.mojom;

import "mojo/public/mojom/base/process_id.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/time.mojom";
import "mojo/public/mojom/base/unguessable_token.mojom";
import "ui/gfx/image/mojom/image.mojom";

[Stable, Extensible]
enum TaskType {
    [Default] kUnknown = 0,

    /* Singleton processes that don't belong to a particular tab. */
    kBrowser,   /* The main browser process. */
    kGpu,       /* A graphics process. */
    kZygote,    /* A Linux zygote process. */
    kUtility,   /* A browser utility process. */

    /* Per-Tab processes. */
    kRenderer,  /* A normal WebContents renderer process. */
    kExtension, /* An extension or app process. */

    /* Plugin processes.*/
    kGuest,            /* A browser plugin guest process. */
    kPlugin,           /* A plugin process. */
    kNacl,             /* A NativeClient loader or broker process. */
    kSandboxHelper,    /* A sandbox helper process. */
    kDedicatedWorker,  /* A dedicated worker running on the renderer process. */
    kSharedWorker,     /* A shared worker running on the renderer process. */
    kServiceWorker,    /* A service worker running on the renderer process. */
};

// A struct mirroring blink::MemoryCache::TypeStatistic.
[Stable]
struct WebCacheResourceTypeStat {
  uint64 count;
  uint64 size;
  uint64 decoded_size;
};

// A struct mirroring blink::MemoryCache::Statistics.
[Stable]
struct WebCacheResourceTypeStats {
  WebCacheResourceTypeStat images;
  WebCacheResourceTypeStat css_style_sheets;
  WebCacheResourceTypeStat scripts;
  WebCacheResourceTypeStat xsl_style_sheets;
  WebCacheResourceTypeStat fonts;
  WebCacheResourceTypeStat other;
};

// A struct represent a task from lacros.
[Stable]
struct Task {
  // Uuid that uniquely identifies the task.
  string task_uuid;
  // Type of lacros task.
  TaskType type;
  // Title of task.
  mojo_base.mojom.String16 title;
  // Process id of task.
  mojo_base.mojom.ProcessId process_id;
  // Icon of task.
  gfx.mojom.ImageSkia? icon;
  // Profile name of task.
  mojo_base.mojom.String16 profile_name;
  // Sqlite used memory in bytes.
  int64 used_sqlite_memory;
  // Allocated v8 memory in bytes.
  int64 v8_memory_allocated;
  // Used v8 memory in bytes.
  int64 v8_memory_used;
  // Webkit resource cache statistics.
  WebCacheResourceTypeStats? web_cache_stats;
  // Keep-alive counter if task is in an event page.
  int64 keep_alive_count;
  // The instantaneous rate, in bytes per second, of network usage
  // (sent and received), as measured over the last refresh cycle.
  int64 network_usage_rate;
  // The cumulative number of bytes of network use (sent and received)
  // over the tasks lifetime.
  int64 cumulative_network_usage;
};

// A struct representing a lacros task group, which is a group of tasks
// whiche share the same process, and the resources associated with it.
[Stable]
struct TaskGroup {
  // Process id of the task group.
  mojo_base.mojom.ProcessId process_id;
  // CPU usage over the most recent refresh cycle. The value is in the range
  // zero to base::SysInfo::NumberOfProcessors() * 100%.
  double platform_independent_cpu_usage;
  // Current memory footprint in bytes.
  int64 memory_footprint_bytes;
  // Current swapped memory in bytes.
  int64 swapped_mem_bytes;
  // GPU memory usage in bytes.
  int64 gpu_memory_bytes;
  // True if this process' GPU resource count is inflated because it is counting
  // other processes' resources.
  bool gpu_memory_has_duplicates;
  // Network usage (in bytes per second) during the current refresh cycle
  // for the process.
  int64 per_process_network_usage_rate;
  // A continuously updating sum of all bytes that have been downloaded and
  // uploaded by all tasks in this process.
  int64 cumulative_per_process_network_usage;
  // Whether the process in a backgrounded process.
  bool is_backgrounded;
  // NaCl GDB debug stub port.
  int64 nacl_debug_stub_port;
  // Number of file descriptors currently open by the process.
  int64 open_fd_count;
  // Number of average idle CPU wakeups per second since the last refresh cycle.
  int64 idle_wakeups_per_second;
};

// Interface for task manager provider. Implemented by lacros-chrome. Used by
// ash-chrome to get lacros task data remotely.
// Next version: 4
// Next method id: 5
[Stable, Uuid="c5073375-8e4b-43c3-85ca-8813adeb0324"]
interface TaskManagerProvider {
  // Deprecated. Use SetRefreshFlags instead.
  DeprecatedSetRefreshArgs@0(mojo_base.mojom.TimeDelta refresh_interval,
      int64 refresh_flags);

  // Gets browser's task data needed for task manager.
  // Returns task data and task group data.
  // Note: SetRefreshFlags must be called before to set the desired refresh
  // interval and refresh flags.
  GetTaskManagerTasks@1()
      => (array<Task> task_results, array<TaskGroup> task_group_results,
          [MinVersion=3] string? active_task_uuid);

  // Notifies Lacros that task manager is closed in ash.
  OnTaskManagerClosed@2();

  // Sets the desired refresh flags, which must be set before calling
  // GetTaskManagerTasks.
  // |refresh_flags| specify the enabled resources types, which is a bit flags
  // from RefreshType enum defined in:
  // chrome/browser/task_manager/task_manager_observer.h
  [MinVersion=1]
  SetRefreshFlags@3(int64 refresh_flags);

  // Activates a lacros task.
  // |task_uuid|: task_uuid of the lacros Task to be activated.
  [MinVersion=2]
  ActivateTask@4(string task_uuid);
};

// Interface for task manager. Implemented by ash-chrome.
// Next version: 2
// Next method id: 2
[Stable, Uuid="c5073375-8e4b-43c3-85ca-8813adeb0324"]
interface TaskManager {
  // A crosapi client can register itself as a task manager provider. This
  // provides ash a mechanism to get task manager data from lacros.
  // The provider is uniquely identified by |token|.
  RegisterTaskManagerProvider@0(
      pending_remote<TaskManagerProvider> provider,
      mojo_base.mojom.UnguessableToken token);

  // Shows the Task Manager window, or re-activates an existing one.
  [MinVersion=1]
  ShowTaskManager@1();
};