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/notifications/stub_alert_dispatcher_mac.h" | 5 #import "chrome/browser/notifications/stub_alert_dispatcher_mac.h" |
6 | 6 |
| 7 #include <set> |
| 8 #include <string> |
| 9 |
| 10 #include "base/callback.h" |
7 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/sys_string_conversions.h" |
8 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | 14 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" |
9 | 15 |
10 @implementation StubAlertDispatcher { | 16 @implementation StubAlertDispatcher { |
11 base::scoped_nsobject<NSMutableArray> alerts_; | 17 base::scoped_nsobject<NSMutableArray> alerts_; |
12 } | 18 } |
13 | 19 |
14 - (instancetype)init { | 20 - (instancetype)init { |
15 if ((self = [super init])) { | 21 if ((self = [super init])) { |
16 alerts_.reset([[NSMutableArray alloc] init]); | 22 alerts_.reset([[NSMutableArray alloc] init]); |
17 } | 23 } |
(...skipping 18 matching lines...) Expand all Loading... |
36 [alerts_ removeObject:toast]; | 42 [alerts_ removeObject:toast]; |
37 break; | 43 break; |
38 } | 44 } |
39 } | 45 } |
40 } | 46 } |
41 | 47 |
42 - (void)closeAllNotifications { | 48 - (void)closeAllNotifications { |
43 [alerts_ removeAllObjects]; | 49 [alerts_ removeAllObjects]; |
44 } | 50 } |
45 | 51 |
| 52 - (void) |
| 53 getDisplayedAlertsForProfileId:(NSString*)profileId |
| 54 withNotificationCenter:(NSUserNotificationCenter*)notificationCenter |
| 55 callback:(DisplayedNotificationsCallback)callback { |
| 56 std::unique_ptr<std::set<std::string>> displayedNotifications = |
| 57 base::MakeUnique<std::set<std::string>>(); |
| 58 for (NSUserNotification* toast in |
| 59 [notificationCenter deliveredNotifications]) { |
| 60 NSString* toastProfileId = [toast.userInfo |
| 61 objectForKey:notification_constants::kNotificationProfileId]; |
| 62 if ([toastProfileId isEqualToString:profileId]) { |
| 63 displayedNotifications->insert(base::SysNSStringToUTF8([toast.userInfo |
| 64 objectForKey:notification_constants::kNotificationId])); |
| 65 } |
| 66 } |
| 67 |
| 68 callback.Run(std::move(displayedNotifications), |
| 69 true /* supports_synchronization */); |
| 70 } |
| 71 |
46 - (NSArray*)alerts { | 72 - (NSArray*)alerts { |
47 return [[alerts_ copy] autorelease]; | 73 return [[alerts_ copy] autorelease]; |
48 } | 74 } |
49 | 75 |
50 @end | 76 @end |
OLD | NEW |