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

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

Issue 2790683002: [Mac] Set the ptype and pid Crashpad annotations for AlertNotificationService.xpc. (Closed)
Patch Set: '' 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <unistd.h>
8
7 #import "base/mac/scoped_nsobject.h" 9 #import "base/mac/scoped_nsobject.h"
10 #include "base/strings/string_number_conversions.h"
8 #import "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" 11 #import "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h"
9 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h" 12 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
10 #import "chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.h" 13 #import "chrome/browser/ui/cocoa/notifications/xpc_transaction_handler.h"
11 #include "third_party/crashpad/crashpad/client/crashpad_client.h" 14 #include "third_party/crashpad/crashpad/client/crashpad_client.h"
15 #include "third_party/crashpad/crashpad/client/crashpad_info.h"
16 #include "third_party/crashpad/crashpad/client/simple_string_dictionary.h"
12 17
13 @class NSUserNotificationCenter; 18 @class NSUserNotificationCenter;
14 19
20 namespace {
21
22 crashpad::SimpleStringDictionary* GetCrashpadAnnotations() {
23 static crashpad::SimpleStringDictionary* annotations = []() {
24 auto* annotations = new crashpad::SimpleStringDictionary();
25 annotations->SetKeyValue("ptype", "AlertNotificationService.xpc");
26 annotations->SetKeyValue("pid", base::IntToString(getpid()).c_str());
27 return annotations;
28 }();
29 return annotations;
30 }
31
32 } // namespace
33
15 @implementation AlertNotificationService { 34 @implementation AlertNotificationService {
16 XPCTransactionHandler* transactionHandler_; 35 XPCTransactionHandler* transactionHandler_;
17 36
18 // Ensures that the XPC service has been configured for crash reporting. 37 // 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 38 // Other messages should not be sent to a new instance of the service
20 // before -setMachExceptionPort: is called. 39 // before -setMachExceptionPort: is called.
40 // Because XPC callouts occur on a concurrent dispatch queue, this must be
41 // accessed in a @synchronized(self) block.
21 BOOL didSetExceptionPort_; 42 BOOL didSetExceptionPort_;
22 } 43 }
23 44
24 - (instancetype)initWithTransactionHandler:(XPCTransactionHandler*)handler { 45 - (instancetype)initWithTransactionHandler:(XPCTransactionHandler*)handler {
25 if ((self = [super init])) { 46 if ((self = [super init])) {
26 transactionHandler_ = handler; 47 transactionHandler_ = handler;
27 } 48 }
28 return self; 49 return self;
29 } 50 }
30 51
31 - (void)setMachExceptionPort:(CrXPCMachPort*)port { 52 - (void)setMachExceptionPort:(CrXPCMachPort*)port {
32 base::mac::ScopedMachSendRight sendRight([port takeRight]); 53 base::mac::ScopedMachSendRight sendRight([port takeRight]);
33 if (!sendRight.is_valid()) { 54 if (!sendRight.is_valid()) {
34 NOTREACHED(); 55 NOTREACHED();
35 return; 56 return;
36 } 57 }
37 58
38 crashpad::CrashpadClient client; 59 @synchronized(self) {
39 didSetExceptionPort_ = client.SetHandlerMachPort(std::move(sendRight)); 60 if (didSetExceptionPort_) {
40 DCHECK(didSetExceptionPort_); 61 return;
62 }
63
64 crashpad::CrashpadClient client;
65 didSetExceptionPort_ = client.SetHandlerMachPort(std::move(sendRight));
66 DCHECK(didSetExceptionPort_);
67
68 crashpad::CrashpadInfo::GetCrashpadInfo()->set_simple_annotations(
69 GetCrashpadAnnotations());
70 }
41 } 71 }
42 72
43 - (void)deliverNotification:(NSDictionary*)notificationData { 73 - (void)deliverNotification:(NSDictionary*)notificationData {
44 DCHECK(didSetExceptionPort_); 74 DCHECK(didSetExceptionPort_);
45 75
46 base::scoped_nsobject<NotificationBuilder> builder( 76 base::scoped_nsobject<NotificationBuilder> builder(
47 [[NotificationBuilder alloc] initWithDictionary:notificationData]); 77 [[NotificationBuilder alloc] initWithDictionary:notificationData]);
48 78
49 NSUserNotification* toast = [builder buildUserNotification]; 79 NSUserNotification* toast = [builder buildUserNotification];
50 [[NSUserNotificationCenter defaultUserNotificationCenter] 80 [[NSUserNotificationCenter defaultUserNotificationCenter]
(...skipping 26 matching lines...) Expand all
77 107
78 - (void)closeAllNotifications { 108 - (void)closeAllNotifications {
79 DCHECK(didSetExceptionPort_); 109 DCHECK(didSetExceptionPort_);
80 110
81 [[NSUserNotificationCenter defaultUserNotificationCenter] 111 [[NSUserNotificationCenter defaultUserNotificationCenter]
82 removeAllDeliveredNotifications]; 112 removeAllDeliveredNotifications];
83 [transactionHandler_ closeTransactionIfNeeded]; 113 [transactionHandler_ closeTransactionIfNeeded];
84 } 114 }
85 115
86 @end 116 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698