diff --git a/browser/brave_ads/ads_service_delegate.cc b/browser/brave_ads/ads_service_delegate.cc index 38a9c0b21064..04ee1392b193 100644 --- a/browser/brave_ads/ads_service_delegate.cc +++ b/browser/brave_ads/ads_service_delegate.cc @@ -20,6 +20,7 @@ #include "brave/components/skus/browser/pref_names.h" #include "build/build_config.h" #include "chrome/browser/notifications/notification_display_service.h" +#include "chrome/browser/notifications/notification_display_service_factory.h" #include "chrome/browser/profiles/profile.h" #include "chrome/common/channel_info.h" #include "components/search_engines/template_url_prepopulate_data.h" @@ -107,7 +108,6 @@ AdsServiceDelegate::AdsServiceDelegate( PrefService* local_state, brave_adaptive_captcha::BraveAdaptiveCaptchaService* adaptive_captcha_service, - NotificationDisplayService* notification_display_service, std::unique_ptr notification_ad_platform_bridge) : profile_(profile), @@ -117,7 +117,6 @@ AdsServiceDelegate::AdsServiceDelegate( local_state_, /*is_profile_eligible_for_dse_guest_propagation=*/false), adaptive_captcha_service_(adaptive_captcha_service), - notification_display_service_(notification_display_service), notification_ad_platform_bridge_( std::move(notification_ad_platform_bridge)) {} @@ -224,13 +223,13 @@ void AdsServiceDelegate::SnoozeScheduledCaptcha() { void AdsServiceDelegate::Display( const message_center::Notification& notification) { - notification_display_service_->Display(NotificationHandler::Type::BRAVE_ADS, - notification, nullptr); + GetNotificationDisplayService()->Display(NotificationHandler::Type::BRAVE_ADS, + notification, nullptr); } void AdsServiceDelegate::Close(const std::string& notification_id) { - notification_display_service_->Close(NotificationHandler::Type::BRAVE_ADS, - notification_id); + GetNotificationDisplayService()->Close(NotificationHandler::Type::BRAVE_ADS, + notification_id); } void AdsServiceDelegate::ShowNotificationAd(const std::string& id, @@ -279,4 +278,9 @@ base::Value::Dict AdsServiceDelegate::GetVirtualPrefs() { .Set("[virtual]:skus", GetSkus()); } +NotificationDisplayService* +AdsServiceDelegate::GetNotificationDisplayService() { + return NotificationDisplayServiceFactory::GetForProfile(profile_); +} + } // namespace brave_ads diff --git a/browser/brave_ads/ads_service_delegate.h b/browser/brave_ads/ads_service_delegate.h index c2240d2e5ae0..9a9663ca8c0d 100644 --- a/browser/brave_ads/ads_service_delegate.h +++ b/browser/brave_ads/ads_service_delegate.h @@ -35,7 +35,6 @@ class AdsServiceDelegate : public AdsService::Delegate { PrefService* local_state, brave_adaptive_captcha::BraveAdaptiveCaptchaService* adaptive_captcha_service, - NotificationDisplayService* notification_display_service, std::unique_ptr notification_ad_platform_bridge); @@ -78,13 +77,13 @@ class AdsServiceDelegate : public AdsService::Delegate { base::Value::Dict GetVirtualPrefs() override; private: + NotificationDisplayService* GetNotificationDisplayService(); + raw_ptr profile_ = nullptr; raw_ptr local_state_ = nullptr; search_engines::SearchEngineChoiceService search_engine_choice_service_; raw_ptr adaptive_captcha_service_ = nullptr; - raw_ptr - notification_display_service_ = nullptr; std::unique_ptr notification_ad_platform_bridge_; }; diff --git a/browser/brave_ads/ads_service_factory.cc b/browser/brave_ads/ads_service_factory.cc index be896f5d131b..3f966d5c747f 100644 --- a/browser/brave_ads/ads_service_factory.cc +++ b/browser/brave_ads/ads_service_factory.cc @@ -76,11 +76,8 @@ AdsServiceFactory::BuildServiceInstanceForBrowserContext( auto* brave_adaptive_captcha_service = brave_adaptive_captcha::BraveAdaptiveCaptchaServiceFactory::GetInstance() ->GetForProfile(profile); - auto* display_service = - NotificationDisplayServiceFactory::GetForProfile(profile); auto delegate = std::make_unique( profile, g_browser_process->local_state(), brave_adaptive_captcha_service, - display_service, std::make_unique(*profile)); auto* history_service = HistoryServiceFactory::GetInstance()->GetForProfile(