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

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

Issue 2709213005: [Mac] Add XPC alerts to GetDisplayedNotifications (Closed)
Patch Set: review + linux support Created 3 years, 8 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 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
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 incognito:(BOOL)incognito
55 notificationCenter:(NSUserNotificationCenter*)notificationCenter
56 callback:(GetDisplayedNotificationsCallback)callback {
57 std::unique_ptr<std::set<std::string>> displayedNotifications =
58 base::MakeUnique<std::set<std::string>>();
59 for (NSUserNotification* toast in
60 [notificationCenter deliveredNotifications]) {
61 NSString* toastProfileId = [toast.userInfo
62 objectForKey:notification_constants::kNotificationProfileId];
63 if ([toastProfileId isEqualToString:profileId]) {
64 displayedNotifications->insert(base::SysNSStringToUTF8([toast.userInfo
65 objectForKey:notification_constants::kNotificationId]));
66 }
67 }
68
69 callback.Run(std::move(displayedNotifications),
70 true /* supports_synchronization */);
71 }
72
46 - (NSArray*)alerts { 73 - (NSArray*)alerts {
47 return [[alerts_ copy] autorelease]; 74 return [[alerts_ copy] autorelease];
48 } 75 }
49 76
50 @end 77 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698