blob: 5af02dfe183765adc4d095f6136abcdeb4980155 [file] [log] [blame]
Avi Drissman8ba1bad2022-09-13 19:22:361// Copyright 2020 The Chromium Authors
Abigail Klein5eb53a42020-11-08 22:06:152// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Akihiro Otaf297cea2021-05-18 22:58:355#ifndef COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_
6#define COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_
Abigail Klein5eb53a42020-11-08 22:06:157
Edman Anjos721a1bd52024-04-18 13:08:398#include <string_view>
9
Akihiro Otacee2d142021-06-08 00:52:0510#include "base/component_export.h"
Rob Schonbergerd535aca2023-08-31 00:10:5211#include "base/containers/flat_map.h"
Rob Schonberger72e01032024-12-09 00:19:5912#include "base/containers/flat_set.h"
Amanda Deacona577c77f2021-01-28 21:46:1613#include "base/files/file_path.h"
Rob Schonberger2d421fc2024-11-22 02:29:5414#include "base/timer/timer.h"
Yeunjoo Choi0f194fea2022-09-13 14:19:2415#include "chromeos/ash/components/dbus/dlcservice/dlcservice_client.h"
Amanda Deacon074dfb5d2021-05-04 01:19:1216#include "components/soda/soda_installer.h"
Abigail Klein5eb53a42020-11-08 22:06:1517
18class PrefService;
Katie Dektarf194ea982021-03-31 19:58:3919
Abigail Klein5eb53a42020-11-08 22:06:1520namespace speech {
21
22// Installer of SODA (Speech On-Device API) for the Live Caption feature on
23// ChromeOS.
Akihiro Otacee2d142021-06-08 00:52:0524class COMPONENT_EXPORT(SODA_INSTALLER) SodaInstallerImplChromeOS
25 : public SodaInstaller {
Abigail Klein5eb53a42020-11-08 22:06:1526 public:
evliu30abfcb82021-01-06 19:40:3127 SodaInstallerImplChromeOS();
28 ~SodaInstallerImplChromeOS() override;
29 SodaInstallerImplChromeOS(const SodaInstallerImplChromeOS&) = delete;
30 SodaInstallerImplChromeOS& operator=(const SodaInstallerImplChromeOS&) =
Abigail Klein5eb53a42020-11-08 22:06:1531 delete;
32
Amanda Deacona577c77f2021-01-28 21:46:1633 // Where the SODA DLC was installed. Cached on completed installation.
34 // Empty if SODA DLC not installed yet.
Amanda Deacone1063372021-02-03 06:24:0935 base::FilePath GetSodaBinaryPath() const override;
36
Katie Dektar39b78ad72021-06-25 04:42:2437 // Where the SODA language pack DLC was installed for a given language.
38 // Cached on completed installation. Empty if not installed yet.
39 base::FilePath GetLanguagePath(const std::string& language) const override;
Amanda Deacona577c77f2021-01-28 21:46:1640
evliu30abfcb82021-01-06 19:40:3141 // SodaInstaller:
Amanda Deaconbeecf5e2021-05-10 03:47:2842 void InstallLanguage(const std::string& language,
Amanda Deacond4f30f22021-04-15 02:23:4843 PrefService* global_prefs) override;
evliua5e2b462023-01-12 00:16:1644 void UninstallLanguage(const std::string& language,
45 PrefService* global_prefs) override;
Katie Dektar39b78ad72021-06-25 04:42:2446 std::vector<std::string> GetAvailableLanguages() const override;
Rob Schonbergerab183852024-08-15 00:15:5047 std::vector<std::string> GetLiveCaptionEnabledLanguages() const override;
Andre Led5bf86f2024-08-22 17:23:1648 std::string GetLanguageDlcNameForLocale(
49 const std::string& locale) const override;
Amanda Deacon8193a542021-03-24 22:56:1850
yilkal056006c2021-06-07 21:09:3551 private:
Amanda Deacon8193a542021-03-24 22:56:1852 // SodaInstaller:
Amanda Deacon0eb95202021-04-15 03:39:1753 void InstallSoda(PrefService* global_prefs) override;
Amanda Deacon3e1e226d2021-03-09 01:13:3454 // Here "uninstall" is used in the DLC sense of the term: Uninstallation will
55 // disable a DLC but not immediately remove it from disk.
56 // Once a refcount to the DLC reaches 0 (meaning all profiles which had it
57 // installed have called to uninstall it), the DLC will remain in cache; if it
58 // is then not installed within a (DLC-service-defined) window of time, the
59 // DLC is automatically purged from disk.
Amanda Deacon460584a2021-02-07 23:02:3760 void UninstallSoda(PrefService* global_prefs) override;
Abigail Klein5eb53a42020-11-08 22:06:1561
Rob Schonberger72e01032024-12-09 00:19:5962 void InstallLanguageInternal(const std::string& language);
63
Amanda Deacone1063372021-02-03 06:24:0964 void SetSodaBinaryPath(base::FilePath new_path);
Rob Schonbergerd535aca2023-08-31 00:10:5265 void SetLanguagePath(const LanguageCode language, base::FilePath new_path);
Amanda Deacona577c77f2021-01-28 21:46:1666
Rob Schonbergerb31ff262024-03-13 01:19:0167 // Initializes language and installs the per-language components.
68 void InitLanguages(PrefService* profile_prefs,
69 PrefService* global_prefs) override;
70
Amanda Deacone1063372021-02-03 06:24:0971 // These functions are the InstallCallbacks for DlcserviceClient::Install().
Abigail Klein01301542021-02-02 04:40:1472 void OnSodaInstalled(
yilkal0af3d252022-01-13 22:19:3473 const base::Time start_time,
Yeunjoo Choi0f194fea2022-09-13 14:19:2474 const ash::DlcserviceClient::InstallResult& install_result);
Rob Schonberger2d421fc2024-11-22 02:29:5475 void OnSodaInstallRetry();
Rob Schonberger72e01032024-12-09 00:19:5976 void OnSodaLanguageInstallRetry();
Amanda Deacone1063372021-02-03 06:24:0977 void OnLanguageInstalled(
yilkal0af3d252022-01-13 22:19:3478 const LanguageCode language_code,
Rob Schonberger454b0f52024-04-02 06:24:2279 const std::string language_name,
yilkal0af3d252022-01-13 22:19:3480 const base::Time start_time,
Yeunjoo Choi0f194fea2022-09-13 14:19:2481 const ash::DlcserviceClient::InstallResult& install_result);
Abigail Klein5eb53a42020-11-08 22:06:1582
Amanda Deacone1063372021-02-03 06:24:0983 // These functions are the ProgressCallbacks for DlcserviceClient::Install().
evliu30abfcb82021-01-06 19:40:3184 void OnSodaProgress(double progress);
Rob Schonbergerd535aca2023-08-31 00:10:5285 void OnLanguageProgress(const LanguageCode language_code, double progress);
Amanda Deacone1063372021-02-03 06:24:0986
87 void OnSodaCombinedProgress();
88
Amanda Deacon460584a2021-02-07 23:02:3789 // This is the UninstallCallback for DlcserviceClient::Uninstall().
Edman Anjos721a1bd52024-04-18 13:08:3990 void OnDlcUninstalled(std::string_view dlc_id, std::string_view err);
Amanda Deacon460584a2021-02-07 23:02:3791
Amanda Deacone1063372021-02-03 06:24:0992 double soda_progress_ = 0.0;
Amanda Deacona577c77f2021-01-28 21:46:1693
Rob Schonberger2d421fc2024-11-22 02:29:5494 double soda_backoff_seconds_ = 1.0;
95 // timer only used for soda install retries.
96 base::OneShotTimer soda_install_retry_timer_;
97
Rob Schonberger72e01032024-12-09 00:19:5998 // timer only used for soda languagepack install retries. We keep them merged
99 // as we don't expect independent failures.
100 double soda_languagepack_backoff_seconds_ = 1.0;
101 base::OneShotTimer languagepack_install_retry_timer_;
102 base::flat_set<std::string> retry_languages_to_install_;
103
Amanda Deacona577c77f2021-01-28 21:46:16104 base::FilePath soda_lib_path_;
Rob Schonbergerd535aca2023-08-31 00:10:52105
106 base::flat_map<LanguageCode, base::FilePath> installed_language_paths_;
107
108 struct LanguageInfo {
109 std::string dlc_name;
110 LanguageCode language_code;
111 };
Rob Schonbergerb79d3ba2023-09-27 05:17:54112 base::flat_map<std::string, LanguageInfo> ConstructAvailableLanguages() const;
Rob Schonbergerd535aca2023-08-31 00:10:52113
114 base::flat_map<std::string, LanguageInfo> available_languages_;
Abigail Klein5eb53a42020-11-08 22:06:15115};
116
117} // namespace speech
118
Akihiro Otaf297cea2021-05-18 22:58:35119#endif // COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_