Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_MAC_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_MAC_H_ |
| 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_MAC_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_MAC_H_ |
| 7 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "chrome/browser/notifications/notification_common.h" | 14 #include "chrome/browser/notifications/notification_common.h" |
| 15 #include "chrome/browser/notifications/notification_platform_bridge.h" | 15 #include "chrome/browser/notifications/notification_platform_bridge.h" |
| 16 | 16 |
| 17 class Notification; | 17 class Notification; |
| 18 @class NotificationCenterDelegate; | 18 @class NotificationCenterDelegate; |
| 19 @class NSDictionary; | 19 @class NSDictionary; |
| 20 @class NSUserNotificationCenter; | 20 @class NSUserNotificationCenter; |
| 21 class PrefService; | 21 class PrefService; |
| 22 @class NSXPCConnection; | |
| 23 | |
| 24 // Interface to communicate with the Alert XPC service. | |
|
Peter Beverloo
2016/07/19 17:31:40
This could use a little bit more colour to explain
| |
| 25 @interface NotificationRemoteDispatcher : NSObject | |
| 26 | |
| 27 // The connection to the XPC server in charge of delivering alerts | |
|
Peter Beverloo
2016/07/19 17:31:40
Here, and lines 56, 68 and 71: sentences end with
| |
| 28 @property(readonly) NSXPCConnection* xpcConnection; | |
| 29 | |
| 30 - (instancetype)init; | |
| 31 - (void)dispatchNotification:(NSDictionary*)data; | |
| 32 | |
| 33 @end | |
| 22 | 34 |
| 23 // This class is an implementation of NotificationPlatformBridge that will | 35 // This class is an implementation of NotificationPlatformBridge that will |
| 24 // send platform notifications to the the MacOSX notification center. | 36 // send platform notifications to the the MacOSX notification center. |
| 25 class NotificationPlatformBridgeMac : public NotificationPlatformBridge { | 37 class NotificationPlatformBridgeMac : public NotificationPlatformBridge { |
| 26 public: | 38 public: |
| 27 explicit NotificationPlatformBridgeMac( | 39 explicit NotificationPlatformBridgeMac( |
| 28 NSUserNotificationCenter* notification_center); | 40 NSUserNotificationCenter* notification_center); |
| 29 ~NotificationPlatformBridgeMac() override; | 41 ~NotificationPlatformBridgeMac() override; |
| 30 | 42 |
| 31 // NotificationPlatformBridge implementation. | 43 // NotificationPlatformBridge implementation. |
| 32 void Display(NotificationCommon::Type notification_type, | 44 void Display(NotificationCommon::Type notification_type, |
| 33 const std::string& notification_id, | 45 const std::string& notification_id, |
| 34 const std::string& profile_id, | 46 const std::string& profile_id, |
| 35 bool incognito, | 47 bool incognito, |
| 36 const Notification& notification) override; | 48 const Notification& notification) override; |
| 37 void Close(const std::string& profile_id, | 49 void Close(const std::string& profile_id, |
| 38 const std::string& notification_id) override; | 50 const std::string& notification_id) override; |
| 39 bool GetDisplayed(const std::string& profile_id, | 51 bool GetDisplayed(const std::string& profile_id, |
| 40 bool incognito, | 52 bool incognito, |
| 41 std::set<std::string>* notifications) const override; | 53 std::set<std::string>* notifications) const override; |
| 42 bool SupportsNotificationCenter() const override; | 54 bool SupportsNotificationCenter() const override; |
| 43 | 55 |
| 56 // Processes a notification response | |
| 57 static void ProcessNotificationResponse(NSDictionary* response); | |
| 58 | |
| 44 // Validates contents of the |response| dictionary as received from the system | 59 // Validates contents of the |response| dictionary as received from the system |
| 45 // when a notification gets activated. | 60 // when a notification gets activated. |
| 46 static bool VerifyNotificationData(NSDictionary* response) WARN_UNUSED_RESULT; | 61 static bool VerifyNotificationData(NSDictionary* response) WARN_UNUSED_RESULT; |
| 47 | 62 |
| 48 private: | 63 private: |
| 49 // Cocoa class that receives callbacks from the NSUserNotificationCenter. | 64 // Cocoa class that receives callbacks from the NSUserNotificationCenter. |
| 50 base::scoped_nsobject<NotificationCenterDelegate> delegate_; | 65 base::scoped_nsobject<NotificationCenterDelegate> delegate_; |
| 51 | 66 |
| 52 // The notification center to use, this can be overriden in tests | 67 // The notification center to use for local banner notifications, |
| 68 // this can be overriden in tests | |
| 53 NSUserNotificationCenter* notification_center_; | 69 NSUserNotificationCenter* notification_center_; |
| 54 | 70 |
| 71 // The object in charge of dispatching remote notifications | |
| 72 base::scoped_nsobject<NotificationRemoteDispatcher> | |
| 73 notification_remote_dispatcher_; | |
| 74 | |
| 55 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeMac); | 75 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeMac); |
| 56 }; | 76 }; |
| 57 | 77 |
| 58 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_MAC_H_ | 78 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_MAC_H_ |
| OLD | NEW |