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

Unified Diff: chrome/browser/notifications/notification_platform_bridge_mac.mm

Issue 2709213005: [Mac] Add XPC alerts to GetDisplayedNotifications (Closed)
Patch Set: - Created 3 years, 10 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/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 f708a0bd47c32a8e8c116a12a92cf636e17bcc11..1c13ae7b4d4ac3d046b1fe4b48228cd037f90b64 100644
--- a/chrome/browser/notifications/notification_platform_bridge_mac.mm
+++ b/chrome/browser/notifications/notification_platform_bridge_mac.mm
@@ -120,6 +120,15 @@ void DoProcessNotificationResponse(NotificationCommon::Operation operation,
// Close all notifications.
- (void)closeAllNotifications;
+// Retrieves all the alerts currenlty displayed by the XPC server
+// They are subsequently merged with the local ones (passed in
+// |localNotifications|
+// and included in |callback|.
Peter Beverloo 2017/02/24 16:12:24 nit: weird line break
Miguel Garcia 2017/03/22 22:00:07 Done.
+- (void)getDisplayedAlertIds:(NSString*)profileId
+ withLocalNotifications:(NSArray*)localNotifications
+ withCallback:
+ (NotificationCommon::NotificationResultCallback)callback;
+
@end
// /////////////////////////////////////////////////////////////////////////////
@@ -289,9 +298,23 @@ bool NotificationPlatformBridgeMac::GetDisplayed(
objectForKey:notification_constants::kNotificationId]));
}
}
+
return true;
}
+void NotificationPlatformBridgeMac::GetDisplayedAsync(
+ const std::string& profile_id,
+ bool incognito,
+ const NotificationCommon::NotificationResultCallback& callback) const {
+#if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
+ [alert_dispatcher_
+ getDisplayedAlertIds:base::SysUTF8ToNSString(profile_id)
+ withLocalNotifications:[notification_center_ deliveredNotifications]
+ withCallback:callback];
+
+#endif // ENABLE_XPC_NOTIFICATIONS
+}
+
// static
void NotificationPlatformBridgeMac::ProcessNotificationResponse(
NSDictionary* response) {
@@ -476,6 +499,40 @@ bool NotificationPlatformBridgeMac::VerifyNotificationData(
[[xpcConnection_ remoteObjectProxy] closeAllNotifications];
}
+- (void)getDisplayedAlertIds:(NSString*)profileId
+ withLocalNotifications:(NSArray*)localNotifications
+ withCallback:
+ (NotificationCommon::NotificationResultCallback)callback {
+ [[xpcConnection_ remoteObjectProxy]
+ getDisplayedAlertIds:profileId
+ withReply:^(NSArray* alerts) {
Robert Sesek 2017/02/24 22:38:05 This is hard to read due to the amount of indent n
Miguel Garcia 2017/03/22 22:00:07 Done.
+ std::unique_ptr<std::set<std::string>>
+ displayedNotifications =
+ base::MakeUnique<std::set<std::string>>();
Peter Beverloo 2017/02/24 16:12:24 nit {}
Miguel Garcia 2017/03/22 22:00:07 Done.
+
+ for (NSUserNotification* toast in localNotifications) {
Peter Beverloo 2017/02/24 16:12:24 Can it happen that the XPC service does not reply,
Robert Sesek 2017/02/24 22:38:05 Yes this is possible.
Miguel Garcia 2017/03/22 22:00:07 I have changed the flow now so that the xpc alerts
+ NSString* toast_profile_id = [toast.userInfo
Peter Beverloo 2017/02/24 16:12:24 nit: toastProfileId
Miguel Garcia 2017/03/22 22:00:07 Done.
+ objectForKey:notification_constants::
+ kNotificationProfileId];
+ if ([toast_profile_id isEqualToString:profileId]) {
+ displayedNotifications->insert(base::SysNSStringToUTF8(
+ [toast.userInfo objectForKey:notification_constants::
+ kNotificationId]));
+ }
+ }
+
+ for (NSString* alert in alerts)
+ displayedNotifications->insert(
+ base::SysNSStringToUTF8(alert));
Peter Beverloo 2017/02/24 16:12:24 nit: {}
Miguel Garcia 2017/03/22 22:00:07 Done.
+
+ content::BrowserThread::PostTask(
+ content::BrowserThread::IO, FROM_HERE,
+ base::Bind(callback,
+ base::Passed(&displayedNotifications),
+ true /* supports sync */));
+ }];
+}
+
// NotificationReply implementation
- (void)notificationClick:(NSDictionary*)notificationResponseData {
NotificationPlatformBridgeMac::ProcessNotificationResponse(

Powered by Google App Engine
This is Rietveld 408576698