Commit eef2ff59 authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Fix crash in NotificationUIManagerImpl

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/+/1895378Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Commit-Queue: Evan Stade <estade@chromium.org>
Cr-Commit-Position: refs/heads/master@{#711967}
parent 9932d106
......@@ -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.
......
......@@ -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);
}
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment