| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "chrome/browser/ui/cocoa/notifications/alert_notification_service.h" | 5 #import "chrome/browser/ui/cocoa/notifications/alert_notification_service.h" |
| 6 | 6 |
| 7 #import "base/mac/scoped_nsobject.h" | 7 #import "base/mac/scoped_nsobject.h" |
| 8 #import "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" | 8 #import "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" |
| 9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | 9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
| 10 #import "chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.h" |
| 10 | 11 |
| 11 @class NSUserNotificationCenter; | 12 @class NSUserNotificationCenter; |
| 12 | 13 |
| 13 @implementation AlertNotificationService | 14 @implementation AlertNotificationService { |
| 15 XPCTransactionHandler* transactionHandler_; |
| 16 } |
| 17 |
| 18 - (instancetype)initWithTransactionHandler:(XPCTransactionHandler*)handler { |
| 19 if ((self = [super init])) { |
| 20 transactionHandler_ = handler; |
| 21 } |
| 22 return self; |
| 23 } |
| 14 | 24 |
| 15 - (void)deliverNotification:(NSDictionary*)notificationData { | 25 - (void)deliverNotification:(NSDictionary*)notificationData { |
| 16 base::scoped_nsobject<NotificationBuilder> builder( | 26 base::scoped_nsobject<NotificationBuilder> builder( |
| 17 [[NotificationBuilder alloc] initWithDictionary:notificationData]); | 27 [[NotificationBuilder alloc] initWithDictionary:notificationData]); |
| 18 | 28 |
| 19 NSUserNotification* toast = [builder buildUserNotification]; | 29 NSUserNotification* toast = [builder buildUserNotification]; |
| 20 | |
| 21 [[NSUserNotificationCenter defaultUserNotificationCenter] | 30 [[NSUserNotificationCenter defaultUserNotificationCenter] |
| 22 deliverNotification:toast]; | 31 deliverNotification:toast]; |
| 32 [transactionHandler_ openTransactionIfNeeded]; |
| 23 } | 33 } |
| 24 | 34 |
| 25 - (void)closeNotificationWithId:(NSString*)notificationId | 35 - (void)closeNotificationWithId:(NSString*)notificationId |
| 26 withProfileId:(NSString*)profileId { | 36 withProfileId:(NSString*)profileId { |
| 27 NSUserNotificationCenter* notificationCenter = | 37 NSUserNotificationCenter* notificationCenter = |
| 28 [NSUserNotificationCenter defaultUserNotificationCenter]; | 38 [NSUserNotificationCenter defaultUserNotificationCenter]; |
| 29 for (NSUserNotification* candidate in | 39 for (NSUserNotification* candidate in |
| 30 [notificationCenter deliveredNotifications]) { | 40 [notificationCenter deliveredNotifications]) { |
| 31 NSString* candidateId = [candidate.userInfo | 41 NSString* candidateId = [candidate.userInfo |
| 32 objectForKey:notification_constants::kNotificationId]; | 42 objectForKey:notification_constants::kNotificationId]; |
| 33 | 43 |
| 34 NSString* candidateProfileId = [candidate.userInfo | 44 NSString* candidateProfileId = [candidate.userInfo |
| 35 objectForKey:notification_constants::kNotificationProfileId]; | 45 objectForKey:notification_constants::kNotificationProfileId]; |
| 36 | 46 |
| 37 if ([candidateId isEqualToString:notificationId] && | 47 if ([candidateId isEqualToString:notificationId] && |
| 38 [profileId isEqualToString:candidateProfileId]) { | 48 [profileId isEqualToString:candidateProfileId]) { |
| 39 [notificationCenter removeDeliveredNotification:candidate]; | 49 [notificationCenter removeDeliveredNotification:candidate]; |
| 50 [transactionHandler_ closeTransactionIfNeeded]; |
| 40 break; | 51 break; |
| 41 } | 52 } |
| 42 } | 53 } |
| 43 } | 54 } |
| 44 | 55 |
| 45 - (void)closeAllNotifications { | 56 - (void)closeAllNotifications { |
| 46 [[NSUserNotificationCenter defaultUserNotificationCenter] | 57 [[NSUserNotificationCenter defaultUserNotificationCenter] |
| 47 removeAllDeliveredNotifications]; | 58 removeAllDeliveredNotifications]; |
| 59 [transactionHandler_ closeTransactionIfNeeded]; |
| 48 } | 60 } |
| 49 | 61 |
| 50 @end | 62 @end |
| OLD | NEW |