| Index: chrome/browser/notifications/notification_platform_bridge_mac.mm
|
| diff --git a/chrome/browser/notifications/notification_platform_bridge_mac.mm b/chrome/browser/notifications/notification_platform_bridge_mac.mm
|
| index e8f9f1cbc6e15ca045b0a9ba15fd7c33a7436917..85a88cb50b529141cc78012e46e30cde10c5e975 100644
|
| --- a/chrome/browser/notifications/notification_platform_bridge_mac.mm
|
| +++ b/chrome/browser/notifications/notification_platform_bridge_mac.mm
|
| @@ -16,6 +16,7 @@
|
| #include "base/strings/string_number_conversions.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| #include "chrome/browser/browser_process.h"
|
| +#include "chrome/browser/notifications/alert_dispatcher.h"
|
| #include "chrome/browser/notifications/native_notification_display_service.h"
|
| #include "chrome/browser/notifications/notification.h"
|
| #include "chrome/browser/notifications/notification_common.h"
|
| @@ -100,12 +101,6 @@ void DoProcessNotificationResponse(NotificationCommon::Operation operation,
|
|
|
| } // namespace
|
|
|
| -// static
|
| -NotificationPlatformBridge* NotificationPlatformBridge::Create() {
|
| - return new NotificationPlatformBridgeMac(
|
| - [NSUserNotificationCenter defaultUserNotificationCenter]);
|
| -}
|
| -
|
| // A Cocoa class that represents the delegate of NSUserNotificationCenter and
|
| // can forward commands to C++.
|
| @interface NotificationCenterDelegate
|
| @@ -114,7 +109,9 @@ NotificationPlatformBridge* NotificationPlatformBridge::Create() {
|
| @end
|
|
|
| // Interface to communicate with the Alert XPC service.
|
| -@interface NotificationRemoteDispatcher : NSObject
|
| +@interface AlertDispatcherImpl : NSObject<AlertDispatcher>
|
| +
|
| +- (instancetype)init;
|
|
|
| // Deliver a notification to the XPC service to be displayed as an alert.
|
| - (void)dispatchNotification:(NSDictionary*)data;
|
| @@ -129,18 +126,12 @@ NotificationPlatformBridge* NotificationPlatformBridge::Create() {
|
| @end
|
|
|
| // /////////////////////////////////////////////////////////////////////////////
|
| -
|
| NotificationPlatformBridgeMac::NotificationPlatformBridgeMac(
|
| - NSUserNotificationCenter* notification_center)
|
| + NSUserNotificationCenter* notification_center,
|
| + id<AlertDispatcher> alert_dispatcher)
|
| : delegate_([NotificationCenterDelegate alloc]),
|
| notification_center_(notification_center),
|
| -#if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
|
| - notification_remote_dispatcher_(
|
| - [[NotificationRemoteDispatcher alloc] init])
|
| -#else
|
| - notification_remote_dispatcher_(nullptr)
|
| -#endif // ENABLE_XPC_NOTIFICATIONS
|
| -{
|
| + alert_dispatcher_(alert_dispatcher) {
|
| [notification_center_ setDelegate:delegate_.get()];
|
| }
|
|
|
| @@ -150,10 +141,22 @@ NotificationPlatformBridgeMac::~NotificationPlatformBridgeMac() {
|
| // TODO(miguelg) do not remove banners if possible.
|
| [notification_center_ removeAllDeliveredNotifications];
|
| #if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
|
| - [notification_remote_dispatcher_ closeAllNotifications];
|
| + [alert_dispatcher_ closeAllNotifications];
|
| #endif // BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
|
| }
|
|
|
| +// static
|
| +NotificationPlatformBridge* NotificationPlatformBridge::Create() {
|
| +#if BUILDFLAG(ENABLE_XPC_NOTIFICATIONS)
|
| + return new NotificationPlatformBridgeMac(
|
| + [NSUserNotificationCenter defaultUserNotificationCenter],
|
| + [[AlertDispatcherImpl alloc] init]);
|
| +#else
|
| + return new NotificationPlatformBridgeMac(
|
| + [NSUserNotificationCenter defaultUserNotificationCenter], nil);
|
| +#endif // ENABLE_XPC_NOTIFICATIONS
|
| +}
|
| +
|
| void NotificationPlatformBridgeMac::Display(
|
| NotificationCommon::Type notification_type,
|
| const std::string& notification_id,
|
| @@ -229,7 +232,7 @@ void NotificationPlatformBridgeMac::Display(
|
| // banners.
|
| if (notification.never_timeout()) {
|
| NSDictionary* dict = [builder buildDictionary];
|
| - [notification_remote_dispatcher_ dispatchNotification:dict];
|
| + [alert_dispatcher_ dispatchNotification:dict];
|
| } else {
|
| NSUserNotification* toast = [builder buildUserNotification];
|
| [notification_center_ deliverNotification:toast];
|
| @@ -265,9 +268,8 @@ void NotificationPlatformBridgeMac::Close(const std::string& profile_id,
|
| // If no banner existed with that ID try to see if there is an alert
|
| // in the xpc server.
|
| if (!notification_removed) {
|
| - [notification_remote_dispatcher_
|
| - closeNotificationWithId:candidate_id
|
| - withProfileId:current_profile_id];
|
| + [alert_dispatcher_ closeNotificationWithId:candidate_id
|
| + withProfileId:current_profile_id];
|
| }
|
| #endif // ENABLE_XPC_NOTIFICATIONS
|
| }
|
| @@ -424,7 +426,7 @@ bool NotificationPlatformBridgeMac::VerifyNotificationData(
|
|
|
| @end
|
|
|
| -@implementation NotificationRemoteDispatcher {
|
| +@implementation AlertDispatcherImpl {
|
| // The connection to the XPC server in charge of delivering alerts.
|
| base::scoped_nsobject<NSXPCConnection> xpcConnection_;
|
| }
|
|
|