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

Fixes user feedback loop crash if ads are disabled or region is not supported #3174

Merged
merged 1 commit into from
Aug 14, 2019
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
28 changes: 28 additions & 0 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
}
Expand Down Expand Up @@ -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)));
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -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)));
Expand All @@ -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)));
Expand Down