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/alert_dispatcher.h" | |
14 #include "chrome/browser/notifications/notification_common.h" | 15 #include "chrome/browser/notifications/notification_common.h" |
15 #include "chrome/browser/notifications/notification_platform_bridge.h" | 16 #include "chrome/browser/notifications/notification_platform_bridge.h" |
16 | 17 |
17 class Notification; | 18 class Notification; |
18 @class NotificationCenterDelegate; | 19 @class NotificationCenterDelegate; |
19 @class NotificationRemoteDispatcher; | |
20 @class NSDictionary; | 20 @class NSDictionary; |
21 @class NSUserNotificationCenter; | 21 @class NSUserNotificationCenter; |
22 @class NSXPCConnection; | 22 @class NSXPCConnection; |
23 class PrefService; | 23 class PrefService; |
24 | 24 |
25 // This class is an implementation of NotificationPlatformBridge that will | 25 // This class is an implementation of NotificationPlatformBridge that will |
26 // send platform notifications to the the MacOSX notification center. | 26 // send platform notifications to the the MacOSX notification center. |
27 class NotificationPlatformBridgeMac : public NotificationPlatformBridge { | 27 class NotificationPlatformBridgeMac : public NotificationPlatformBridge { |
28 public: | 28 public: |
29 explicit NotificationPlatformBridgeMac( | 29 NotificationPlatformBridgeMac(NSUserNotificationCenter* notification_center, |
30 NSUserNotificationCenter* notification_center); | 30 id<AlertDispatcher> alert_dispatcher); |
Robert Sesek
2016/11/07 17:51:18
What's the ownership of the alert_dispatcher here?
Miguel Garcia
2016/11/10 12:46:52
So it is owned by the NotificationPlatformBridgeMa
Robert Sesek
2016/11/10 23:52:41
Right.
Miguel Garcia
2016/11/11 15:26:40
Done.
| |
31 | |
31 ~NotificationPlatformBridgeMac() override; | 32 ~NotificationPlatformBridgeMac() override; |
32 | 33 |
33 // NotificationPlatformBridge implementation. | 34 // NotificationPlatformBridge implementation. |
34 void Display(NotificationCommon::Type notification_type, | 35 void Display(NotificationCommon::Type notification_type, |
35 const std::string& notification_id, | 36 const std::string& notification_id, |
36 const std::string& profile_id, | 37 const std::string& profile_id, |
37 bool incognito, | 38 bool incognito, |
38 const Notification& notification) override; | 39 const Notification& notification) override; |
40 | |
39 void Close(const std::string& profile_id, | 41 void Close(const std::string& profile_id, |
40 const std::string& notification_id) override; | 42 const std::string& notification_id) override; |
41 bool GetDisplayed(const std::string& profile_id, | 43 bool GetDisplayed(const std::string& profile_id, |
42 bool incognito, | 44 bool incognito, |
43 std::set<std::string>* notifications) const override; | 45 std::set<std::string>* notifications) const override; |
44 | 46 |
45 // Processes a notification response generated from a user action | 47 // Processes a notification response generated from a user action |
46 // (click close, etc.). | 48 // (click close, etc.). |
47 static void ProcessNotificationResponse(NSDictionary* response); | 49 static void ProcessNotificationResponse(NSDictionary* response); |
48 | 50 |
49 // Validates contents of the |response| dictionary as received from the system | 51 // Validates contents of the |response| dictionary as received from the system |
50 // when a notification gets activated. | 52 // when a notification gets activated. |
51 static bool VerifyNotificationData(NSDictionary* response) WARN_UNUSED_RESULT; | 53 static bool VerifyNotificationData(NSDictionary* response) WARN_UNUSED_RESULT; |
52 | 54 |
53 private: | 55 private: |
54 // Cocoa class that receives callbacks from the NSUserNotificationCenter. | 56 // Cocoa class that receives callbacks from the NSUserNotificationCenter. |
55 base::scoped_nsobject<NotificationCenterDelegate> delegate_; | 57 base::scoped_nsobject<NotificationCenterDelegate> delegate_; |
56 | 58 |
57 // The notification center to use for local banner notifications, | 59 // The notification center to use for local banner notifications, |
58 // this can be overriden in tests. | 60 // this can be overriden in tests. |
59 NSUserNotificationCenter* notification_center_; | 61 NSUserNotificationCenter* notification_center_; |
60 | 62 |
61 // The object in charge of dispatching remote notifications. | 63 // The object in charge of dispatching remote notifications. |
62 base::scoped_nsobject<NotificationRemoteDispatcher> | 64 // id<AlertDispatcher> |
63 notification_remote_dispatcher_; | 65 base::scoped_nsobject<id> alert_dispatcher_; |
Miguel Garcia
2016/11/07 14:24:14
I have not found a better way to define that the w
Robert Sesek
2016/11/07 17:51:18
scoped_nsprotocol<id<AlertDispatcher>> ?
Miguel Garcia
2016/11/10 12:46:52
That seems to expect an object of type id<AlertDis
Robert Sesek
2016/11/10 23:52:41
Did you try my suggestion? It should work:
https:
Miguel Garcia
2016/11/11 15:26:40
I had misread your suggestion (scoped_nsobject vs
| |
64 | 66 |
65 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeMac); | 67 DISALLOW_COPY_AND_ASSIGN(NotificationPlatformBridgeMac); |
66 }; | 68 }; |
67 | 69 |
68 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_MAC_H_ | 70 #endif // CHROME_BROWSER_NOTIFICATIONS_NOTIFICATION_PLATFORM_BRIDGE_MAC_H_ |
OLD | NEW |