Skip to content

Commit

Permalink
Merge pull request #6304 from /issues/9393
Browse files Browse the repository at this point in the history
Brave Ads intermittently crashes when opening a new tab
  • Loading branch information
tmancey authored Aug 3, 2020
2 parents 872a342 + 250912a commit 137588e
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 @@ -570,6 +570,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 @@ -651,10 +655,6 @@ void AdsServiceImpl::Start() {
}

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

ShutdownBatAds();
}

Expand Down Expand Up @@ -849,10 +849,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 @@ -877,6 +881,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 137588e

Please sign in to comment.