OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/notifications/stub_notification_center_mac.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "base/mac/scoped_nsobject.h" | |
9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" | |
10 | |
11 @implementation StubNotificationCenter { | |
12 base::scoped_nsobject<NSMutableArray> alerts_; | |
13 } | |
14 | |
15 - (instancetype)init { | |
16 if ((self = [super init])) { | |
17 alerts_.reset([[NSMutableArray alloc] init]); | |
18 } | |
19 return self; | |
20 } | |
21 | |
22 // The default implementation adds some extra checks on what constructors can | |
23 // be used. isKindOfClass bypasses all of that. | |
24 - (BOOL)isKindOfClass:(Class)cls { | |
25 if ([cls isEqual:NSClassFromString(@"_NSConcreteUserNotificationCenter")]) { | |
26 return YES; | |
27 } | |
28 return [super isKindOfClass:cls]; | |
29 } | |
30 | |
31 - (void)deliverNotification:(NSUserNotification*)notification { | |
32 [alerts_ addObject:notification]; | |
33 } | |
34 | |
35 - (NSArray*)deliveredNotifications { | |
36 return [[alerts_ copy] autorelease]; | |
37 } | |
38 | |
39 - (void)removeDeliveredNotification:(NSUserNotification*)notification { | |
40 NSString* notificationId = [notification.userInfo | |
41 objectForKey:notification_constants::kNotificationId]; | |
42 NSString* profileId = [notification.userInfo | |
43 objectForKey:notification_constants::kNotificationProfileId]; | |
44 DCHECK(profileId); | |
45 DCHECK(notificationId); | |
46 for (NSUserNotification* toast in alerts_.get()) { | |
47 NSString* toastId = | |
48 [toast.userInfo objectForKey:notification_constants::kNotificationId]; | |
49 NSString* persistentProfileId = [toast.userInfo | |
50 objectForKey:notification_constants::kNotificationProfileId]; | |
51 if ([toastId isEqualToString:notificationId] && | |
52 [persistentProfileId isEqualToString:profileId]) { | |
53 [alerts_ removeObject:toast]; | |
54 break; | |
55 } | |
56 } | |
57 } | |
58 | |
59 - (void)removeAllDeliveredNotifications { | |
60 [alerts_ removeAllObjects]; | |
61 } | |
62 | |
63 - (void)setDelegate:(NSUserNotificationCenterDelegate*)delegate { | |
Robert Sesek
2016/11/01 17:09:01
Leave a comment why you nop this out?
Miguel Garcia
2016/11/07 14:18:41
Done.
| |
64 } | |
65 | |
66 @end | |
OLD | NEW |