Skip to content

Commit

Permalink
Do not prefetch NTP ad on browser start
Browse files Browse the repository at this point in the history
  • Loading branch information
aseren committed Jul 4, 2022
1 parent 0a10ada commit 56c350e
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "base/base64.h"
#include "base/base_switches.h"
#include "base/bind.h"
#include "base/callback_helpers.h"
#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/cxx17_backports.h"
Expand Down Expand Up @@ -697,13 +698,10 @@ void AdsServiceImpl::SetupOnFirstInitialize() {
file_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&RemoveDeprecatedAdsDataFiles, base_path_));

// Initiate prefetching of the new tab page ad. Also need to purge orphaned
// new tab page ad events which may have remained from the previous browser
// startup.
PurgeOrphanedAdEventsForType(
ads::mojom::AdType::kNewTabPageAd,
base::BindOnce(&AdsServiceImpl::OnPurgeOrphanedAdEventsForNewTabPageAds,
AsWeakPtr()));
// Purge orphaned new tab page ad events which may have remained from the
// previous browser startup.
PurgeOrphanedAdEventsForType(ads::mojom::AdType::kNewTabPageAd,
base::DoNothing());
}

void AdsServiceImpl::ShutdownBatAds() {
Expand Down Expand Up @@ -1358,18 +1356,17 @@ void AdsServiceImpl::PrefetchNewTabPageAd() {

void AdsServiceImpl::OnPrefetchNewTabPageAd(bool success,
const std::string& json) {
// The previous prefetched new tab page ad was not served.
if (!success) {
return;
}

// The previous successfully prefetched new tab page ad was not served.
if (prefetched_new_tab_page_ad_info_ &&
!purge_orphaned_new_tab_page_ad_events_time_) {
purge_orphaned_new_tab_page_ad_events_time_ =
base::Time::Now() + base::Hours(1);
}

if (!success) {
prefetched_new_tab_page_ad_info_.reset();
return;
}

ads::NewTabPageAdInfo ad_info;
ad_info.FromJson(json);
prefetched_new_tab_page_ad_info_ = ad_info;
Expand Down

0 comments on commit 56c350e

Please sign in to comment.