| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | |
| 6 #define CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <map> | |
| 12 #include <memory> | |
| 13 #include <set> | |
| 14 #include <vector> | |
| 15 | |
| 16 #include "base/id_map.h" | |
| 17 #include "base/macros.h" | |
| 18 #include "base/memory/ref_counted.h" | |
| 19 #include "content/child/notifications/notification_dispatcher.h" | |
| 20 #include "content/common/platform_notification_messages.h" | |
| 21 #include "content/public/child/worker_thread.h" | |
| 22 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onManager.h" | |
| 23 | |
| 24 namespace content { | |
| 25 | |
| 26 struct NotificationResources; | |
| 27 struct PlatformNotificationData; | |
| 28 class ThreadSafeSender; | |
| 29 | |
| 30 class NotificationManager : public blink::WebNotificationManager, | |
| 31 public WorkerThread::Observer { | |
| 32 public: | |
| 33 ~NotificationManager() override; | |
| 34 | |
| 35 // |thread_safe_sender| and |notification_dispatcher| are used if | |
| 36 // calling this leads to construction. | |
| 37 static NotificationManager* ThreadSpecificInstance( | |
| 38 ThreadSafeSender* thread_safe_sender, | |
| 39 NotificationDispatcher* notification_dispatcher); | |
| 40 | |
| 41 // WorkerThread::Observer implementation. | |
| 42 void WillStopCurrentWorkerThread() override; | |
| 43 | |
| 44 void show( | |
| 45 const blink::WebSecurityOrigin& origin, | |
| 46 const blink::WebNotificationData& notification_data, | |
| 47 std::unique_ptr<blink::WebNotificationResources> notification_resources, | |
| 48 blink::WebNotificationDelegate* delegate) override; | |
| 49 void showPersistent( | |
| 50 const blink::WebSecurityOrigin& origin, | |
| 51 const blink::WebNotificationData& notification_data, | |
| 52 std::unique_ptr<blink::WebNotificationResources> notification_resources, | |
| 53 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 54 blink::WebNotificationShowCallbacks* callbacks) override; | |
| 55 void getNotifications( | |
| 56 const blink::WebString& filter_tag, | |
| 57 blink::WebServiceWorkerRegistration* service_worker_registration, | |
| 58 blink::WebNotificationGetCallbacks* callbacks) override; | |
| 59 void close(blink::WebNotificationDelegate* delegate) override; | |
| 60 void closePersistent(const blink::WebSecurityOrigin& origin, | |
| 61 int64_t persistent_notification_id) override; | |
| 62 void notifyDelegateDestroyed( | |
| 63 blink::WebNotificationDelegate* delegate) override; | |
| 64 blink::mojom::PermissionStatus checkPermission( | |
| 65 const blink::WebSecurityOrigin& origin) override; | |
| 66 | |
| 67 // Called by the NotificationDispatcher. | |
| 68 bool OnMessageReceived(const IPC::Message& message); | |
| 69 | |
| 70 private: | |
| 71 NotificationManager(ThreadSafeSender* thread_safe_sender, | |
| 72 NotificationDispatcher* notification_dispatcher); | |
| 73 | |
| 74 // IPC message handlers. | |
| 75 void OnDidShow(int notification_id); | |
| 76 void OnDidShowPersistent(int request_id, bool success); | |
| 77 void OnDidClose(int notification_id); | |
| 78 void OnDidClick(int notification_id); | |
| 79 void OnDidGetNotifications( | |
| 80 int request_id, | |
| 81 const std::vector<PersistentNotificationInfo>& notification_infos); | |
| 82 | |
| 83 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | |
| 84 scoped_refptr<NotificationDispatcher> notification_dispatcher_; | |
| 85 | |
| 86 // Tracks pending requests for getting a list of notifications. | |
| 87 IDMap<blink::WebNotificationGetCallbacks, IDMapOwnPointer> | |
| 88 pending_get_notification_requests_; | |
| 89 | |
| 90 // Tracks pending requests for displaying persistent notifications. | |
| 91 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> | |
| 92 pending_show_notification_requests_; | |
| 93 | |
| 94 // Map to store the delegate associated with a notification request Id. | |
| 95 std::map<int, blink::WebNotificationDelegate*> active_page_notifications_; | |
| 96 | |
| 97 DISALLOW_COPY_AND_ASSIGN(NotificationManager); | |
| 98 }; | |
| 99 | |
| 100 } // namespace content | |
| 101 | |
| 102 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | |
| OLD | NEW |