Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not prefetch NTP ad on browser start #14029

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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