chromium/chrome/browser/ui/webui/suggest_internals/suggest_internals.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 suggest_internals.mojom;

import "mojo/public/mojom/base/unguessable_token.mojom";
import "url/mojom/url.mojom";
import "mojo/public/mojom/base/time.mojom";

enum RequestStatus {
  kHardcoded = 0,
  kCreated = 1,
  kSent = 2,
  kSucceeded = 3,
  kFailed = 4,
};

// Represents a suggest request and its associated metadata and response.
struct Request {
  // The unique identifier of the request.
  mojo_base.mojom.UnguessableToken id;

  // The request URL.
  url.mojom.Url url;

  // A key/value map of the request data such as the HTTP method (e.g., GET) and
  // the variations header (i.e., X-Client-Data).
  map<string, string> data;

  // The status of the request. Updated after the request has completed.
  RequestStatus status;

  // The request start timestamp.
  mojo_base.mojom.Time start_time;

  // The request completion timestamp. Set after the request has completed.
  mojo_base.mojom.Time end_time;

  // The response body for the request. Set after the request has completed.
  string response;
};

// Browser-side handler for requests from WebUI page.
interface PageHandler {
  // Called by the page when first initialized.
  SetPage(pending_remote<Page> page);
  // Called by the page to hardcode a given response for all suggest requests.
  // The returned promise is a synthetic request with the hardcoded response.
  HardcodeResponse(string response) => (Request request);
};

// WebUI-side handler for requests from the browser.
interface Page {
  // Notifies the page that the given request has been created.
  OnSuggestRequestCreated(Request request);
  // Notifies the page that the given request has started.
  OnSuggestRequestStarted(Request request);
  // Notifies the page that the given request has completed.
  OnSuggestRequestCompleted(Request request);
};