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

Side by Side Diff: chrome/browser/ui/cocoa/notifications/alert_notification_service.mm

Issue 2748903003: [Mac] Use Crashpad in the AlertNotificationService.xpc. (Closed)
Patch Set: Comments 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 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 #import "chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.h"
11 #include "third_party/crashpad/crashpad/client/crashpad_client.h"
11 12
12 @class NSUserNotificationCenter; 13 @class NSUserNotificationCenter;
13 14
14 @implementation AlertNotificationService { 15 @implementation AlertNotificationService {
15 XPCTransactionHandler* transactionHandler_; 16 XPCTransactionHandler* transactionHandler_;
17
18 // Ensures that the XPC service has been configured for crash reporting.
19 // Other messages should not be sent to a new instance of the service
20 // before -setMachExceptionPort: is called.
21 BOOL didSetExceptionPort_;
16 } 22 }
17 23
18 - (instancetype)initWithTransactionHandler:(XPCTransactionHandler*)handler { 24 - (instancetype)initWithTransactionHandler:(XPCTransactionHandler*)handler {
19 if ((self = [super init])) { 25 if ((self = [super init])) {
20 transactionHandler_ = handler; 26 transactionHandler_ = handler;
21 } 27 }
22 return self; 28 return self;
23 } 29 }
24 30
31 - (void)setMachExceptionPort:(CrXPCMachPort*)port {
32 base::mac::ScopedMachSendRight sendRight([port takeRight]);
33 if (!sendRight.is_valid()) {
34 NOTREACHED();
35 return;
36 }
37
38 crashpad::CrashpadClient client;
39 didSetExceptionPort_ = client.SetHandlerMachPort(std::move(sendRight));
40 DCHECK(didSetExceptionPort_);
41 }
42
25 - (void)deliverNotification:(NSDictionary*)notificationData { 43 - (void)deliverNotification:(NSDictionary*)notificationData {
44 DCHECK(didSetExceptionPort_);
45
26 base::scoped_nsobject<NotificationBuilder> builder( 46 base::scoped_nsobject<NotificationBuilder> builder(
27 [[NotificationBuilder alloc] initWithDictionary:notificationData]); 47 [[NotificationBuilder alloc] initWithDictionary:notificationData]);
28 48
29 NSUserNotification* toast = [builder buildUserNotification]; 49 NSUserNotification* toast = [builder buildUserNotification];
30 [[NSUserNotificationCenter defaultUserNotificationCenter] 50 [[NSUserNotificationCenter defaultUserNotificationCenter]
31 deliverNotification:toast]; 51 deliverNotification:toast];
32 [transactionHandler_ openTransactionIfNeeded]; 52 [transactionHandler_ openTransactionIfNeeded];
33 } 53 }
34 54
35 - (void)closeNotificationWithId:(NSString*)notificationId 55 - (void)closeNotificationWithId:(NSString*)notificationId
36 withProfileId:(NSString*)profileId { 56 withProfileId:(NSString*)profileId {
57 DCHECK(didSetExceptionPort_);
58
37 NSUserNotificationCenter* notificationCenter = 59 NSUserNotificationCenter* notificationCenter =
38 [NSUserNotificationCenter defaultUserNotificationCenter]; 60 [NSUserNotificationCenter defaultUserNotificationCenter];
39 for (NSUserNotification* candidate in 61 for (NSUserNotification* candidate in
40 [notificationCenter deliveredNotifications]) { 62 [notificationCenter deliveredNotifications]) {
41 NSString* candidateId = [candidate.userInfo 63 NSString* candidateId = [candidate.userInfo
42 objectForKey:notification_constants::kNotificationId]; 64 objectForKey:notification_constants::kNotificationId];
43 65
44 NSString* candidateProfileId = [candidate.userInfo 66 NSString* candidateProfileId = [candidate.userInfo
45 objectForKey:notification_constants::kNotificationProfileId]; 67 objectForKey:notification_constants::kNotificationProfileId];
46 68
47 if ([candidateId isEqualToString:notificationId] && 69 if ([candidateId isEqualToString:notificationId] &&
48 [profileId isEqualToString:candidateProfileId]) { 70 [profileId isEqualToString:candidateProfileId]) {
49 [notificationCenter removeDeliveredNotification:candidate]; 71 [notificationCenter removeDeliveredNotification:candidate];
50 [transactionHandler_ closeTransactionIfNeeded]; 72 [transactionHandler_ closeTransactionIfNeeded];
51 break; 73 break;
52 } 74 }
53 } 75 }
54 } 76 }
55 77
56 - (void)closeAllNotifications { 78 - (void)closeAllNotifications {
79 DCHECK(didSetExceptionPort_);
80
57 [[NSUserNotificationCenter defaultUserNotificationCenter] 81 [[NSUserNotificationCenter defaultUserNotificationCenter]
58 removeAllDeliveredNotifications]; 82 removeAllDeliveredNotifications];
59 [transactionHandler_ closeTransactionIfNeeded]; 83 [transactionHandler_ closeTransactionIfNeeded];
60 } 84 }
61 85
62 @end 86 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698