OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ |
6 #define CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ | 6 #define CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <queue> | 10 #include <queue> |
11 #include <set> | 11 #include <set> |
12 #include <string> | 12 #include <string> |
13 | 13 |
14 #include "base/callback.h" | 14 #include "base/callback.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/memory/weak_ptr.h" | 16 #include "base/memory/weak_ptr.h" |
17 #include "chrome/browser/notifications/notification_common.h" | 17 #include "chrome/browser/notifications/notification_common.h" |
18 #include "chrome/browser/notifications/notification_display_service.h" | 18 #include "chrome/browser/notifications/notification_display_service.h" |
19 | 19 |
20 namespace base { | |
21 class NullableString16; | |
22 } | |
23 | |
24 class MessageCenterDisplayService; | 20 class MessageCenterDisplayService; |
25 class Notification; | 21 class Notification; |
26 class NotificationHandler; | |
27 class NotificationPlatformBridge; | 22 class NotificationPlatformBridge; |
28 class Profile; | 23 class Profile; |
29 | 24 |
30 // A class to display and interact with notifications in native notification | 25 // A class to display and interact with notifications in native notification |
31 // centers on platforms that support it. | 26 // centers on platforms that support it. |
32 class NativeNotificationDisplayService : public NotificationDisplayService { | 27 class NativeNotificationDisplayService : public NotificationDisplayService { |
33 public: | 28 public: |
34 NativeNotificationDisplayService( | 29 NativeNotificationDisplayService( |
35 Profile* profile, | 30 Profile* profile, |
36 NotificationPlatformBridge* notification_bridge); | 31 NotificationPlatformBridge* notification_bridge); |
37 ~NativeNotificationDisplayService() override; | 32 ~NativeNotificationDisplayService() override; |
38 | 33 |
39 // NotificationDisplayService implementation. | 34 // NotificationDisplayService implementation. |
40 void Display(NotificationCommon::Type notification_type, | 35 void Display(NotificationCommon::Type notification_type, |
41 const std::string& notification_id, | 36 const std::string& notification_id, |
42 const Notification& notification) override; | 37 const Notification& notification) override; |
43 void Close(NotificationCommon::Type notification_type, | 38 void Close(NotificationCommon::Type notification_type, |
44 const std::string& notification_id) override; | 39 const std::string& notification_id) override; |
45 void GetDisplayed(const DisplayedNotificationsCallback& callback) override; | 40 void GetDisplayed(const DisplayedNotificationsCallback& callback) override; |
46 | 41 |
47 // Used by the notification bridge to propagate back events (click, close...). | |
48 void ProcessNotificationOperation(NotificationCommon::Operation operation, | |
49 NotificationCommon::Type notification_type, | |
50 const std::string& origin, | |
51 const std::string& notification_id, | |
52 int action_index, | |
53 const base::NullableString16& reply); | |
54 | |
55 // Registers an implementation object to handle notification operations | |
56 // for |notification_type|. | |
57 void AddNotificationHandler(NotificationCommon::Type notification_type, | |
58 std::unique_ptr<NotificationHandler> handler); | |
59 private: | 42 private: |
60 NotificationHandler* GetNotificationHandler( | |
61 NotificationCommon::Type notification_type); | |
62 | |
63 // Called by |notification_bridge_| when it is finished | 43 // Called by |notification_bridge_| when it is finished |
64 // initializing. |success| indicates it is ready to be used. | 44 // initializing. |success| indicates it is ready to be used. |
65 void OnNotificationPlatformBridgeReady(bool success); | 45 void OnNotificationPlatformBridgeReady(bool success); |
66 | 46 |
67 Profile* profile_; | 47 Profile* profile_; |
68 | 48 |
69 NotificationPlatformBridge* notification_bridge_; | 49 NotificationPlatformBridge* notification_bridge_; |
70 // Indicates if |notification_bridge_| is ready to be used. | 50 // Indicates if |notification_bridge_| is ready to be used. |
71 bool notification_bridge_ready_; | 51 bool notification_bridge_ready_; |
72 | 52 |
73 // MessageCenterDisplayService to fallback on if initialization of | 53 // MessageCenterDisplayService to fallback on if initialization of |
74 // |notification_bridge_| failed. | 54 // |notification_bridge_| failed. |
75 std::unique_ptr<MessageCenterDisplayService> message_center_display_service_; | 55 std::unique_ptr<MessageCenterDisplayService> message_center_display_service_; |
76 | 56 |
77 // Tasks that need to be run once we have the initialization status | 57 // Tasks that need to be run once we have the initialization status |
78 // for |notification_bridge_|. | 58 // for |notification_bridge_|. |
79 std::queue<base::OnceClosure> actions_; | 59 std::queue<base::OnceClosure> actions_; |
80 | 60 |
81 std::map<NotificationCommon::Type, std::unique_ptr<NotificationHandler>> | |
82 notification_handlers_; | |
83 | |
84 base::WeakPtrFactory<NativeNotificationDisplayService> weak_factory_; | 61 base::WeakPtrFactory<NativeNotificationDisplayService> weak_factory_; |
85 | 62 |
86 DISALLOW_COPY_AND_ASSIGN(NativeNotificationDisplayService); | 63 DISALLOW_COPY_AND_ASSIGN(NativeNotificationDisplayService); |
87 }; | 64 }; |
88 | 65 |
89 #endif // CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ | 66 #endif // CHROME_BROWSER_NOTIFICATIONS_NATIVE_NOTIFICATION_DISPLAY_SERVICE_H_ |
OLD | NEW |