Avi Drissman | 8ba1bad | 2022-09-13 19:22:36 | [diff] [blame] | 1 | // Copyright 2020 The Chromium Authors |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Akihiro Ota | f297cea | 2021-05-18 22:58:35 | [diff] [blame] | 5 | #ifndef COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_ |
| 6 | #define COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_ |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 7 | |
Edman Anjos | 721a1bd5 | 2024-04-18 13:08:39 | [diff] [blame] | 8 | #include <string_view> |
| 9 | |
Akihiro Ota | cee2d14 | 2021-06-08 00:52:05 | [diff] [blame] | 10 | #include "base/component_export.h" |
Rob Schonberger | d535aca | 2023-08-31 00:10:52 | [diff] [blame] | 11 | #include "base/containers/flat_map.h" |
Rob Schonberger | 72e0103 | 2024-12-09 00:19:59 | [diff] [blame] | 12 | #include "base/containers/flat_set.h" |
Amanda Deacon | a577c77f | 2021-01-28 21:46:16 | [diff] [blame] | 13 | #include "base/files/file_path.h" |
Rob Schonberger | 2d421fc | 2024-11-22 02:29:54 | [diff] [blame] | 14 | #include "base/timer/timer.h" |
Yeunjoo Choi | 0f194fea | 2022-09-13 14:19:24 | [diff] [blame] | 15 | #include "chromeos/ash/components/dbus/dlcservice/dlcservice_client.h" |
Amanda Deacon | 074dfb5d | 2021-05-04 01:19:12 | [diff] [blame] | 16 | #include "components/soda/soda_installer.h" |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 17 | |
| 18 | class PrefService; |
Katie Dektar | f194ea98 | 2021-03-31 19:58:39 | [diff] [blame] | 19 | |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 20 | namespace speech { |
| 21 | |
| 22 | // Installer of SODA (Speech On-Device API) for the Live Caption feature on |
| 23 | // ChromeOS. |
Akihiro Ota | cee2d14 | 2021-06-08 00:52:05 | [diff] [blame] | 24 | class COMPONENT_EXPORT(SODA_INSTALLER) SodaInstallerImplChromeOS |
| 25 | : public SodaInstaller { |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 26 | public: |
evliu | 30abfcb8 | 2021-01-06 19:40:31 | [diff] [blame] | 27 | SodaInstallerImplChromeOS(); |
| 28 | ~SodaInstallerImplChromeOS() override; |
| 29 | SodaInstallerImplChromeOS(const SodaInstallerImplChromeOS&) = delete; |
| 30 | SodaInstallerImplChromeOS& operator=(const SodaInstallerImplChromeOS&) = |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 31 | delete; |
| 32 | |
Amanda Deacon | a577c77f | 2021-01-28 21:46:16 | [diff] [blame] | 33 | // Where the SODA DLC was installed. Cached on completed installation. |
| 34 | // Empty if SODA DLC not installed yet. |
Amanda Deacon | e106337 | 2021-02-03 06:24:09 | [diff] [blame] | 35 | base::FilePath GetSodaBinaryPath() const override; |
| 36 | |
Katie Dektar | 39b78ad7 | 2021-06-25 04:42:24 | [diff] [blame] | 37 | // 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 Deacon | a577c77f | 2021-01-28 21:46:16 | [diff] [blame] | 40 | |
evliu | 30abfcb8 | 2021-01-06 19:40:31 | [diff] [blame] | 41 | // SodaInstaller: |
Amanda Deacon | beecf5e | 2021-05-10 03:47:28 | [diff] [blame] | 42 | void InstallLanguage(const std::string& language, |
Amanda Deacon | d4f30f2 | 2021-04-15 02:23:48 | [diff] [blame] | 43 | PrefService* global_prefs) override; |
evliu | a5e2b46 | 2023-01-12 00:16:16 | [diff] [blame] | 44 | void UninstallLanguage(const std::string& language, |
| 45 | PrefService* global_prefs) override; |
Katie Dektar | 39b78ad7 | 2021-06-25 04:42:24 | [diff] [blame] | 46 | std::vector<std::string> GetAvailableLanguages() const override; |
Rob Schonberger | ab18385 | 2024-08-15 00:15:50 | [diff] [blame] | 47 | std::vector<std::string> GetLiveCaptionEnabledLanguages() const override; |
Andre Le | d5bf86f | 2024-08-22 17:23:16 | [diff] [blame] | 48 | std::string GetLanguageDlcNameForLocale( |
| 49 | const std::string& locale) const override; |
Amanda Deacon | 8193a54 | 2021-03-24 22:56:18 | [diff] [blame] | 50 | |
yilkal | 056006c | 2021-06-07 21:09:35 | [diff] [blame] | 51 | private: |
Amanda Deacon | 8193a54 | 2021-03-24 22:56:18 | [diff] [blame] | 52 | // SodaInstaller: |
Amanda Deacon | 0eb9520 | 2021-04-15 03:39:17 | [diff] [blame] | 53 | void InstallSoda(PrefService* global_prefs) override; |
Amanda Deacon | 3e1e226d | 2021-03-09 01:13:34 | [diff] [blame] | 54 | // 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 Deacon | 460584a | 2021-02-07 23:02:37 | [diff] [blame] | 60 | void UninstallSoda(PrefService* global_prefs) override; |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 61 | |
Rob Schonberger | 72e0103 | 2024-12-09 00:19:59 | [diff] [blame] | 62 | void InstallLanguageInternal(const std::string& language); |
| 63 | |
Amanda Deacon | e106337 | 2021-02-03 06:24:09 | [diff] [blame] | 64 | void SetSodaBinaryPath(base::FilePath new_path); |
Rob Schonberger | d535aca | 2023-08-31 00:10:52 | [diff] [blame] | 65 | void SetLanguagePath(const LanguageCode language, base::FilePath new_path); |
Amanda Deacon | a577c77f | 2021-01-28 21:46:16 | [diff] [blame] | 66 | |
Rob Schonberger | b31ff26 | 2024-03-13 01:19:01 | [diff] [blame] | 67 | // Initializes language and installs the per-language components. |
| 68 | void InitLanguages(PrefService* profile_prefs, |
| 69 | PrefService* global_prefs) override; |
| 70 | |
Amanda Deacon | e106337 | 2021-02-03 06:24:09 | [diff] [blame] | 71 | // These functions are the InstallCallbacks for DlcserviceClient::Install(). |
Abigail Klein | 0130154 | 2021-02-02 04:40:14 | [diff] [blame] | 72 | void OnSodaInstalled( |
yilkal | 0af3d25 | 2022-01-13 22:19:34 | [diff] [blame] | 73 | const base::Time start_time, |
Yeunjoo Choi | 0f194fea | 2022-09-13 14:19:24 | [diff] [blame] | 74 | const ash::DlcserviceClient::InstallResult& install_result); |
Rob Schonberger | 2d421fc | 2024-11-22 02:29:54 | [diff] [blame] | 75 | void OnSodaInstallRetry(); |
Rob Schonberger | 72e0103 | 2024-12-09 00:19:59 | [diff] [blame] | 76 | void OnSodaLanguageInstallRetry(); |
Amanda Deacon | e106337 | 2021-02-03 06:24:09 | [diff] [blame] | 77 | void OnLanguageInstalled( |
yilkal | 0af3d25 | 2022-01-13 22:19:34 | [diff] [blame] | 78 | const LanguageCode language_code, |
Rob Schonberger | 454b0f5 | 2024-04-02 06:24:22 | [diff] [blame] | 79 | const std::string language_name, |
yilkal | 0af3d25 | 2022-01-13 22:19:34 | [diff] [blame] | 80 | const base::Time start_time, |
Yeunjoo Choi | 0f194fea | 2022-09-13 14:19:24 | [diff] [blame] | 81 | const ash::DlcserviceClient::InstallResult& install_result); |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 82 | |
Amanda Deacon | e106337 | 2021-02-03 06:24:09 | [diff] [blame] | 83 | // These functions are the ProgressCallbacks for DlcserviceClient::Install(). |
evliu | 30abfcb8 | 2021-01-06 19:40:31 | [diff] [blame] | 84 | void OnSodaProgress(double progress); |
Rob Schonberger | d535aca | 2023-08-31 00:10:52 | [diff] [blame] | 85 | void OnLanguageProgress(const LanguageCode language_code, double progress); |
Amanda Deacon | e106337 | 2021-02-03 06:24:09 | [diff] [blame] | 86 | |
| 87 | void OnSodaCombinedProgress(); |
| 88 | |
Amanda Deacon | 460584a | 2021-02-07 23:02:37 | [diff] [blame] | 89 | // This is the UninstallCallback for DlcserviceClient::Uninstall(). |
Edman Anjos | 721a1bd5 | 2024-04-18 13:08:39 | [diff] [blame] | 90 | void OnDlcUninstalled(std::string_view dlc_id, std::string_view err); |
Amanda Deacon | 460584a | 2021-02-07 23:02:37 | [diff] [blame] | 91 | |
Amanda Deacon | e106337 | 2021-02-03 06:24:09 | [diff] [blame] | 92 | double soda_progress_ = 0.0; |
Amanda Deacon | a577c77f | 2021-01-28 21:46:16 | [diff] [blame] | 93 | |
Rob Schonberger | 2d421fc | 2024-11-22 02:29:54 | [diff] [blame] | 94 | double soda_backoff_seconds_ = 1.0; |
| 95 | // timer only used for soda install retries. |
| 96 | base::OneShotTimer soda_install_retry_timer_; |
| 97 | |
Rob Schonberger | 72e0103 | 2024-12-09 00:19:59 | [diff] [blame] | 98 | // 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 Deacon | a577c77f | 2021-01-28 21:46:16 | [diff] [blame] | 104 | base::FilePath soda_lib_path_; |
Rob Schonberger | d535aca | 2023-08-31 00:10:52 | [diff] [blame] | 105 | |
| 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 Schonberger | b79d3ba | 2023-09-27 05:17:54 | [diff] [blame] | 112 | base::flat_map<std::string, LanguageInfo> ConstructAvailableLanguages() const; |
Rob Schonberger | d535aca | 2023-08-31 00:10:52 | [diff] [blame] | 113 | |
| 114 | base::flat_map<std::string, LanguageInfo> available_languages_; |
Abigail Klein | 5eb53a4 | 2020-11-08 22:06:15 | [diff] [blame] | 115 | }; |
| 116 | |
| 117 | } // namespace speech |
| 118 | |
Akihiro Ota | f297cea | 2021-05-18 22:58:35 | [diff] [blame] | 119 | #endif // COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_ |