Skip to content

Commit bdcbee1

Browse files
authored
Fixes ads are not shown due to compressed resources failing to load
Fixes brave/brave-browser#6139
1 parent 64d852b commit bdcbee1

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

components/brave_ads/browser/ads_service_impl.cc

+23-17
Original file line numberDiff line numberDiff line change
@@ -1745,14 +1745,25 @@ const std::vector<std::string> AdsServiceImpl::GetUserModelLanguages() const {
17451745
return languages;
17461746
}
17471747

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+
17481762
void AdsServiceImpl::LoadUserModelForLanguage(
17491763
const std::string& language,
17501764
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);
17561767
callback(ads::Result::SUCCESS, user_model);
17571768
}
17581769

@@ -1899,23 +1910,18 @@ void AdsServiceImpl::Reset(
18991910

19001911
const std::string AdsServiceImpl::LoadJsonSchema(
19011912
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);
19091915
}
19101916

19111917
void AdsServiceImpl::LoadSampleBundle(
19121918
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);
19161924

1917-
std::string sample_bundle;
1918-
sample_bundle_raw.CopyToString(&sample_bundle);
19191925
callback(ads::Result::SUCCESS, sample_bundle);
19201926
}
19211927

components/brave_ads/browser/ads_service_impl.h

+3
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ class AdsServiceImpl : public AdsService,
328328

329329
uint32_t next_timer_id();
330330

331+
std::string LoadDataResourceAndDecompressIfNeeded(
332+
const int id) const;
333+
331334
bool connected();
332335

333336
// AdsClient implementation

vendor/bat-native-ads/resources/bat_ads_resources.grd

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
</outputs>
99
<release seq="1">
1010
<includes>
11-
<include name="IDR_ADS_CATALOG_SCHEMA" file="catalog-schema.json" type="BINDATA" />
12-
<include name="IDR_ADS_BUNDLE_SCHEMA" file="bundle-schema.json" type="BINDATA" />
13-
<include name="IDR_ADS_SAMPLE_BUNDLE" file="sample_bundle.json" type="BINDATA" />
11+
<include name="IDR_ADS_CATALOG_SCHEMA" file="catalog-schema.json" type="BINDATA" compress="gzip" />
12+
<include name="IDR_ADS_BUNDLE_SCHEMA" file="bundle-schema.json" type="BINDATA" compress="gzip" />
13+
<include name="IDR_ADS_SAMPLE_BUNDLE" file="sample_bundle.json" type="BINDATA" compress="gzip" />
1414
<include name="IDR_ADS_USER_MODEL_EN" file="user_models/languages/en/user_model.json" type="BINDATA" compress="gzip" />
1515
<include name="IDR_ADS_USER_MODEL_DE" file="user_models/languages/de/user_model.json" type="BINDATA" compress="gzip" />
1616
<include name="IDR_ADS_USER_MODEL_FR" file="user_models/languages/fr/user_model.json" type="BINDATA" compress="gzip" />

0 commit comments

Comments
 (0)