blob: 0df36f75635add2fbe0591dde9442a0de1c83c4d [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"
Amanda Deacona577c77f2021-01-28 21:46:1612#include "base/files/file_path.h"
Yeunjoo Choi0f194fea2022-09-13 14:19:2413#include "chromeos/ash/components/dbus/dlcservice/dlcservice_client.h"
Amanda Deacon074dfb5d2021-05-04 01:19:1214#include "components/soda/soda_installer.h"
Abigail Klein5eb53a42020-11-08 22:06:1515
16class PrefService;
Katie Dektarf194ea982021-03-31 19:58:3917
Abigail Klein5eb53a42020-11-08 22:06:1518namespace speech {
19
20// Installer of SODA (Speech On-Device API) for the Live Caption feature on
21// ChromeOS.
Akihiro Otacee2d142021-06-08 00:52:0522class COMPONENT_EXPORT(SODA_INSTALLER) SodaInstallerImplChromeOS
23 : public SodaInstaller {
Abigail Klein5eb53a42020-11-08 22:06:1524 public:
evliu30abfcb82021-01-06 19:40:3125 SodaInstallerImplChromeOS();
26 ~SodaInstallerImplChromeOS() override;
27 SodaInstallerImplChromeOS(const SodaInstallerImplChromeOS&) = delete;
28 SodaInstallerImplChromeOS& operator=(const SodaInstallerImplChromeOS&) =
Abigail Klein5eb53a42020-11-08 22:06:1529 delete;
30
Amanda Deacona577c77f2021-01-28 21:46:1631 // Where the SODA DLC was installed. Cached on completed installation.
32 // Empty if SODA DLC not installed yet.
Amanda Deacone1063372021-02-03 06:24:0933 base::FilePath GetSodaBinaryPath() const override;
34
Katie Dektar39b78ad72021-06-25 04:42:2435 // Where the SODA language pack DLC was installed for a given language.
36 // Cached on completed installation. Empty if not installed yet.
37 base::FilePath GetLanguagePath(const std::string& language) const override;
Amanda Deacona577c77f2021-01-28 21:46:1638
evliu30abfcb82021-01-06 19:40:3139 // SodaInstaller:
Amanda Deaconbeecf5e2021-05-10 03:47:2840 void InstallLanguage(const std::string& language,
Amanda Deacond4f30f22021-04-15 02:23:4841 PrefService* global_prefs) override;
evliua5e2b462023-01-12 00:16:1642 void UninstallLanguage(const std::string& language,
43 PrefService* global_prefs) override;
Katie Dektar39b78ad72021-06-25 04:42:2444 std::vector<std::string> GetAvailableLanguages() const override;
Rob Schonbergerab183852024-08-15 00:15:5045 std::vector<std::string> GetLiveCaptionEnabledLanguages() const override;
Andre Led5bf86f2024-08-22 17:23:1646 std::string GetLanguageDlcNameForLocale(
47 const std::string& locale) const override;
Amanda Deacon8193a542021-03-24 22:56:1848
yilkal056006c2021-06-07 21:09:3549 private:
Amanda Deacon8193a542021-03-24 22:56:1850 // SodaInstaller:
Amanda Deacon0eb95202021-04-15 03:39:1751 void InstallSoda(PrefService* global_prefs) override;
Amanda Deacon3e1e226d2021-03-09 01:13:3452 // Here "uninstall" is used in the DLC sense of the term: Uninstallation will
53 // disable a DLC but not immediately remove it from disk.
54 // Once a refcount to the DLC reaches 0 (meaning all profiles which had it
55 // installed have called to uninstall it), the DLC will remain in cache; if it
56 // is then not installed within a (DLC-service-defined) window of time, the
57 // DLC is automatically purged from disk.
Amanda Deacon460584a2021-02-07 23:02:3758 void UninstallSoda(PrefService* global_prefs) override;
Abigail Klein5eb53a42020-11-08 22:06:1559
Amanda Deacone1063372021-02-03 06:24:0960 void SetSodaBinaryPath(base::FilePath new_path);
Rob Schonbergerd535aca2023-08-31 00:10:5261 void SetLanguagePath(const LanguageCode language, base::FilePath new_path);
Amanda Deacona577c77f2021-01-28 21:46:1662
Rob Schonbergerb31ff262024-03-13 01:19:0163 // Initializes language and installs the per-language components.
64 void InitLanguages(PrefService* profile_prefs,
65 PrefService* global_prefs) override;
66
Amanda Deacone1063372021-02-03 06:24:0967 // These functions are the InstallCallbacks for DlcserviceClient::Install().
Abigail Klein01301542021-02-02 04:40:1468 void OnSodaInstalled(
yilkal0af3d252022-01-13 22:19:3469 const base::Time start_time,
Yeunjoo Choi0f194fea2022-09-13 14:19:2470 const ash::DlcserviceClient::InstallResult& install_result);
Amanda Deacone1063372021-02-03 06:24:0971 void OnLanguageInstalled(
yilkal0af3d252022-01-13 22:19:3472 const LanguageCode language_code,
Rob Schonberger454b0f52024-04-02 06:24:2273 const std::string language_name,
yilkal0af3d252022-01-13 22:19:3474 const base::Time start_time,
Yeunjoo Choi0f194fea2022-09-13 14:19:2475 const ash::DlcserviceClient::InstallResult& install_result);
Abigail Klein5eb53a42020-11-08 22:06:1576
Amanda Deacone1063372021-02-03 06:24:0977 // These functions are the ProgressCallbacks for DlcserviceClient::Install().
evliu30abfcb82021-01-06 19:40:3178 void OnSodaProgress(double progress);
Rob Schonbergerd535aca2023-08-31 00:10:5279 void OnLanguageProgress(const LanguageCode language_code, double progress);
Amanda Deacone1063372021-02-03 06:24:0980
81 void OnSodaCombinedProgress();
82
Amanda Deacon460584a2021-02-07 23:02:3783 // This is the UninstallCallback for DlcserviceClient::Uninstall().
Edman Anjos721a1bd52024-04-18 13:08:3984 void OnDlcUninstalled(std::string_view dlc_id, std::string_view err);
Amanda Deacon460584a2021-02-07 23:02:3785
Amanda Deacone1063372021-02-03 06:24:0986 double soda_progress_ = 0.0;
Amanda Deacona577c77f2021-01-28 21:46:1687
88 base::FilePath soda_lib_path_;
Rob Schonbergerd535aca2023-08-31 00:10:5289
90 base::flat_map<LanguageCode, base::FilePath> installed_language_paths_;
91
92 struct LanguageInfo {
93 std::string dlc_name;
94 LanguageCode language_code;
95 };
Rob Schonbergerb79d3ba2023-09-27 05:17:5496 base::flat_map<std::string, LanguageInfo> ConstructAvailableLanguages() const;
Rob Schonbergerd535aca2023-08-31 00:10:5297
98 base::flat_map<std::string, LanguageInfo> available_languages_;
Abigail Klein5eb53a42020-11-08 22:06:1599};
100
101} // namespace speech
102
Akihiro Otaf297cea2021-05-18 22:58:35103#endif // COMPONENTS_SODA_SODA_INSTALLER_IMPL_CHROMEOS_H_