Skip to content

Commit

Permalink
[DanglingPtr] Fix dangling pointers in BraveAdsTabHelperTest
Browse files Browse the repository at this point in the history
  • Loading branch information
aseren committed Nov 1, 2024
1 parent 499ad60 commit 2e949de
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 57 deletions.
6 changes: 6 additions & 0 deletions browser/brave_ads/ads_service_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,17 @@ void AdsServiceDelegate::SnoozeScheduledCaptcha() {

void AdsServiceDelegate::Display(
const message_center::Notification& notification) {
// We cannot store a raw_ptr to NotificationDisplayService due to upstream
// browser tests changes NotificationDisplayService instance during test run
// which leads to dangling pointer errors.
GetNotificationDisplayService()->Display(NotificationHandler::Type::BRAVE_ADS,
notification, nullptr);
}

void AdsServiceDelegate::Close(const std::string& notification_id) {
// We cannot store a raw_ptr to NotificationDisplayService due to upstream
// browser tests changes NotificationDisplayService instance during test run
// which leads to dangling pointer errors.
GetNotificationDisplayService()->Close(NotificationHandler::Type::BRAVE_ADS,
notification_id);
}
Expand Down
4 changes: 2 additions & 2 deletions browser/brave_ads/ads_service_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class AdsServiceDelegate : public AdsService::Delegate {
private:
NotificationDisplayService* GetNotificationDisplayService();

raw_ptr<Profile> profile_ = nullptr;
raw_ptr<PrefService> local_state_ = nullptr;
raw_ptr<Profile> profile_ = nullptr; // NOT OWNED
raw_ptr<PrefService> local_state_ = nullptr; // NOT OWNED
search_engines::SearchEngineChoiceService search_engine_choice_service_;
raw_ptr<brave_adaptive_captcha::BraveAdaptiveCaptchaService>
adaptive_captcha_service_ = nullptr;
Expand Down
Loading

0 comments on commit 2e949de

Please sign in to comment.