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

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

Issue 2748903003: [Mac] Use Crashpad in the AlertNotificationService.xpc. (Closed)
Patch Set: 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
Mark Mentovai 2017/03/14 23:24:51 …and it’s probably not reasonable for us to expose
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 #include "chrome/browser/notifications/notification_platform_bridge_mac.h" 5 #include "chrome/browser/notifications/notification_platform_bridge_mac.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/mac/bundle_locations.h" 11 #include "base/mac/bundle_locations.h"
12 #include "base/mac/foundation_util.h" 12 #include "base/mac/foundation_util.h"
13 #include "base/mac/mac_util.h" 13 #include "base/mac/mac_util.h"
14 #include "base/mac/scoped_mach_port.h"
14 #include "base/mac/scoped_nsobject.h" 15 #include "base/mac/scoped_nsobject.h"
15 #include "base/strings/nullable_string16.h" 16 #include "base/strings/nullable_string16.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/sys_string_conversions.h" 18 #include "base/strings/sys_string_conversions.h"
18 #include "chrome/browser/browser_process.h" 19 #include "chrome/browser/browser_process.h"
19 #include "chrome/browser/notifications/native_notification_display_service.h" 20 #include "chrome/browser/notifications/native_notification_display_service.h"
20 #include "chrome/browser/notifications/notification.h" 21 #include "chrome/browser/notifications/notification.h"
21 #include "chrome/browser/notifications/notification_common.h" 22 #include "chrome/browser/notifications/notification_common.h"
22 #include "chrome/browser/notifications/notification_display_service_factory.h" 23 #include "chrome/browser/notifications/notification_display_service_factory.h"
23 #include "chrome/browser/notifications/persistent_notification_delegate.h" 24 #include "chrome/browser/notifications/persistent_notification_delegate.h"
24 #include "chrome/browser/notifications/platform_notification_service_impl.h" 25 #include "chrome/browser/notifications/platform_notification_service_impl.h"
25 #include "chrome/browser/profiles/profile.h" 26 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/profiles/profile_manager.h" 27 #include "chrome/browser/profiles/profile_manager.h"
27 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h" 28 #include "chrome/browser/ui/cocoa/notifications/notification_builder_mac.h"
29 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
28 #import "chrome/browser/ui/cocoa/notifications/notification_delivery.h" 30 #import "chrome/browser/ui/cocoa/notifications/notification_delivery.h"
29 #include "chrome/browser/ui/cocoa/notifications/notification_constants_mac.h"
30 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac .h" 31 #import "chrome/browser/ui/cocoa/notifications/notification_response_builder_mac .h"
31 #include "chrome/common/features.h" 32 #include "chrome/common/features.h"
32 #include "chrome/grit/generated_resources.h" 33 #include "chrome/grit/generated_resources.h"
34 #include "components/crash/content/app/crashpad.h"
33 #include "components/url_formatter/elide_url.h" 35 #include "components/url_formatter/elide_url.h"
34 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onConstants.h" 36 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onConstants.h"
35 #include "ui/base/l10n/l10n_util_mac.h" 37 #include "ui/base/l10n/l10n_util_mac.h"
36 #include "url/gurl.h" 38 #include "url/gurl.h"
37 #include "url/origin.h" 39 #include "url/origin.h"
38 40
39 @class NSUserNotification; 41 @class NSUserNotification;
40 @class NSUserNotificationCenter; 42 @class NSUserNotificationCenter;
41 43
42 // The mapping from web notifications to NsUserNotification works as follows 44 // The mapping from web notifications to NsUserNotification works as follows
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 shouldPresentNotification:(NSUserNotification*)nsNotification { 423 shouldPresentNotification:(NSUserNotification*)nsNotification {
422 // Always display notifications, regardless of whether the app is foreground. 424 // Always display notifications, regardless of whether the app is foreground.
423 return YES; 425 return YES;
424 } 426 }
425 427
426 @end 428 @end
427 429
428 @implementation AlertDispatcherImpl { 430 @implementation AlertDispatcherImpl {
429 // The connection to the XPC server in charge of delivering alerts. 431 // The connection to the XPC server in charge of delivering alerts.
430 base::scoped_nsobject<NSXPCConnection> xpcConnection_; 432 base::scoped_nsobject<NSXPCConnection> xpcConnection_;
433
434 // YES if the remote object has had |-setMachExceptionPort:| called
435 // since the service was last started, interrupted, or invalidated.
436 // If NO, then -serviceProxy will set the exception port.
437 BOOL setExceptionPort_;
431 } 438 }
432 439
433 - (instancetype)init { 440 - (instancetype)init {
434 if ((self = [super init])) { 441 if ((self = [super init])) {
435 xpcConnection_.reset([[NSXPCConnection alloc] 442 xpcConnection_.reset([[NSXPCConnection alloc]
436 initWithServiceName: 443 initWithServiceName:
437 [NSString 444 [NSString
438 stringWithFormat:notification_constants::kAlertXPCServiceName, 445 stringWithFormat:notification_constants::kAlertXPCServiceName,
439 [base::mac::FrameworkBundle() 446 [base::mac::FrameworkBundle()
440 bundleIdentifier]]]); 447 bundleIdentifier]]]);
441 xpcConnection_.get().remoteObjectInterface = 448 xpcConnection_.get().remoteObjectInterface =
442 [NSXPCInterface interfaceWithProtocol:@protocol(NotificationDelivery)]; 449 [NSXPCInterface interfaceWithProtocol:@protocol(NotificationDelivery)];
443 450
444 xpcConnection_.get().interruptionHandler = ^{ 451 xpcConnection_.get().interruptionHandler = ^{
445 LOG(WARNING) << "connection interrupted: interruptionHandler: "; 452 LOG(WARNING) << "connection interrupted: interruptionHandler: ";
453 setExceptionPort_ = NO;
446 // TODO(miguelg): perhaps add some UMA here. 454 // TODO(miguelg): perhaps add some UMA here.
447 // We will be getting this handler both when the XPC server crashes or 455 // We will be getting this handler both when the XPC server crashes or
448 // when it decides to close the connection. 456 // when it decides to close the connection.
449 }; 457 };
450 xpcConnection_.get().invalidationHandler = ^{ 458 xpcConnection_.get().invalidationHandler = ^{
451 LOG(WARNING) << "connection invalidationHandler received"; 459 LOG(WARNING) << "connection invalidationHandler received";
460 setExceptionPort_ = NO;
452 // This means that the connection should be recreated if it needs 461 // This means that the connection should be recreated if it needs
453 // to be used again. It should not really happen. 462 // to be used again. It should not really happen.
454 DCHECK(false) << "XPC Connection invalidated"; 463 DCHECK(false) << "XPC Connection invalidated";
455 }; 464 };
456 465
457 xpcConnection_.get().exportedInterface = 466 xpcConnection_.get().exportedInterface =
458 [NSXPCInterface interfaceWithProtocol:@protocol(NotificationReply)]; 467 [NSXPCInterface interfaceWithProtocol:@protocol(NotificationReply)];
459 xpcConnection_.get().exportedObject = self; 468 xpcConnection_.get().exportedObject = self;
460 [xpcConnection_ resume]; 469 [xpcConnection_ resume];
461 } 470 }
462 471
463 return self; 472 return self;
464 } 473 }
465 474
466 - (void)dispatchNotification:(NSDictionary*)data { 475 - (void)dispatchNotification:(NSDictionary*)data {
467 [[xpcConnection_ remoteObjectProxy] deliverNotification:data]; 476 [[self serviceProxy] deliverNotification:data];
468 } 477 }
469 478
470 - (void)closeNotificationWithId:(NSString*)notificationId 479 - (void)closeNotificationWithId:(NSString*)notificationId
471 withProfileId:(NSString*)profileId { 480 withProfileId:(NSString*)profileId {
472 [[xpcConnection_ remoteObjectProxy] closeNotificationWithId:notificationId 481 [[self serviceProxy] closeNotificationWithId:notificationId
473 withProfileId:profileId]; 482 withProfileId:profileId];
474 } 483 }
475 484
476 - (void)closeAllNotifications { 485 - (void)closeAllNotifications {
477 [[xpcConnection_ remoteObjectProxy] closeAllNotifications]; 486 [[self serviceProxy] closeAllNotifications];
478 } 487 }
479 488
480 // NotificationReply implementation 489 // NotificationReply:
490
481 - (void)notificationClick:(NSDictionary*)notificationResponseData { 491 - (void)notificationClick:(NSDictionary*)notificationResponseData {
482 NotificationPlatformBridgeMac::ProcessNotificationResponse( 492 NotificationPlatformBridgeMac::ProcessNotificationResponse(
483 notificationResponseData); 493 notificationResponseData);
484 } 494 }
485 495
496 // Private methods:
497
498 // Retrieves the connection's remoteObjectProxy. Always use this as opposed
499 // to going directly through the connection, since this will ensure that the
500 // service has its exception port configured for crash reporting.
501 - (id<NotificationDelivery>)serviceProxy {
502 id<NotificationDelivery> proxy = [xpcConnection_ remoteObjectProxy];
503
504 if (!setExceptionPort_) {
505 base::mac::ScopedMachSendRight exceptionPort(
506 crash_reporter::GetHandlerMachPort());
507 base::scoped_nsobject<CrXPCMachPort> xpcPort(
508 [[CrXPCMachPort alloc] initWithMachSendRight:std::move(exceptionPort)]);
509 [proxy setMachExceptionPort:xpcPort];
510 setExceptionPort_ = YES;
511 }
512
513 return proxy;
514 }
515
486 @end 516 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698