Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4923)

Unified Diff: chrome/browser/ui/cocoa/notifications/alert_notification_service.mm

Issue 2402303002: Implement the ability to close alerts programatically (Closed)
Patch Set: break early if the notification to close is found Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/notifications/alert_notification_service.mm
diff --git a/chrome/browser/ui/cocoa/notifications/alert_notification_service.mm b/chrome/browser/ui/cocoa/notifications/alert_notification_service.mm
index 522d42a935ba63e658ac3f69f2299258903fec4f..45e22f821884676fd880212af456a8a4ca7d3427 100644
--- a/chrome/browser/ui/cocoa/notifications/alert_notification_service.mm
+++ b/chrome/browser/ui/cocoa/notifications/alert_notification_service.mm
@@ -6,6 +6,7 @@
#import "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h"
+#include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
@class NSUserNotificationCenter;
@@ -21,4 +22,29 @@
deliverNotification:toast];
}
+- (void)closeNotificationWithId:(NSString*)notificationId
+ withProfileId:(NSString*)profileId {
+ NSUserNotificationCenter* notificationCenter =
+ [NSUserNotificationCenter defaultUserNotificationCenter];
+ for (NSUserNotification* candidate in
+ [notificationCenter deliveredNotifications]) {
+ NSString* candidateId = [candidate.userInfo
+ objectForKey:notification_constants::kNotificationId];
+
+ NSString* candidateProfileId = [candidate.userInfo
+ objectForKey:notification_constants::kNotificationProfileId];
+
+ if ([candidateId isEqualToString:notificationId] &&
+ [profileId isEqualToString:candidateProfileId]) {
+ [notificationCenter removeDeliveredNotification:candidate];
+ break;
+ }
+ }
+}
+
+- (void)closeAllNotifications {
+ [[NSUserNotificationCenter defaultUserNotificationCenter]
+ removeAllDeliveredNotifications];
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698