Skip to content

Commit

Permalink
Fix crash in NotificationUIManagerImpl
Browse files Browse the repository at this point in the history
The profile can be null in the case of "system" notifications.

Bug: 1020555
Change-Id: I80d65c74d4534ed15ffec43c582584fb54559d4a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1895378
Reviewed-by: Steven Bennetts <stevenjb@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711967}
  • Loading branch information
Evan Stade authored and Commit Bot committed Nov 2, 2019
1 parent 9932d10 commit eef2ff5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ IN_PROC_BROWSER_TEST_F(NotificationUIManagerBrowserTest, RetrieveBaseParts) {
EXPECT_TRUE(message_center());
}

IN_PROC_BROWSER_TEST_F(NotificationUIManagerBrowserTest, BasicNullProfile) {
TestMessageCenterObserver observer;
message_center()->AddObserver(&observer);
manager()->CancelAll();
manager()->Add(CreateTestNotification("hey"), nullptr);
EXPECT_EQ(1u, message_center()->NotificationCount());
EXPECT_NE("", observer.last_displayed_id());
manager()->CancelById("hey", NotificationUIManager::GetProfileID(nullptr));
EXPECT_EQ(0u, message_center()->NotificationCount());
message_center()->RemoveObserver(&observer);
}

IN_PROC_BROWSER_TEST_F(NotificationUIManagerBrowserTest, BasicAddCancel) {
// Someone may create system notifications like "you're in multi-profile
// mode..." or something which may change the expectation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void NotificationUIManagerImpl::Add(
std::make_unique<message_center::Notification>(
profile_notification->notification()));

if (profile->IsOffTheRecord())
if (profile && profile->IsOffTheRecord())
observed_otr_profiles_.Add(profile);
}

Expand Down
3 changes: 2 additions & 1 deletion chrome/browser/notifications/profile_notification.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ProfileNotification {
public:
// Returns a string that uniquely identifies a profile + delegate_id pair.
// The profile_id is used as an identifier to identify a profile instance; it
// cannot be NULL. The ID becomes invalid when a profile is destroyed.
// can be null for system notifications. The ID becomes invalid when a profile
// is destroyed.
static std::string GetProfileNotificationId(const std::string& delegate_id,
ProfileID profile_id);

Expand Down

0 comments on commit eef2ff5

Please sign in to comment.