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

Side by Side Diff: chrome/browser/notifications/notification_platform_bridge_mac.mm

Issue 2714743002: Retrive displayed notifications asynchronously
Patch Set: apply review comments from https://codereview.chromium.org/2709213005/ Created 3 years, 9 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 unified diff | Download patch
OLDNEW
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 // Deliver a notification to the XPC service to be displayed as an alert. 113 // Deliver a notification to the XPC service to be displayed as an alert.
114 - (void)dispatchNotification:(NSDictionary*)data; 114 - (void)dispatchNotification:(NSDictionary*)data;
115 115
116 // Close a notification for a given |notificationId| and |profileId|. 116 // Close a notification for a given |notificationId| and |profileId|.
117 - (void)closeNotificationWithId:(NSString*)notificationId 117 - (void)closeNotificationWithId:(NSString*)notificationId
118 withProfileId:(NSString*)profileId; 118 withProfileId:(NSString*)profileId;
119 119
120 // Close all notifications. 120 // Close all notifications.
121 - (void)closeAllNotifications; 121 - (void)closeAllNotifications;
122 122
123 // Get displayed alerts for |profileId| merge them with |localNotifications|
124 // and post |callback| to the IO thread.
125 - (void)
126 getDisplayedAlertsForProfileId:(NSString*)profileId
127 withLocalNotifications:(NSArray*)localNotifications
128 callback:(NotificationCommon::NotificationResultCallback)
129 callback;
130
123 @end 131 @end
124 132
125 // ///////////////////////////////////////////////////////////////////////////// 133 // /////////////////////////////////////////////////////////////////////////////
126 NotificationPlatformBridgeMac::NotificationPlatformBridgeMac( 134 NotificationPlatformBridgeMac::NotificationPlatformBridgeMac(
127 NSUserNotificationCenter* notification_center, 135 NSUserNotificationCenter* notification_center,
128 id<AlertDispatcher> alert_dispatcher) 136 id<AlertDispatcher> alert_dispatcher)
129 : delegate_([NotificationCenterDelegate alloc]), 137 : delegate_([NotificationCenterDelegate alloc]),
130 notification_center_([notification_center retain]), 138 notification_center_([notification_center retain]),
131 alert_dispatcher_([alert_dispatcher retain]) { 139 alert_dispatcher_([alert_dispatcher retain]) {
132 [notification_center_ setDelegate:delegate_.get()]; 140 [notification_center_ setDelegate:delegate_.get()];
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); 290 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id);
283 for (NSUserNotification* toast in 291 for (NSUserNotification* toast in
284 [notification_center_ deliveredNotifications]) { 292 [notification_center_ deliveredNotifications]) {
285 NSString* toast_profile_id = [toast.userInfo 293 NSString* toast_profile_id = [toast.userInfo
286 objectForKey:notification_constants::kNotificationProfileId]; 294 objectForKey:notification_constants::kNotificationProfileId];
287 if ([toast_profile_id isEqualToString:current_profile_id]) { 295 if ([toast_profile_id isEqualToString:current_profile_id]) {
288 notifications->insert(base::SysNSStringToUTF8([toast.userInfo 296 notifications->insert(base::SysNSStringToUTF8([toast.userInfo
289 objectForKey:notification_constants::kNotificationId])); 297 objectForKey:notification_constants::kNotificationId]));
290 } 298 }
291 } 299 }
300
292 return true; 301 return true;
293 } 302 }
294 303
304 void NotificationPlatformBridgeMac::GetDisplayedAsync(
305 const std::string& profile_id,
306 bool incognito,
307 const NotificationCommon::NotificationResultCallback& callback) const {
308 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
309 [alert_dispatcher_
310 getDisplayedAlertsForProfileId:base::SysUTF8ToNSString(profile_id)
311 withLocalNotifications:[notification_center_
312 deliveredNotifications]
313 callback:callback];
314
315 #endif // ENABLE_XPC_NOTIFICATIONS
316 }
317
295 // static 318 // static
296 void NotificationPlatformBridgeMac::ProcessNotificationResponse( 319 void NotificationPlatformBridgeMac::ProcessNotificationResponse(
297 NSDictionary* response) { 320 NSDictionary* response) {
298 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) 321 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response))
299 return; 322 return;
300 323
301 NSNumber* button_index = 324 NSNumber* button_index =
302 [response objectForKey:notification_constants::kNotificationButtonIndex]; 325 [response objectForKey:notification_constants::kNotificationButtonIndex];
303 NSNumber* operation = 326 NSNumber* operation =
304 [response objectForKey:notification_constants::kNotificationOperation]; 327 [response objectForKey:notification_constants::kNotificationOperation];
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 - (void)closeNotificationWithId:(NSString*)notificationId 492 - (void)closeNotificationWithId:(NSString*)notificationId
470 withProfileId:(NSString*)profileId { 493 withProfileId:(NSString*)profileId {
471 [[xpcConnection_ remoteObjectProxy] closeNotificationWithId:notificationId 494 [[xpcConnection_ remoteObjectProxy] closeNotificationWithId:notificationId
472 withProfileId:profileId]; 495 withProfileId:profileId];
473 } 496 }
474 497
475 - (void)closeAllNotifications { 498 - (void)closeAllNotifications {
476 [[xpcConnection_ remoteObjectProxy] closeAllNotifications]; 499 [[xpcConnection_ remoteObjectProxy] closeAllNotifications];
477 } 500 }
478 501
502 - (void)
503 getDisplayedAlertsForProfileId:(NSString*)profileId
504 withLocalNotifications:(NSArray*)localNotifications
505 callback:(NotificationCommon::NotificationResultCallback)
506 callback {
507 auto reply = ^(NSArray* alerts) {
508 std::unique_ptr<std::set<std::string>> displayedNotifications =
509 base::MakeUnique<std::set<std::string>>();
510
511 for (NSUserNotification* toast in localNotifications) {
512 NSString* toastProfileId = [toast.userInfo
513 objectForKey:notification_constants::kNotificationProfileId];
514 if ([toastProfileId isEqualToString:profileId]) {
515 displayedNotifications->insert(base::SysNSStringToUTF8([toast.userInfo
516 objectForKey:notification_constants::kNotificationId]));
517 }
518 }
519
520 for (NSString* alert in alerts) {
521 displayedNotifications->insert(base::SysNSStringToUTF8(alert));
522 }
523
524 content::BrowserThread::PostTask(
525 content::BrowserThread::IO, FROM_HERE,
526 base::Bind(callback, base::Passed(&displayedNotifications),
527 true /* supports sync */));
528 };
529
530 [[xpcConnection_ remoteObjectProxy] getDisplayedAlertsForProfileId:profileId
531 withReply:reply];
532 }
533
479 // NotificationReply implementation 534 // NotificationReply implementation
480 - (void)notificationClick:(NSDictionary*)notificationResponseData { 535 - (void)notificationClick:(NSDictionary*)notificationResponseData {
481 NotificationPlatformBridgeMac::ProcessNotificationResponse( 536 NotificationPlatformBridgeMac::ProcessNotificationResponse(
482 notificationResponseData); 537 notificationResponseData);
483 } 538 }
484 539
485 @end 540 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698