OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" | 5 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS) | 266 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS) |
267 // If no banner existed with that ID try to see if there is an alert | 267 // If no banner existed with that ID try to see if there is an alert |
268 // in the xpc server. | 268 // in the xpc server. |
269 if (!notification_removed) { | 269 if (!notification_removed) { |
270 [alert_dispatcher_ closeNotificationWithId:candidate_id | 270 [alert_dispatcher_ closeNotificationWithId:candidate_id |
271 withProfileId:current_profile_id]; | 271 withProfileId:current_profile_id]; |
272 } | 272 } |
273 #endif // ENABLE_XPC_NOTIFICATIONS | 273 #endif // ENABLE_XPC_NOTIFICATIONS |
274 } | 274 } |
275 | 275 |
276 bool NotificationPlatformBridgeMac::GetDisplayed( | 276 void NotificationPlatformBridgeMac::GetDisplayed( |
277 const std::string& profile_id, | 277 const std::string& profile_id, |
278 bool incognito, | 278 bool incognito, |
279 std::set<std::string>* notifications) const { | 279 const DisplayedNotificationsCallback& callback) const { |
280 DCHECK(notifications); | 280 auto displayed_notifications = base::MakeUnique<std::set<std::string>>(); |
281 | |
282 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); | 281 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); |
283 for (NSUserNotification* toast in | 282 for (NSUserNotification* toast in |
284 [notification_center_ deliveredNotifications]) { | 283 [notification_center_ deliveredNotifications]) { |
285 NSString* toast_profile_id = [toast.userInfo | 284 NSString* toast_profile_id = [toast.userInfo |
286 objectForKey:notification_constants::kNotificationProfileId]; | 285 objectForKey:notification_constants::kNotificationProfileId]; |
287 if ([toast_profile_id isEqualToString:current_profile_id]) { | 286 if ([toast_profile_id isEqualToString:current_profile_id]) { |
288 notifications->insert(base::SysNSStringToUTF8([toast.userInfo | 287 displayed_notifications->insert(base::SysNSStringToUTF8([toast.userInfo |
289 objectForKey:notification_constants::kNotificationId])); | 288 objectForKey:notification_constants::kNotificationId])); |
290 } | 289 } |
291 } | 290 } |
292 return true; | 291 content::BrowserThread::PostTask( |
| 292 content::BrowserThread::UI, FROM_HERE, |
| 293 base::Bind(callback, base::Passed(&displayed_notifications), |
| 294 true /* supports sync */)); |
293 } | 295 } |
294 | 296 |
295 // static | 297 // static |
296 void NotificationPlatformBridgeMac::ProcessNotificationResponse( | 298 void NotificationPlatformBridgeMac::ProcessNotificationResponse( |
297 NSDictionary* response) { | 299 NSDictionary* response) { |
298 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) | 300 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) |
299 return; | 301 return; |
300 | 302 |
301 NSNumber* button_index = | 303 NSNumber* button_index = |
302 [response objectForKey:notification_constants::kNotificationButtonIndex]; | 304 [response objectForKey:notification_constants::kNotificationButtonIndex]; |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 [[xpcConnection_ remoteObjectProxy] closeAllNotifications]; | 479 [[xpcConnection_ remoteObjectProxy] closeAllNotifications]; |
478 } | 480 } |
479 | 481 |
480 // NotificationReply implementation | 482 // NotificationReply implementation |
481 - (void)notificationClick:(NSDictionary*)notificationResponseData { | 483 - (void)notificationClick:(NSDictionary*)notificationResponseData { |
482 NotificationPlatformBridgeMac::ProcessNotificationResponse( | 484 NotificationPlatformBridgeMac::ProcessNotificationResponse( |
483 notificationResponseData); | 485 notificationResponseData); |
484 } | 486 } |
485 | 487 |
486 @end | 488 @end |
OLD | NEW |