From fb68c9c0e6016d74d8f3ba9b539baca76c632931 Mon Sep 17 00:00:00 2001 From: miguelg Date: Mon, 14 Mar 2016 11:59:04 -0700 Subject: Implement renotify in mac native notifications. BUG=571056 Review URL: https://codereview.chromium.org/1763023003 Cr-Commit-Position: refs/heads/master@{#381028} --- .../notifications/notification_ui_manager_mac.mm | 17 +++++++++++++++++ ui/message_center/notification.h | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/chrome/browser/notifications/notification_ui_manager_mac.mm b/chrome/browser/notifications/notification_ui_manager_mac.mm index be72587..74023f7 100644 --- a/chrome/browser/notifications/notification_ui_manager_mac.mm +++ b/chrome/browser/notifications/notification_ui_manager_mac.mm @@ -167,6 +167,23 @@ void NotificationUIManagerMac::Add(const Notification& notification, !notification.tag().empty()) { [toast setValue:base::SysUTF8ToNSString(notification.tag()) forKey:@"identifier"]; + + // If renotify is needed, delete the notification with the same tag + // from the notification center before displaying this one. + if (notification.renotify()) { + NSUserNotificationCenter* notification_center = + [NSUserNotificationCenter defaultUserNotificationCenter]; + for (NSUserNotification* existing_notification in + [notification_center deliveredNotifications]) { + NSString* identifier = + [existing_notification valueForKey:@"identifier"]; + if ([identifier isEqual:base::SysUTF8ToNSString(notification.tag())]) { + [notification_center + removeDeliveredNotification:existing_notification]; + break; + } + } + } } int64_t persistent_notification_id = delegate->persistent_notification_id(); diff --git a/ui/message_center/notification.h b/ui/message_center/notification.h index 1214ee2..7bbcc8f 100644 --- a/ui/message_center/notification.h +++ b/ui/message_center/notification.h @@ -129,7 +129,8 @@ class MESSAGE_CENTER_EXPORT Notification { optional_fields_.vibration_pattern = vibration_pattern; } - // This property currently has no effect on non-Android platforms. + // This property currently only works in platforms that support native + // notifications. // It determines whether the sound and vibration effects should signal // if the notification is replacing another notification. bool renotify() const { return optional_fields_.renotify; } -- cgit v1.1