chromium/chromeos/ash/components/language_packs/public/mojom/language_packs.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.

// Private API exposed by Language Packs.
// It allows clients to check, request and observe the files managed by
// Language Packs.

module ash.language.mojom;

// ID of the Feature using LanguagePacks.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused. When adding new enumerations to this
// enum, you must add those to the LanguagePackMojoFeatureId definition in
// tools/metrics/histograms/enums.xml to keep them in sync.
// Next MinVersion: 2
// TODO(b/335692393): Add a default value for FeatureId.
[Extensible]
enum FeatureId {
  // Unknown feature, not supported.
  UNSUPPORTED_UNKNOWN = 0,
  // Handwriting Recognition used by the Virtual Keyboard.
  HANDWRITING_RECOGNITION = 1,
  // Text-To-Speech feature.
  [MinVersion=1] TTS = 2,
};

// Current state of Pack on disk.
// INSTALLED means that it's mounted and can be used.
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused.  When adding new enumerations to this
// enum, you must add those to the LanguagePackMojoPackState definition in
// tools/metrics/histograms/enums.xml to keep them in sync.
// Next MinVersion: 4
[Extensible]
enum PackState {
  // TODO: b/294162606 - Deprecate this value and use UNKNOWN instead.
  ERROR = 0,
  NOT_INSTALLED = 1,
  INSTALLING = 2,
  INSTALLED = 3,
  [MinVersion=3, Default] UNKNOWN = 4
};

// The error that is encountered when performing an IPC operation.
// Next MinVersion: 1
[Extensible]
enum ErrorCode {
  [Default] kUnknown = 0,
  kNone = 1,
  kOther = 2,
  kWrongId = 3,
  kNeedReboot = 4,
  kAllocation = 5
};

// This struct holds information that allows clients to use a Language Pack.
// Next MinVersion: 4
struct LanguagePackInfo {
  PackState pack_state;
  string path;
  [MinVersion=2] ErrorCode error;
  [MinVersion=3] FeatureId feature_id;
  [MinVersion=3] string? locale;
};

// This struct holds information that allows clients to use a Base Pack.
// Next MinVersion: 3
struct BasePackInfo {
  PackState pack_state;
  string path;
  [MinVersion=2] ErrorCode error;
};

// Interface for observing Language Packs.
// It allows clients to get notifications when the state of a Language Pack
// changes.
// Next ordinal: 1
// Next MinVersion: 1
interface LanguagePacksObserver {
  // Called whenever the state of a Language Pack is changed.
  OnPackStateChanged@0(LanguagePackInfo info);
};

// Interface for managing Language Packs.
// It allows clients to get information about a Language Pack or to alter the
// installation of one.
// Language Packs are mounted to the user partition once they are installed and
// this interface allows to get the path to the files.
// Next ordinal: 5
// Next MinVersion: 2
interface LanguagePacks {
  // Gets information about the current state of a Language Pack.
  // Takes the id of the feature (for example handwriting) and the language.
  // It returns |info| which contains details about the pack and error
  // information if any.
  GetPackInfo@0(FeatureId feature_id, string language) =>
      (LanguagePackInfo info);

  // Requests to install a Language Pack.
  // Takes the id of the feature (for example handwriting) and the language.
  // It returns |info| which contains details about the pack and error
  // information if any.
  InstallPack@1(FeatureId feature_id, string language) =>
      (LanguagePackInfo info);

  // Requests to install the Base Pack for a `feature_id`.
  // The Base Pack contains the dependencies needed for a Language Pack to
  // function correctly.
  // Takes the id of the feature (for example handwriting).
  // If there's no Base Pack for the specified feature, then `info` will have an
  // ERROR PackState.
  InstallBasePack@2(FeatureId feature_id) =>
      (BasePackInfo info);

  // Requests to uninstall a Language Pack.
  // Takes the id of the feature (for example handwriting) and the language.
  UninstallPack@3(FeatureId feature_id, string language) => ();

  // Adds an observer to observe Language Packs. Observers can live in the
  // browser, renderer, or extension process.
  [MinVersion=1] AddObserver@4(
      pending_associated_remote<LanguagePacksObserver> observer);
};