Skip to content

Commit

Permalink
Merge pull request brave#1149 from brave/issues/2639
Browse files Browse the repository at this point in the history
call `Initialize` at the time that brave ads is disabled, not on shut…
  • Loading branch information
bridiver authored and tmancey committed Dec 20, 2018
1 parent eb4ffd2 commit f6fadaa
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
17 changes: 6 additions & 11 deletions components/brave_ads/browser/ads_service_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,6 @@ AdsServiceImpl::AdsServiceImpl(Profile* profile) :
bundle_state_backend_(
new BundleStateDatabase(base_path_.AppendASCII("bundle_state"))),
display_service_(NotificationDisplayService::GetForProfile(profile_)),
enabled_(false),
#if !defined(OS_ANDROID)
last_idle_state_(ui::IdleState::IDLE_STATE_ACTIVE),
is_foreground_(!!chrome::FindBrowserWithActiveWindow()),
Expand Down Expand Up @@ -369,6 +368,10 @@ void AdsServiceImpl::Start() {
}

void AdsServiceImpl::Stop() {
if (connected()) {
// this is kind of weird, but we need to call Initialize on disable too
bat_ads_->Initialize(base::NullCallback());
}
Shutdown();
}

Expand Down Expand Up @@ -410,12 +413,6 @@ void AdsServiceImpl::Shutdown() {
fetchers_.clear();
idle_poll_timer_.Stop();

if (connected()) {
if (!enabled_) {
// this is kind of weird, but we need to call Initialize on disable too
bat_ads_->Initialize(base::NullCallback());
}
}
bat_ads_.reset();
bat_ads_client_binding_.Close();

Expand All @@ -430,11 +427,9 @@ void AdsServiceImpl::Shutdown() {

void AdsServiceImpl::OnPrefsChanged(const std::string& pref) {
if (pref == prefs::kBraveAdsEnabled) {
if (is_enabled() && !enabled_) {
enabled_ = true;
if (is_enabled()) {
Start();
} else if (!is_enabled() && enabled_) {
enabled_ = false;
} else if (!is_enabled()) {
Stop();
}
} else if (pref == prefs::kBraveAdsIdleThreshold) {
Expand Down
1 change: 0 additions & 1 deletion components/brave_ads/browser/ads_service_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ class AdsServiceImpl : public AdsService,
uint32_t next_timer_id_;
std::unique_ptr<BundleStateDatabase> bundle_state_backend_;
NotificationDisplayService* display_service_; // NOT OWNED
bool enabled_;
#if !defined(OS_ANDROID)
ui::IdleState last_idle_state_;
bool is_foreground_;
Expand Down

0 comments on commit f6fadaa

Please sign in to comment.