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

Brave Ads intermittently crashes when opening a new tab #6304

Merged
merged 1 commit into from
Aug 3, 2020
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
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