@@ -1745,14 +1745,24 @@ const std::vector<std::string> AdsServiceImpl::GetUserModelLanguages() const {
1745
1745
return languages;
1746
1746
}
1747
1747
1748
+ std::string AdsServiceImpl::LoadDataResourceAndDecompressIfNeeded (
1749
+ const int id) const {
1750
+ std::string data_resource;
1751
+
1752
+ if (ui::ResourceBundle::GetSharedInstance ().IsGzipped (id)) {
1753
+ data_resource = ui::ResourceBundle::GetSharedInstance ().DecompressDataResource (id);
1754
+ } else {
1755
+ data_resource = ui::ResourceBundle::GetSharedInstance ().GetRawDataResource (id).as_string ();
1756
+ }
1757
+
1758
+ return data_resource;
1759
+ }
1760
+
1748
1761
void AdsServiceImpl::LoadUserModelForLanguage (
1749
1762
const std::string& language,
1750
1763
ads::OnLoadCallback callback) const {
1751
- auto raw_data = ui::ResourceBundle::GetSharedInstance ().GetRawDataResource (
1752
- GetUserModelResourceId (language));
1753
-
1754
- std::string user_model;
1755
- raw_data.CopyToString (&user_model);
1764
+ const auto resource_id = GetUserModelResourceId (language);
1765
+ const auto user_model = LoadDataResourceAndDecompressIfNeeded (resource_id);
1756
1766
callback (ads::Result::SUCCESS, user_model);
1757
1767
}
1758
1768
@@ -1899,23 +1909,18 @@ void AdsServiceImpl::Reset(
1899
1909
1900
1910
const std::string AdsServiceImpl::LoadJsonSchema (
1901
1911
const std::string& name) {
1902
- base::StringPiece schema_raw =
1903
- ui::ResourceBundle::GetSharedInstance ().GetRawDataResource (
1904
- GetSchemaResourceId (name));
1905
-
1906
- std::string schema;
1907
- schema_raw.CopyToString (&schema);
1908
- return schema;
1912
+ const auto resource_id = GetSchemaResourceId (name);
1913
+ return LoadDataResourceAndDecompressIfNeeded (resource_id);
1909
1914
}
1910
1915
1911
1916
void AdsServiceImpl::LoadSampleBundle (
1912
1917
ads::OnLoadSampleBundleCallback callback) {
1913
- base::StringPiece sample_bundle_raw =
1914
- ui::ResourceBundle::GetSharedInstance ().GetRawDataResource (
1915
- IDR_ADS_SAMPLE_BUNDLE);
1918
+ const auto resource_id =
1919
+ GetSchemaResourceId (ads::_bundle_schema_resource_name);
1920
+
1921
+ const auto sample_bundle =
1922
+ LoadDataResourceAndDecompressIfNeeded (resource_id);
1916
1923
1917
- std::string sample_bundle;
1918
- sample_bundle_raw.CopyToString (&sample_bundle);
1919
1924
callback (ads::Result::SUCCESS, sample_bundle);
1920
1925
}
1921
1926
0 commit comments