chromium/content/browser/tracing/trace_report/trace_report.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 trace_report.mojom;

import "mojo/public/mojom/base/big_buffer.mojom";
import "mojo/public/mojom/base/time.mojom";
import "mojo/public/mojom/base/token.mojom";

// Keep in sync with ReportUploadState from
// content/browser/tracing/trace_report/trace_report_database.h
enum ReportUploadState {
  kNotUploaded = 0,
  kPending = 1,
  kPending_UserRequested = 2,
  kUploaded = 3
};

// Keep in sync with SkipUploadReason from
// content/browser/tracing/trace_report/trace_report_database.h
// TODO: update once the skip reasons have been established.
enum SkipUploadReason {
  kNoSkip = 0,
  kSizeLimitExceeded = 1,
  kNotAnonymized = 2,
  kScenarioQuotaExceeded = 3,
  kUploadTimedOut = 4,
};

// Information about a single trace to display
struct ClientTraceReport {
  // A unique identifier for each trace recorded.
  mojo_base.mojom.Token uuid;

  // The time at which the report was created.
  mojo_base.mojom.Time creation_time;

  // The name of the scenario that trigger this trace to be collected and
  // report to be created.
  string scenario_name;

  // The upload rule name this report needs to respect or this report to be
  // uploaded.
  string upload_rule_name;

  // The total size in bytes taken by the report.
  int64 total_size;

  // The current upload state for this report represented by
  // ReportUploadState enum.
  ReportUploadState upload_state;

  // The time at which the report was successfully uploaded to a server.
  mojo_base.mojom.Time upload_time;

  // The reason for which a report was not uploaded even if the upload rules
  // were met.
  SkipUploadReason skip_reason;

  // Whether the report has content (payload) attached to it.
  bool has_trace_content;
};

struct Scenario {
  string hash;
  string scenario_name;
};

// Used by the WebUI page to bootstrap bidirectional communication.
interface TraceReportHandlerFactory {
  // The WebUI calls this method when the page is first initialized.
  CreatePageHandler(pending_remote<Page> page,
                    pending_receiver<PageHandler> handler);
};

// Browser-side handler for requests from WebUI page.
interface PageHandler {
  // Get visual data for all the traces currently stored locally.
  GetAllTraceReports() => (array<ClientTraceReport> reports);

  // Delete a single trace from the database.
  DeleteSingleTrace(mojo_base.mojom.Token uuid) => (bool success);

  // Delete all traces from the database.
  DeleteAllTraces() => (bool success);

  // Manually upload a trace.
  UserUploadSingleTrace(mojo_base.mojom.Token uuid) => (bool success);

  // Download locally the trace file.
  DownloadTrace(mojo_base.mojom.Token uuid)
    => (mojo_base.mojom.BigBuffer? trace);

  // Get the tracing list of scenarios for local tracing.
  GetAllPresetScenarios() => (array<Scenario> config);

  // Get the tracing list of scenarios for field tracing.
  GetAllFieldScenarios() => (array<Scenario> config);

  // Get enabled tracing scenarios hashes for local tracing.
  GetEnabledScenarios() => (array<string> config);

  // Set the tracing scenario hashes for local tracing.
  SetEnabledScenarios(array<string> new_config) => (bool success);
};

// WebUI-side handler for requests from the browser.
interface Page {
};