| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | 5 #ifndef CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ |
| 6 #define CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | 6 #define CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 void showPersistent( | 49 void showPersistent( |
| 50 const blink::WebSecurityOrigin& origin, | 50 const blink::WebSecurityOrigin& origin, |
| 51 const blink::WebNotificationData& notification_data, | 51 const blink::WebNotificationData& notification_data, |
| 52 std::unique_ptr<blink::WebNotificationResources> notification_resources, | 52 std::unique_ptr<blink::WebNotificationResources> notification_resources, |
| 53 blink::WebServiceWorkerRegistration* service_worker_registration, | 53 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 54 blink::WebNotificationShowCallbacks* callbacks) override; | 54 blink::WebNotificationShowCallbacks* callbacks) override; |
| 55 void getNotifications( | 55 void getNotifications( |
| 56 const blink::WebString& filter_tag, | 56 const blink::WebString& filter_tag, |
| 57 blink::WebServiceWorkerRegistration* service_worker_registration, | 57 blink::WebServiceWorkerRegistration* service_worker_registration, |
| 58 blink::WebNotificationGetCallbacks* callbacks) override; | 58 blink::WebNotificationGetCallbacks* callbacks) override; |
| 59 void close(blink::WebNotificationDelegate* delegate) override; | 59 void close(const blink::WebSecurityOrigin& origin, |
| 60 void closePersistent(const blink::WebSecurityOrigin& origin, | 60 const blink::WebString& tag, |
| 61 const blink::WebString& tag, | 61 const blink::WebString& notification_id) override; |
| 62 const blink::WebString& notification_id) override; | |
| 63 void notifyDelegateDestroyed( | 62 void notifyDelegateDestroyed( |
| 64 blink::WebNotificationDelegate* delegate) override; | 63 blink::WebNotificationDelegate* delegate) override; |
| 65 | 64 |
| 66 // Called by the NotificationDispatcher. | 65 // Called by the NotificationDispatcher. |
| 67 bool OnMessageReceived(const IPC::Message& message); | 66 bool OnMessageReceived(const IPC::Message& message); |
| 68 | 67 |
| 69 private: | 68 private: |
| 70 NotificationManager(ThreadSafeSender* thread_safe_sender, | 69 NotificationManager(ThreadSafeSender* thread_safe_sender, |
| 71 NotificationDispatcher* notification_dispatcher); | 70 NotificationDispatcher* notification_dispatcher); |
| 72 | 71 |
| 73 // IPC message handlers. | 72 // IPC message handlers. |
| 74 void OnDidShow(int notification_id); | 73 void OnDidShow(int non_persistent_notification_id, |
| 74 const std::string& notification_id); |
| 75 void OnDidShowPersistent(int request_id, bool success); | 75 void OnDidShowPersistent(int request_id, bool success); |
| 76 void OnDidClose(int notification_id); | 76 void OnDidClose(int non_persistent_notification_id, |
| 77 void OnDidClick(int notification_id); | 77 const std::string& notification_id); |
| 78 void OnDidClick(int non_persistent_notification_id); |
| 78 void OnDidGetNotifications( | 79 void OnDidGetNotifications( |
| 79 int request_id, | 80 int request_id, |
| 80 const std::vector<PersistentNotificationInfo>& notification_infos); | 81 const std::vector<PersistentNotificationInfo>& notification_infos); |
| 81 | 82 |
| 82 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 83 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
| 83 scoped_refptr<NotificationDispatcher> notification_dispatcher_; | 84 scoped_refptr<NotificationDispatcher> notification_dispatcher_; |
| 84 | 85 |
| 85 // Tracks pending requests for getting a list of notifications. | 86 // Tracks pending requests for getting a list of notifications. |
| 86 IDMap<blink::WebNotificationGetCallbacks, IDMapOwnPointer> | 87 IDMap<blink::WebNotificationGetCallbacks, IDMapOwnPointer> |
| 87 pending_get_notification_requests_; | 88 pending_get_notification_requests_; |
| 88 | 89 |
| 89 // Tracks pending requests for displaying persistent notifications. | 90 // Tracks pending requests for displaying persistent notifications. |
| 90 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> | 91 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> |
| 91 pending_show_notification_requests_; | 92 pending_show_notification_requests_; |
| 92 | 93 |
| 93 // Structure holding the information for active non-persistent notifications. | 94 // Map from the notification ID to the associated delegate for non-persistent |
| 94 struct ActiveNotificationData { | 95 // notifications, for the purposes of triggering events. |
| 95 ActiveNotificationData() = default; | 96 std::unordered_map<int, blink::WebNotificationDelegate*> |
| 96 ActiveNotificationData(blink::WebNotificationDelegate* delegate, | 97 non_persistent_notifications_; |
| 97 const GURL& origin, | |
| 98 const std::string& tag); | |
| 99 ~ActiveNotificationData(); | |
| 100 | 98 |
| 101 blink::WebNotificationDelegate* delegate = nullptr; | 99 // Association from the notification ID string to the non-persistent |
| 102 GURL origin; | 100 // notification ID for non-persistent notifications. |
| 103 std::string tag; | 101 std::unordered_map<std::string, int> non_persistent_notification_ids_; |
| 104 }; | |
| 105 | |
| 106 // Map to store the delegate associated with a notification request Id. | |
| 107 std::unordered_map<int, ActiveNotificationData> active_page_notifications_; | |
| 108 | 102 |
| 109 DISALLOW_COPY_AND_ASSIGN(NotificationManager); | 103 DISALLOW_COPY_AND_ASSIGN(NotificationManager); |
| 110 }; | 104 }; |
| 111 | 105 |
| 112 } // namespace content | 106 } // namespace content |
| 113 | 107 |
| 114 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | 108 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ |
| OLD | NEW |