@@ -1745,14 +1745,25 @@ 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
+ auto & resource_bundle = ui::ResourceBundle::GetSharedInstance ();
1753
+ if (resource_bundle.IsGzipped (id)) {
1754
+ data_resource = resource_bundle.DecompressDataResource (id);
1755
+ } else {
1756
+ data_resource = resource_bundle.GetRawDataResource (id).as_string ();
1757
+ }
1758
+
1759
+ return data_resource;
1760
+ }
1761
+
1748
1762
void AdsServiceImpl::LoadUserModelForLanguage (
1749
1763
const std::string& language,
1750
1764
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);
1765
+ const auto resource_id = GetUserModelResourceId (language);
1766
+ const auto user_model = LoadDataResourceAndDecompressIfNeeded (resource_id);
1756
1767
callback (ads::Result::SUCCESS, user_model);
1757
1768
}
1758
1769
@@ -1899,23 +1910,18 @@ void AdsServiceImpl::Reset(
1899
1910
1900
1911
const std::string AdsServiceImpl::LoadJsonSchema (
1901
1912
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;
1913
+ const auto resource_id = GetSchemaResourceId (name);
1914
+ return LoadDataResourceAndDecompressIfNeeded (resource_id);
1909
1915
}
1910
1916
1911
1917
void AdsServiceImpl::LoadSampleBundle (
1912
1918
ads::OnLoadSampleBundleCallback callback) {
1913
- base::StringPiece sample_bundle_raw =
1914
- ui::ResourceBundle::GetSharedInstance ().GetRawDataResource (
1915
- IDR_ADS_SAMPLE_BUNDLE);
1919
+ const auto resource_id =
1920
+ GetSchemaResourceId (ads::_bundle_schema_resource_name);
1921
+
1922
+ const auto sample_bundle =
1923
+ LoadDataResourceAndDecompressIfNeeded (resource_id);
1916
1924
1917
- std::string sample_bundle;
1918
- sample_bundle_raw.CopyToString (&sample_bundle);
1919
1925
callback (ads::Result::SUCCESS, sample_bundle);
1920
1926
}
1921
1927
0 commit comments