|
11 | 11 | #include "base/logging.h"
|
12 | 12 | #include "base/notreached.h"
|
13 | 13 | #include "base/strings/stringprintf.h"
|
| 14 | +#include "bat/ads/new_tab_page_ad_info.h" |
14 | 15 | #include "brave/components/ntp_background_images/browser/url_constants.h"
|
15 | 16 | #include "content/public/common/url_constants.h"
|
16 | 17 |
|
@@ -196,6 +197,10 @@ Campaign NTPSponsoredImagesData::GetCampaignFromValue(
|
196 | 197 |
|
197 | 198 | Campaign campaign;
|
198 | 199 |
|
| 200 | + if (const std::string* campaign_id = value.FindStringKey(kCampaignIdKey)) { |
| 201 | + campaign.campaign_id = *campaign_id; |
| 202 | + } |
| 203 | + |
199 | 204 | Logo default_logo;
|
200 | 205 | if (auto* logo = value.FindDictKey(kLogoKey)) {
|
201 | 206 | default_logo = GetLogoFromValue(installed_dir, url_prefix, logo);
|
@@ -324,6 +329,41 @@ base::Value NTPSponsoredImagesData::GetBackgroundAt(size_t campaign_index,
|
324 | 329 | return data;
|
325 | 330 | }
|
326 | 331 |
|
| 332 | +base::Value NTPSponsoredImagesData::GetBackgroundByAdInfo( |
| 333 | + const ads::NewTabPageAdInfo& ad_info) { |
| 334 | + // Find campaign |
| 335 | + LOG(ERROR) << ad_info.campaign_id; |
| 336 | + size_t campaign_index = 0; |
| 337 | + for (; campaign_index != campaigns.size(); ++campaign_index) { |
| 338 | + LOG(ERROR) << campaigns[campaign_index].campaign_id; |
| 339 | + if (campaigns[campaign_index].campaign_id == ad_info.campaign_id) { |
| 340 | + break; |
| 341 | + } |
| 342 | + } |
| 343 | + if (campaign_index == campaigns.size()) { |
| 344 | + LOG(ERROR) << "Ad campaign wasn't found in NTP sposored images data: " |
| 345 | + << ad_info.campaign_id; |
| 346 | + return base::Value(); |
| 347 | + } |
| 348 | + |
| 349 | + const auto& sponsored_backgrounds = campaigns[campaign_index].backgrounds; |
| 350 | + size_t background_index = 0; |
| 351 | + for (; background_index != sponsored_backgrounds.size(); ++background_index) { |
| 352 | + LOG(ERROR) << sponsored_backgrounds[background_index].creative_instance_id; |
| 353 | + if (sponsored_backgrounds[background_index].creative_instance_id == |
| 354 | + ad_info.creative_instance_id) { |
| 355 | + break; |
| 356 | + } |
| 357 | + } |
| 358 | + if (background_index == sponsored_backgrounds.size()) { |
| 359 | + LOG(ERROR) << "Creative instance wasn't found in NTP sposored images data: " |
| 360 | + << ad_info.creative_instance_id; |
| 361 | + return base::Value(); |
| 362 | + } |
| 363 | + |
| 364 | + return GetBackgroundAt(campaign_index, background_index); |
| 365 | +} |
| 366 | + |
327 | 367 | void NTPSponsoredImagesData::PrintCampaignsParsingResult() const {
|
328 | 368 | VLOG(2) << __func__ << ": This is "
|
329 | 369 | << (IsSuperReferral() ? " NTP SR Data" : " NTP SI Data");
|
|
0 commit comments