Skip to content

Commit 0163cb3

Browse files
authored
Fixes ads are not shown due to compressed resources failing to load
Fixes brave/brave-browser#6139
1 parent e17f0c7 commit 0163cb3

File tree

3 files changed

+28
-20
lines changed

3 files changed

+28
-20
lines changed

components/brave_ads/browser/ads_service_impl.cc

+22-17
Original file line numberDiff line numberDiff line change
@@ -1745,14 +1745,24 @@ 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+
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+
17481761
void AdsServiceImpl::LoadUserModelForLanguage(
17491762
const std::string& language,
17501763
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);
17561766
callback(ads::Result::SUCCESS, user_model);
17571767
}
17581768

@@ -1899,23 +1909,18 @@ void AdsServiceImpl::Reset(
18991909

19001910
const std::string AdsServiceImpl::LoadJsonSchema(
19011911
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);
19091914
}
19101915

19111916
void AdsServiceImpl::LoadSampleBundle(
19121917
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);
19161923

1917-
std::string sample_bundle;
1918-
sample_bundle_raw.CopyToString(&sample_bundle);
19191924
callback(ads::Result::SUCCESS, sample_bundle);
19201925
}
19211926

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)