chromium/chromeos/ash/services/libassistant/public/mojom/service_controller.mojom

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

module ash.libassistant.mojom;

import "chromeos/ash/services/libassistant/public/mojom/settings_controller.mojom";
import "services/network/public/mojom/url_loader_factory.mojom";

enum ServiceState {
  // The service has been started but is not ready yet to handle queries.
  kStarted,
  // The service is ready to handle queries.
  kRunning,
  // The service is not running.
  kStopped,
  // The service is disconnected. This is different than `kStopped` because
  // `disconnected` is unexpected. This is used to inform the observers so that
  // the service could be restarted automatically.
  kDisconnected,
};

// Interface managing the lifecycle of Libassistant,
// exposing methods to start/stop and configure Libassistant.
interface ServiceController {
  // Initialize the service. This must be called before Start() and before
  // restarting the service (so between all Stop() and Start() calls).
  // Will be a noop if the service is started or running.
  // Note that calling Initialize() will not cause any change in the service
  // state, as the service will remain in state |kStopped| until Start() is
  // called.
  Initialize(BootupConfig bootup_config,
      pending_remote<network.mojom.URLLoaderFactory> url_loading_factory);

  // Start the service. Can be called multiple times, and will be a noop if
  // the service is already started or running.
  Start();

  // Stop the service. Will be a noop if the service is already stopped.
  Stop();

  // Stop the service, and erase all config files and user data.
  // Will be a noop if the service is already stopped.
  ResetAllDataAndStop();

  // Add a state observer. It will immediately be called with the current state,
  // and then once for each state change.
  AddAndFireStateObserver(pending_remote<StateObserver> observer);
};

// Observer that will be informed whenever the running state of the service
// changes.
interface StateObserver {
  // Called when the running state of the service changes.
  // Will never be called twice consecutively with the same state.
  OnStateChanged(ServiceState new_state);
};

// Configuration settings that must be set to allow Libassistant to boot.
struct BootupConfig {
  // A custom URI for the S3 Server. Used to use a fake S3 server during
  // unittests.
  string? s3_server_uri_override;
  // A custom device id. Used during unittests.
  string? device_id_override;

  array<AuthenticationToken> authentication_tokens;
  string locale;
  bool spoken_feedback_enabled;
  bool dark_mode_enabled;
  bool hotword_enabled;
};