constants.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. // Copyright 2020 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef COMPONENTS_SODA_CONSTANTS_H_
  5. #define COMPONENTS_SODA_CONSTANTS_H_
  6. #include <string>
  7. #include "base/files/file_path.h"
  8. #include "components/soda/pref_names.h"
  9. #include "components/strings/grit/components_strings.h"
  10. #include "third_party/abseil-cpp/absl/types/optional.h"
  11. namespace speech {
  12. extern const char kUsEnglishLocale[];
  13. // Metrics names for keeping track of SODA installation.
  14. extern const char kSodaBinaryInstallationResult[];
  15. extern const char kSodaBinaryInstallationSuccessTimeTaken[];
  16. extern const char kSodaBinaryInstallationFailureTimeTaken[];
  17. // These values are persisted to logs. Entries should not be renumbered and
  18. // numeric values should never be reused.
  19. enum class LanguageCode {
  20. kNone = 0,
  21. kEnUs = 1,
  22. kJaJp = 2,
  23. kDeDe = 3,
  24. kEsEs = 4,
  25. kFrFr = 5,
  26. kItIt = 6,
  27. kMaxValue = kItIt,
  28. };
  29. // Describes all metadata needed to dynamically install SODA language pack
  30. // components.
  31. struct SodaLanguagePackComponentConfig {
  32. // The language code of the language pack component.
  33. LanguageCode language_code = LanguageCode::kNone;
  34. // The language name for the language component (e.g. "en-US").
  35. const char* language_name = nullptr;
  36. // The message ID for the display name of the language component (e.g.
  37. // "English").
  38. const int display_name;
  39. // The name of the config file path pref for the language pack.
  40. const char* config_path_pref = nullptr;
  41. // The SHA256 of the SubjectPublicKeyInfo used to sign the language pack
  42. // component.
  43. const uint8_t public_key_sha[32] = {};
  44. };
  45. constexpr SodaLanguagePackComponentConfig kLanguageComponentConfigs[] = {
  46. {LanguageCode::kEnUs,
  47. "en-US",
  48. IDS_SODA_LANGUAGE_DISPLAY_NAME_ENGLISH,
  49. prefs::kSodaEnUsConfigPath,
  50. {0xe4, 0x64, 0x1c, 0xc2, 0x8c, 0x2a, 0x97, 0xa7, 0x16, 0x61, 0xbd,
  51. 0xa9, 0xbe, 0xe6, 0x93, 0x56, 0xf5, 0x05, 0x33, 0x9b, 0x8b, 0x0b,
  52. 0x02, 0xe2, 0x6b, 0x7e, 0x6c, 0x40, 0xa1, 0xd2, 0x7e, 0x18}},
  53. {LanguageCode::kDeDe,
  54. "de-DE",
  55. IDS_SODA_LANGUAGE_DISPLAY_NAME_GERMAN,
  56. prefs::kSodaDeDeConfigPath,
  57. {0x92, 0xb6, 0xd8, 0xa3, 0x0b, 0x09, 0xce, 0x21, 0xdb, 0x68, 0x48,
  58. 0x15, 0xcb, 0x49, 0xd7, 0xc6, 0x21, 0x3f, 0xe5, 0x96, 0x10, 0x97,
  59. 0x6e, 0x0f, 0x08, 0x31, 0xec, 0xe4, 0x7f, 0xed, 0xef, 0x3d}},
  60. {LanguageCode::kEsEs,
  61. "es-ES",
  62. IDS_SODA_LANGUAGE_DISPLAY_NAME_SPANISH,
  63. prefs::kSodaEsEsConfigPath,
  64. {0x9a, 0x22, 0xac, 0x04, 0x97, 0xc1, 0x70, 0x61, 0x24, 0x1f, 0x49,
  65. 0x18, 0x72, 0xd8, 0x67, 0x31, 0x72, 0x7a, 0xf9, 0x77, 0x04, 0xf0,
  66. 0x17, 0xb5, 0xfe, 0x88, 0xac, 0x60, 0xdd, 0x8a, 0x67, 0xdd}},
  67. {LanguageCode::kFrFr,
  68. "fr-FR",
  69. IDS_SODA_LANGUAGE_DISPLAY_NAME_FRENCH,
  70. prefs::kSodaFrFrConfigPath,
  71. {0x6e, 0x0e, 0x2b, 0xd3, 0xc6, 0xe5, 0x1b, 0x5e, 0xfa, 0xef, 0x42,
  72. 0x3f, 0x57, 0xb9, 0x2b, 0x13, 0x56, 0x47, 0x58, 0xdb, 0x76, 0x89,
  73. 0x71, 0xeb, 0x1f, 0xed, 0x48, 0x6c, 0xac, 0xd5, 0x31, 0xa0}},
  74. {LanguageCode::kItIt,
  75. "it-IT",
  76. IDS_SODA_LANGUAGE_DISPLAY_NAME_ITALIAN,
  77. prefs::kSodaItItConfigPath,
  78. {0x97, 0x45, 0xd7, 0xbc, 0xf0, 0x61, 0x24, 0xb3, 0x0e, 0x13, 0xf2,
  79. 0x97, 0xaa, 0xd5, 0x9e, 0x78, 0xa5, 0x81, 0x35, 0x75, 0xb5, 0x9d,
  80. 0x3b, 0xbb, 0xde, 0xba, 0x0e, 0xf7, 0xf0, 0x48, 0x56, 0x01}},
  81. {LanguageCode::kJaJp,
  82. "ja-JP",
  83. IDS_SODA_LANGUAGE_DISPLAY_NAME_JAPANESE,
  84. prefs::kSodaJaJpConfigPath,
  85. {0xed, 0x7f, 0x96, 0xa5, 0x60, 0x9c, 0xaa, 0x4d, 0x80, 0xe5, 0xb8,
  86. 0x26, 0xea, 0xf0, 0x41, 0x50, 0x09, 0x52, 0xa4, 0xb3, 0x1e, 0x6a,
  87. 0x8e, 0x24, 0x99, 0xde, 0x51, 0x14, 0xc4, 0x3c, 0xfa, 0x48}},
  88. };
  89. // Location of the libsoda binary within the SODA installation directory.
  90. extern const base::FilePath::CharType kSodaBinaryRelativePath[];
  91. // Name of the of the libsoda binary used in browser tests.
  92. extern const base::FilePath::CharType kSodaTestBinaryRelativePath[];
  93. // Location of the SODA component relative to the components directory.
  94. extern const base::FilePath::CharType kSodaInstallationRelativePath[];
  95. // Location of the SODA language packs relative to the components
  96. // directory.
  97. extern const base::FilePath::CharType kSodaLanguagePacksRelativePath[];
  98. // Location of the SODA files used in browser tests.
  99. extern const base::FilePath::CharType kSodaTestResourcesRelativePath[];
  100. // Location of the SODA models directory relative to the language pack
  101. // installation directory.
  102. extern const base::FilePath::CharType kSodaLanguagePackDirectoryRelativePath[];
  103. // Get the absolute path of the SODA component directory.
  104. const base::FilePath GetSodaDirectory();
  105. // Get the absolute path of the SODA directory containing the language packs.
  106. const base::FilePath GetSodaLanguagePacksDirectory();
  107. // Get the absolute path of the SODA directory containing the language packs
  108. // used in browser tests.
  109. const base::FilePath GetSodaTestResourcesDirectory();
  110. // Get the absolute path of the latest SODA language pack for a given language
  111. // (e.g. en-US).
  112. const base::FilePath GetLatestSodaLanguagePackDirectory(
  113. const std::string& language);
  114. // Get the directory containing the latest version of SODA. In most cases
  115. // there will only be one version of SODA, but it is possible for there to be
  116. // multiple versions if a newer version of SODA was recently downloaded before
  117. // the old version gets cleaned up. Returns an empty path if SODA is not
  118. // installed.
  119. const base::FilePath GetLatestSodaDirectory();
  120. // Get the path to the SODA binary. Returns an empty path if SODA is not
  121. // installed.
  122. const base::FilePath GetSodaBinaryPath();
  123. // Get the path to the SODA binary used in browser tests. Returns an empty path
  124. // if SODA is not installed.
  125. const base::FilePath GetSodaTestBinaryPath();
  126. absl::optional<SodaLanguagePackComponentConfig> GetLanguageComponentConfig(
  127. LanguageCode language_code);
  128. absl::optional<SodaLanguagePackComponentConfig> GetLanguageComponentConfig(
  129. const std::string& language_name);
  130. LanguageCode GetLanguageCodeByComponentId(const std::string& component_id);
  131. std::string GetLanguageName(LanguageCode language_code);
  132. LanguageCode GetLanguageCode(const std::string& language_name);
  133. int GetLanguageDisplayName(const std::string& language_name);
  134. // Returns the `SodaInstaller.Language.{language}.InstallationSuccessTime` uma
  135. // metric string for the language code.
  136. const std::string GetInstallationSuccessTimeMetricForLanguagePack(
  137. const LanguageCode& language_code);
  138. // Returns the `SodaInstaller.Language.{language}.InstallationFailureTime` uma
  139. // metric string for the language code.
  140. const std::string GetInstallationFailureTimeMetricForLanguagePack(
  141. const LanguageCode& language_code);
  142. // Returns the `SodaInstaller.Language.{language}.InstallationResult` uma
  143. // metric string for the language code..
  144. const std::string GetInstallationResultMetricForLanguagePack(
  145. const LanguageCode& language_code);
  146. } // namespace speech
  147. #endif // COMPONENTS_SODA_CONSTANTS_H_