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

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

Issue 2749453002: Make GetDisplayedNotifications asynchronous. (Closed)
Patch Set: review 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"
11 #include "base/callback.h"
11 #include "base/mac/bundle_locations.h" 12 #include "base/mac/bundle_locations.h"
12 #include "base/mac/foundation_util.h" 13 #include "base/mac/foundation_util.h"
13 #include "base/mac/mac_util.h" 14 #include "base/mac/mac_util.h"
14 #include "base/mac/scoped_mach_port.h" 15 #include "base/mac/scoped_mach_port.h"
15 #include "base/mac/scoped_nsobject.h" 16 #include "base/mac/scoped_nsobject.h"
16 #include "base/strings/nullable_string16.h" 17 #include "base/strings/nullable_string16.h"
17 #include "base/strings/string_number_conversions.h" 18 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/sys_string_conversions.h" 19 #include "base/strings/sys_string_conversions.h"
19 #include "chrome/browser/browser_process.h" 20 #include "chrome/browser/browser_process.h"
20 #include "chrome/browser/notifications/native_notification_display_service.h" 21 #include "chrome/browser/notifications/native_notification_display_service.h"
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS) 270 #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
270 // If no banner existed with that ID try to see if there is an alert 271 // If no banner existed with that ID try to see if there is an alert
271 // in the xpc server. 272 // in the xpc server.
272 if (!notification_removed) { 273 if (!notification_removed) {
273 [alert_dispatcher_ closeNotificationWithId:candidate_id 274 [alert_dispatcher_ closeNotificationWithId:candidate_id
274 withProfileId:current_profile_id]; 275 withProfileId:current_profile_id];
275 } 276 }
276 #endif // ENABLE_XPC_NOTIFICATIONS 277 #endif // ENABLE_XPC_NOTIFICATIONS
277 } 278 }
278 279
279 bool NotificationPlatformBridgeMac::GetDisplayed( 280 void NotificationPlatformBridgeMac::GetDisplayed(
280 const std::string& profile_id, 281 const std::string& profile_id,
281 bool incognito, 282 bool incognito,
282 std::set<std::string>* notifications) const { 283 const DisplayedNotificationsCallback& callback) const {
283 DCHECK(notifications); 284 auto displayed_notifications = base::MakeUnique<std::set<std::string>>();
284
285 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id); 285 NSString* current_profile_id = base::SysUTF8ToNSString(profile_id);
286 for (NSUserNotification* toast in 286 for (NSUserNotification* toast in
287 [notification_center_ deliveredNotifications]) { 287 [notification_center_ deliveredNotifications]) {
288 NSString* toast_profile_id = [toast.userInfo 288 NSString* toast_profile_id = [toast.userInfo
289 objectForKey:notification_constants::kNotificationProfileId]; 289 objectForKey:notification_constants::kNotificationProfileId];
290 if ([toast_profile_id isEqualToString:current_profile_id]) { 290 if ([toast_profile_id isEqualToString:current_profile_id]) {
291 notifications->insert(base::SysNSStringToUTF8([toast.userInfo 291 displayed_notifications->insert(base::SysNSStringToUTF8([toast.userInfo
292 objectForKey:notification_constants::kNotificationId])); 292 objectForKey:notification_constants::kNotificationId]));
293 } 293 }
294 } 294 }
295 return true; 295 content::BrowserThread::PostTask(
296 content::BrowserThread::UI, FROM_HERE,
297 base::Bind(callback, base::Passed(&displayed_notifications),
298 true /* supports_synchronization */));
296 } 299 }
297 300
298 // static 301 // static
299 void NotificationPlatformBridgeMac::ProcessNotificationResponse( 302 void NotificationPlatformBridgeMac::ProcessNotificationResponse(
300 NSDictionary* response) { 303 NSDictionary* response) {
301 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response)) 304 if (!NotificationPlatformBridgeMac::VerifyNotificationData(response))
302 return; 305 return;
303 306
304 NSNumber* button_index = 307 NSNumber* button_index =
305 [response objectForKey:notification_constants::kNotificationButtonIndex]; 308 [response objectForKey:notification_constants::kNotificationButtonIndex];
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 withProfileId:(NSString*)profileId { 484 withProfileId:(NSString*)profileId {
482 [[self serviceProxy] closeNotificationWithId:notificationId 485 [[self serviceProxy] closeNotificationWithId:notificationId
483 withProfileId:profileId]; 486 withProfileId:profileId];
484 } 487 }
485 488
486 - (void)closeAllNotifications { 489 - (void)closeAllNotifications {
487 [[self serviceProxy] closeAllNotifications]; 490 [[self serviceProxy] closeAllNotifications];
488 } 491 }
489 492
490 // NotificationReply: 493 // NotificationReply:
491
492 - (void)notificationClick:(NSDictionary*)notificationResponseData { 494 - (void)notificationClick:(NSDictionary*)notificationResponseData {
493 NotificationPlatformBridgeMac::ProcessNotificationResponse( 495 NotificationPlatformBridgeMac::ProcessNotificationResponse(
494 notificationResponseData); 496 notificationResponseData);
495 } 497 }
496 498
497 // Private methods: 499 // Private methods:
498 500
499 // Retrieves the connection's remoteObjectProxy. Always use this as opposed 501 // Retrieves the connection's remoteObjectProxy. Always use this as opposed
500 // to going directly through the connection, since this will ensure that the 502 // to going directly through the connection, since this will ensure that the
501 // service has its exception port configured for crash reporting. 503 // service has its exception port configured for crash reporting.
502 - (id<NotificationDelivery>)serviceProxy { 504 - (id<NotificationDelivery>)serviceProxy {
503 id<NotificationDelivery> proxy = [xpcConnection_ remoteObjectProxy]; 505 id<NotificationDelivery> proxy = [xpcConnection_ remoteObjectProxy];
504 506
505 if (!setExceptionPort_) { 507 if (!setExceptionPort_) {
506 base::mac::ScopedMachSendRight exceptionPort( 508 base::mac::ScopedMachSendRight exceptionPort(
507 crash_reporter::GetCrashpadClient().GetHandlerMachPort()); 509 crash_reporter::GetCrashpadClient().GetHandlerMachPort());
508 base::scoped_nsobject<CrXPCMachPort> xpcPort( 510 base::scoped_nsobject<CrXPCMachPort> xpcPort(
509 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]); 511 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]);
510 [proxy setMachExceptionPort:xpcPort]; 512 [proxy setMachExceptionPort:xpcPort];
511 setExceptionPort_ = YES; 513 setExceptionPort_ = YES;
512 } 514 }
513 515
514 return proxy; 516 return proxy;
515 } 517 }
516 518
517 @end 519 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698