File: soda_installer_impl_chromeos.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (119 lines) | stat: -rw-r--r-- 4,591 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// 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.

#ifndef COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_
#define COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_

#include <string_view>

#include "base/component_export.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/timer/timer.h"
#include "chromeos/ash/components/dbus/dlcservice/dlcservice_client.h"
#include "components/soda/soda_installer.h"

class PrefService;

namespace speech {

// Installer of SODA (Speech On-Device API) for the Live Caption feature on
// ChromeOS.
class COMPONENT_EXPORT(SODA_INSTALLER) SodaInstallerImplChromeOS
    : public SodaInstaller {
 public:
  SodaInstallerImplChromeOS();
  ~SodaInstallerImplChromeOS() override;
  SodaInstallerImplChromeOS(const SodaInstallerImplChromeOS&) = delete;
  SodaInstallerImplChromeOS& operator=(const SodaInstallerImplChromeOS&) =
      delete;

  // Where the SODA DLC was installed. Cached on completed installation.
  // Empty if SODA DLC not installed yet.
  base::FilePath GetSodaBinaryPath() const override;

  // Where the SODA language pack DLC was installed for a given language.
  // Cached on completed installation. Empty if not installed yet.
  base::FilePath GetLanguagePath(const std::string& language) const override;

  // SodaInstaller:
  void InstallLanguage(const std::string& language,
                       PrefService* global_prefs) override;
  void UninstallLanguage(const std::string& language,
                         PrefService* global_prefs) override;
  std::vector<std::string> GetAvailableLanguages() const override;
  std::vector<std::string> GetLiveCaptionEnabledLanguages() const override;
  std::string GetLanguageDlcNameForLocale(
      const std::string& locale) const override;

 private:
  // SodaInstaller:
  void InstallSoda(PrefService* global_prefs) override;
  // Here "uninstall" is used in the DLC sense of the term: Uninstallation will
  // disable a DLC but not immediately remove it from disk.
  // Once a refcount to the DLC reaches 0 (meaning all profiles which had it
  // installed have called to uninstall it), the DLC will remain in cache; if it
  // is then not installed within a (DLC-service-defined) window of time, the
  // DLC is automatically purged from disk.
  void UninstallSoda(PrefService* global_prefs) override;

  void InstallLanguageInternal(const std::string& language);

  void SetSodaBinaryPath(base::FilePath new_path);
  void SetLanguagePath(const LanguageCode language, base::FilePath new_path);

  // Initializes language and installs the per-language components.
  void InitLanguages(PrefService* profile_prefs,
                     PrefService* global_prefs) override;

  // These functions are the InstallCallbacks for DlcserviceClient::Install().
  void OnSodaInstalled(
      const base::Time start_time,
      const ash::DlcserviceClient::InstallResult& install_result);
  void OnSodaInstallRetry();
  void OnSodaLanguageInstallRetry();
  void OnLanguageInstalled(
      const LanguageCode language_code,
      const std::string language_name,
      const base::Time start_time,
      const ash::DlcserviceClient::InstallResult& install_result);

  // These functions are the ProgressCallbacks for DlcserviceClient::Install().
  void OnSodaProgress(double progress);
  void OnLanguageProgress(const LanguageCode language_code, double progress);

  void OnSodaCombinedProgress();

  // This is the UninstallCallback for DlcserviceClient::Uninstall().
  void OnDlcUninstalled(std::string_view dlc_id, std::string_view err);

  double soda_progress_ = 0.0;

  double soda_backoff_seconds_ = 1.0;
  // timer only used for soda install retries.
  base::OneShotTimer soda_install_retry_timer_;

  // timer only used for soda languagepack install retries. We keep them merged
  // as we don't expect independent failures.
  double soda_languagepack_backoff_seconds_ = 1.0;
  base::OneShotTimer languagepack_install_retry_timer_;
  base::flat_set<std::string> retry_languages_to_install_;

  base::FilePath soda_lib_path_;

  base::flat_map<LanguageCode, base::FilePath> installed_language_paths_;

  struct LanguageInfo {
    std::string dlc_name;
    LanguageCode language_code;
  };
  base::flat_map<std::string, LanguageInfo> ConstructAvailableLanguages() const;

  base::flat_map<std::string, LanguageInfo> available_languages_;
};

}  // namespace speech

#endif  // COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_