diff --git a/components/brave_ads/browser/ads_service_impl.cc b/components/brave_ads/browser/ads_service_impl.cc index 4c61d512e3d0..891ba4993324 100644 --- a/components/brave_ads/browser/ads_service_impl.cc +++ b/components/brave_ads/browser/ads_service_impl.cc @@ -1140,6 +1140,10 @@ void AdsServiceImpl::SetAdsPerHour(const uint64_t ads_per_hour) { } void AdsServiceImpl::GetAdsHistory(OnGetAdsHistoryCallback callback) { + if (!connected()) { + return; + } + bat_ads_->GetAdsHistory(base::BindOnce(&AdsServiceImpl::OnGetAdsHistory, AsWeakPtr(), std::move(callback))); } @@ -1226,6 +1230,10 @@ void AdsServiceImpl::ToggleAdThumbUp(const std::string& id, const std::string& creative_set_id, int action, OnToggleAdThumbUpCallback callback) { + if (!connected()) { + return; + } + bat_ads_->ToggleAdThumbUp(id, creative_set_id, action, base::BindOnce(&AdsServiceImpl::OnToggleAdThumbUp, AsWeakPtr(), std::move(callback))); @@ -1241,6 +1249,10 @@ void AdsServiceImpl::ToggleAdThumbDown(const std::string& id, const std::string& creative_set_id, int action, OnToggleAdThumbDownCallback callback) { + if (!connected()) { + return; + } + bat_ads_->ToggleAdThumbDown( id, creative_set_id, action, base::BindOnce(&AdsServiceImpl::OnToggleAdThumbDown, AsWeakPtr(), @@ -1257,6 +1269,10 @@ void AdsServiceImpl::ToggleAdOptInAction( const std::string& category, int action, OnToggleAdOptInActionCallback callback) { + if (!connected()) { + return; + } + bat_ads_->ToggleAdOptInAction( category, action, base::BindOnce(&AdsServiceImpl::OnToggleAdOptInAction, AsWeakPtr(), @@ -1274,6 +1290,10 @@ void AdsServiceImpl::ToggleAdOptOutAction( const std::string& category, int action, OnToggleAdOptOutActionCallback callback) { + if (!connected()) { + return; + } + bat_ads_->ToggleAdOptOutAction( category, action, base::BindOnce(&AdsServiceImpl::OnToggleAdOptOutAction, AsWeakPtr(), @@ -1291,6 +1311,10 @@ void AdsServiceImpl::ToggleSaveAd(const std::string& id, const std::string& creative_set_id, bool saved, OnToggleSaveAdCallback callback) { + if (!connected()) { + return; + } + bat_ads_->ToggleSaveAd(id, creative_set_id, saved, base::BindOnce(&AdsServiceImpl::OnToggleSaveAd, AsWeakPtr(), std::move(callback))); @@ -1306,6 +1330,10 @@ void AdsServiceImpl::ToggleFlagAd(const std::string& id, const std::string& creative_set_id, bool flagged, OnToggleFlagAdCallback callback) { + if (!connected()) { + return; + } + bat_ads_->ToggleFlagAd(id, creative_set_id, flagged, base::BindOnce(&AdsServiceImpl::OnToggleFlagAd, AsWeakPtr(), std::move(callback)));