Skip to content

Commit

Permalink
Fixes Brave Ads intermittently crashes when opening a new tab
Browse files Browse the repository at this point in the history
  • Loading branch information
tmancey committed Aug 1, 2020
1 parent f968e8e commit 250912a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,10 @@ void AdsServiceImpl::OnInitialize(
}

void AdsServiceImpl::ShutdownBatAds() {
if (!connected()) {
return;
}

VLOG(1) << "Shutting down ads";

bat_ads_->Shutdown(base::BindOnce(&AdsServiceImpl::OnShutdownBatAds,
Expand Down Expand Up @@ -650,10 +654,6 @@ void AdsServiceImpl::Start() {
}

void AdsServiceImpl::Stop() {
if (!connected()) {
return;
}

ShutdownBatAds();
}

Expand Down Expand Up @@ -848,10 +848,14 @@ void AdsServiceImpl::OnViewAdNotification(
ads::AdNotificationInfo notification;
notification.FromJson(json);

OpenNewTabWithUrl(notification.target_url);

if (!connected()) {
return;
}

bat_ads_->OnAdNotificationEvent(notification.uuid,
ads::AdNotificationEventType::kClicked);

OpenNewTabWithUrl(notification.target_url);
}

void AdsServiceImpl::RetryViewingAdNotification(
Expand All @@ -876,6 +880,10 @@ void AdsServiceImpl::ClearAdsServiceForNotificationHandler() {

void AdsServiceImpl::OpenNewTabWithUrl(
const std::string& url) {
if (g_brave_browser_process->IsShuttingDown()) {
return;
}

GURL gurl(url);
if (!gurl.is_valid()) {
VLOG(0) << "Failed to open new tab due to invalid URL: " << url;
Expand Down

0 comments on commit 250912a

Please sign in to comment.