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

Unified Diff: chrome/browser/ui/cocoa/notifications/xpc_mach_port.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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/notifications/xpc_mach_port.mm
diff --git a/chrome/browser/ui/cocoa/notifications/xpc_mach_port.mm b/chrome/browser/ui/cocoa/notifications/xpc_mach_port.mm
new file mode 100644
index 0000000000000000000000000000000000000000..aa8cfba879372d2dc9ab5420419f4d0514a71114
--- /dev/null
+++ b/chrome/browser/ui/cocoa/notifications/xpc_mach_port.mm
@@ -0,0 +1,80 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/ui/cocoa/notifications/xpc_mach_port.h"
+
+#include "base/logging.h"
+#include "base/mac/scoped_nsobject.h"
+
+@class OS_xpc_mach_send;
+
+extern "C" {
+
+OS_xpc_mach_send* xpc_mach_send_create(mach_port_t);
+mach_port_t xpc_mach_send_copy_right(OS_xpc_mach_send*);
+
+} // extern "C"
+
+// Give the compiler declarations for the NSXPCCoder methods.
+@protocol ForwardDeclareXPCCoder
+- (void)encodeXPCObject:(id)object forKey:(id)key;
+- (id)decodeXPCObjectForKey:(id)key;
+@end
+
+namespace {
+
+NSString* const kCrSendRight = @"org.chromium.xpc.MachSendRight";
+
+} // namespace
+
+@implementation CrXPCMachPort {
+ base::mac::ScopedMachSendRight port_;
+}
+
+- (instancetype)initWithMachSendRight:
+ (base::mac::ScopedMachSendRight)sendRight {
+ if ((self = [super init])) {
+ DCHECK(sendRight.is_valid());
+ port_ = std::move(sendRight);
+ }
+ return self;
+}
+
+- (base::mac::ScopedMachSendRight)takeRight {
+ return std::move(port_);
+}
+
+// NSCoding:
+- (instancetype)initWithCoder:(NSCoder*)coder {
+ DCHECK([coder isKindOfClass:NSClassFromString(@"NSXPCDecoder")]);
+ if ((self = [super init])) {
+ id coderAsId = coder;
+
+ OS_xpc_mach_send* xpcObject =
+ [coderAsId decodeXPCObjectForKey:kCrSendRight];
+ if (!xpcObject)
+ return nil;
+
+ port_.reset(xpc_mach_send_copy_right(xpcObject));
+ }
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder*)coder {
+ DCHECK([coder isKindOfClass:NSClassFromString(@"NSXPCEncoder")]);
+ DCHECK(port_.is_valid());
+
+ id coderAsId = coder;
+
+ base::scoped_nsobject<OS_xpc_mach_send> xpcObject(
+ xpc_mach_send_create(port_.get()));
+ [coderAsId encodeXPCObject:xpcObject forKey:kCrSendRight];
+}
+
+// NSSecureCoding:
++ (BOOL)supportsSecureCoding {
+ return YES;
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698