Skip to content

Commit 414a894

Browse files
authored
Merge pull request #4068 from /issues/4761
Support OS level targeting for ads
2 parents 6466495 + 3017fb5 commit 414a894

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

vendor/bat-native-ads/src/bat/ads/internal/bundle.cc

+49
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ std::unique_ptr<BundleState> Bundle::GenerateFromCatalog(
136136
ad_info.notification_url = creative.payload.target_url;
137137
ad_info.uuid = creative.creative_instance_id;
138138

139+
// OSes
140+
if (!DoesOsSupportCreativeSet(creative_set)) {
141+
continue;
142+
}
143+
139144
// Segments
140145
for (const auto& segment : creative_set.segments) {
141146
auto segment_name = base::ToLowerASCII(segment.name);
@@ -188,6 +193,50 @@ std::unique_ptr<BundleState> Bundle::GenerateFromCatalog(
188193
return state;
189194
}
190195

196+
bool Bundle::DoesOsSupportCreativeSet(
197+
const CreativeSetInfo& creative_set) {
198+
if (creative_set.oses.empty()) {
199+
// Creative set supports all OSes
200+
return true;
201+
}
202+
203+
const std::string client_os = GetClientOS();
204+
for (const auto& os : creative_set.oses) {
205+
if (os.name == client_os) {
206+
return true;
207+
}
208+
}
209+
210+
return false;
211+
}
212+
213+
std::string Bundle::GetClientOS() {
214+
ClientInfo client_info;
215+
ads_client_->GetClientInfo(&client_info);
216+
217+
switch (client_info.platform) {
218+
case UNKNOWN: {
219+
NOTREACHED();
220+
return "";
221+
}
222+
case WINDOWS: {
223+
return "windows";
224+
}
225+
case MACOS: {
226+
return "macos";
227+
}
228+
case IOS: {
229+
return "ios";
230+
}
231+
case ANDROID_OS: {
232+
return "android";
233+
}
234+
case LINUX: {
235+
return "linux";
236+
}
237+
}
238+
}
239+
191240
void Bundle::OnStateSaved(
192241
const std::string& catalog_id,
193242
const uint64_t& catalog_version,

vendor/bat-native-ads/src/bat/ads/internal/bundle.h

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class Bundle {
3838
private:
3939
std::unique_ptr<BundleState> GenerateFromCatalog(const Catalog& catalog);
4040

41+
bool DoesOsSupportCreativeSet(
42+
const CreativeSetInfo& creative_set);
43+
44+
std::string GetClientOS();
45+
4146
void SaveState();
4247
void OnStateSaved(
4348
const std::string& catalog_id,

0 commit comments

Comments
 (0)