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

Unified Diff: chrome/browser/notifications/notification_platform_bridge_mac.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
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/notifications/alert_notification_service.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/notifications/notification_platform_bridge_mac.mm
diff --git a/chrome/browser/notifications/notification_platform_bridge_mac.mm b/chrome/browser/notifications/notification_platform_bridge_mac.mm
index 6b3c20dc60e789395257adb0ddd1f115608ac000..c9ee9791fefe4c9d801a97520b29c7750b6987fe 100644
--- a/chrome/browser/notifications/notification_platform_bridge_mac.mm
+++ b/chrome/browser/notifications/notification_platform_bridge_mac.mm
@@ -109,13 +109,22 @@ NotificationPlatformBridge* NotificationPlatformBridge::Create() {
@interface NotificationCenterDelegate
: NSObject<NSUserNotificationCenterDelegate> {
}
+
Robert Sesek 2016/10/12 15:37:36 nit: remove extra blank line
Miguel Garcia 2016/10/15 09:48:49 Done.
@end
// Interface to communicate with the Alert XPC service.
@interface NotificationRemoteDispatcher : NSObject
+// Deliver a notification to the XPC service to be displayed as an alert.
- (void)dispatchNotification:(NSDictionary*)data;
+// Close a notification for a given |notificationId| and |profileId|.
+- (void)closeNotificationWithId:(NSString*)notificationId
+ withProfileId:(NSString*)profileId;
+
+// Close all notifications.
+- (void)closeAllNotifications;
+
@end
// /////////////////////////////////////////////////////////////////////////////
@@ -137,9 +146,11 @@ NotificationPlatformBridgeMac::NotificationPlatformBridgeMac(
NotificationPlatformBridgeMac::~NotificationPlatformBridgeMac() {
[notification_center_ setDelegate:nil];
- // TODO(miguelg) remove only alerts shown by the XPC service.
// TODO(miguelg) do not remove banners if possible.
[notification_center_ removeAllDeliveredNotifications];
+#if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
+ [notification_remote_dispatcher_ closeAllNotifications];
+#endif // BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
}
void NotificationPlatformBridgeMac::Display(
@@ -231,8 +242,9 @@ void NotificationPlatformBridgeMac::Display(
void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
const std::string& notification_id) {
NSString* candidate_id = base::SysUTF8ToNSString(notification_id);
-
NSString* current_profile_id = base::SysUTF8ToNSString(profile_id);
+
+ bool notification_removed = false;
for (NSUserNotification* toast in
[notification_center_ deliveredNotifications]) {
NSString* toast_id =
@@ -244,8 +256,19 @@ void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
if ([toast_id isEqualToString:candidate_id] &&
[persistent_profile_id isEqualToString:current_profile_id]) {
[notification_center_ removeDeliveredNotification:toast];
+ notification_removed = true;
+ break;
}
}
+#if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
+ // If no banner existed with that ID try to see if there is an alert
+ // in the xpc server.
+ if (!notification_removed) {
+ [notification_remote_dispatcher_
+ closeNotificationWithId:candidate_id
+ withProfileId:current_profile_id];
+ }
+#endif // ENABLE_XPC_NOTIFICATIONS
}
bool NotificationPlatformBridgeMac::GetDisplayed(
@@ -403,10 +426,12 @@ bool NotificationPlatformBridgeMac::VerifyNotificationData(
@implementation NotificationRemoteDispatcher {
// The connection to the XPC server in charge of delivering alerts.
base::scoped_nsobject<NSXPCConnection> xpcConnection_;
+ base::scoped_nsobject<NSMutableSet> alertsDisplayed_;
Peter Beverloo 2016/10/12 12:20:38 delete (line 434 too)
Miguel Garcia 2016/10/15 09:48:49 Done.
}
- (instancetype)init {
if ((self = [super init])) {
+ alertsDisplayed_.reset([[NSMutableSet alloc] init]);
xpcConnection_.reset([[NSXPCConnection alloc]
initWithServiceName:
[NSString
@@ -441,6 +466,16 @@ bool NotificationPlatformBridgeMac::VerifyNotificationData(
[[xpcConnection_ remoteObjectProxy] deliverNotification:data];
}
+- (void)closeNotificationWithId:(NSString*)notificationId
+ withProfileId:(NSString*)profileId {
+ [[xpcConnection_ remoteObjectProxy] closeNotificationWithId:notificationId
+ withProfileId:profileId];
+}
+
+- (void)closeAllNotifications {
+ [[xpcConnection_ remoteObjectProxy] closeAllNotifications];
+}
+
// NotificationReply implementation
- (void)notificationClick:(NSDictionary*)notificationResponseData {
NotificationPlatformBridgeMac::ProcessNotificationResponse(
« no previous file with comments | « no previous file | chrome/browser/ui/cocoa/notifications/alert_notification_service.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698