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 |
11 #include <map> | 11 #include <map> |
| 12 #include <memory> |
12 #include <set> | 13 #include <set> |
13 #include <vector> | 14 #include <vector> |
14 | 15 |
15 #include "base/id_map.h" | 16 #include "base/id_map.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
18 #include "base/single_thread_task_runner.h" | |
19 #include "content/child/notifications/notification_dispatcher.h" | 19 #include "content/child/notifications/notification_dispatcher.h" |
20 #include "content/child/notifications/pending_notifications_tracker.h" | |
21 #include "content/common/platform_notification_messages.h" | 20 #include "content/common/platform_notification_messages.h" |
22 #include "content/public/child/worker_thread.h" | 21 #include "content/public/child/worker_thread.h" |
23 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onManager.h" | 22 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati
onManager.h" |
24 | 23 |
25 namespace content { | 24 namespace content { |
26 | 25 |
27 struct NotificationResources; | 26 struct NotificationResources; |
28 struct PlatformNotificationData; | 27 struct PlatformNotificationData; |
29 class ThreadSafeSender; | 28 class ThreadSafeSender; |
30 | 29 |
31 class NotificationManager : public blink::WebNotificationManager, | 30 class NotificationManager : public blink::WebNotificationManager, |
32 public WorkerThread::Observer { | 31 public WorkerThread::Observer { |
33 public: | 32 public: |
34 ~NotificationManager() override; | 33 ~NotificationManager() override; |
35 | 34 |
36 // |thread_safe_sender| and |notification_dispatcher| are used if | 35 // |thread_safe_sender| and |notification_dispatcher| are used if |
37 // calling this leads to construction. | 36 // calling this leads to construction. |
38 static NotificationManager* ThreadSpecificInstance( | 37 static NotificationManager* ThreadSpecificInstance( |
39 ThreadSafeSender* thread_safe_sender, | 38 ThreadSafeSender* thread_safe_sender, |
40 base::SingleThreadTaskRunner* main_thread_task_runner, | |
41 NotificationDispatcher* notification_dispatcher); | 39 NotificationDispatcher* notification_dispatcher); |
42 | 40 |
43 // WorkerThread::Observer implementation. | 41 // WorkerThread::Observer implementation. |
44 void WillStopCurrentWorkerThread() override; | 42 void WillStopCurrentWorkerThread() override; |
45 | 43 |
46 // blink::WebNotificationManager implementation. | 44 void show( |
47 void show(const blink::WebSecurityOrigin& origin, | 45 const blink::WebSecurityOrigin& origin, |
48 const blink::WebNotificationData& notification_data, | 46 const blink::WebNotificationData& notification_data, |
49 blink::WebNotificationDelegate* delegate) override; | 47 std::unique_ptr<blink::WebNotificationResources> notification_resources, |
| 48 blink::WebNotificationDelegate* delegate) override; |
50 void showPersistent( | 49 void showPersistent( |
51 const blink::WebSecurityOrigin& origin, | 50 const blink::WebSecurityOrigin& origin, |
52 const blink::WebNotificationData& notification_data, | 51 const blink::WebNotificationData& notification_data, |
| 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(blink::WebNotificationDelegate* delegate) override; |
60 void closePersistent(const blink::WebSecurityOrigin& origin, | 60 void closePersistent(const blink::WebSecurityOrigin& origin, |
61 int64_t persistent_notification_id) override; | 61 int64_t persistent_notification_id) override; |
62 void notifyDelegateDestroyed( | 62 void notifyDelegateDestroyed( |
63 blink::WebNotificationDelegate* delegate) override; | 63 blink::WebNotificationDelegate* delegate) override; |
64 blink::WebNotificationPermission checkPermission( | 64 blink::WebNotificationPermission checkPermission( |
65 const blink::WebSecurityOrigin& origin) override; | 65 const blink::WebSecurityOrigin& origin) override; |
66 size_t maxActions() override; | 66 size_t maxActions() override; |
67 | 67 |
68 // Called by the NotificationDispatcher. | 68 // Called by the NotificationDispatcher. |
69 bool OnMessageReceived(const IPC::Message& message); | 69 bool OnMessageReceived(const IPC::Message& message); |
70 | 70 |
71 private: | 71 private: |
72 NotificationManager(ThreadSafeSender* thread_safe_sender, | 72 NotificationManager(ThreadSafeSender* thread_safe_sender, |
73 base::SingleThreadTaskRunner* main_thread_task_runner, | |
74 NotificationDispatcher* notification_dispatcher); | 73 NotificationDispatcher* notification_dispatcher); |
75 | 74 |
76 // IPC message handlers. | 75 // IPC message handlers. |
77 void OnDidShow(int notification_id); | 76 void OnDidShow(int notification_id); |
78 void OnDidShowPersistent(int request_id, bool success); | 77 void OnDidShowPersistent(int request_id, bool success); |
79 void OnDidClose(int notification_id); | 78 void OnDidClose(int notification_id); |
80 void OnDidClick(int notification_id); | 79 void OnDidClick(int notification_id); |
81 void OnDidGetNotifications( | 80 void OnDidGetNotifications( |
82 int request_id, | 81 int request_id, |
83 const std::vector<PersistentNotificationInfo>& notification_infos); | 82 const std::vector<PersistentNotificationInfo>& notification_infos); |
84 | 83 |
85 // To be called when a page notification is ready to be displayed. Will | |
86 // inform the browser process about all available data. The |delegate|, | |
87 // owned by Blink, will be used to feed back events associated with the | |
88 // notification to the JavaScript object. | |
89 void DisplayPageNotification( | |
90 const blink::WebSecurityOrigin& origin, | |
91 const blink::WebNotificationData& notification_data, | |
92 blink::WebNotificationDelegate* delegate, | |
93 const NotificationResources& notification_resources); | |
94 | |
95 // To be called when a persistent notification is ready to be displayed. Will | |
96 // inform the browser process about all available data. The |callbacks| will | |
97 // be used to inform the Promise pending in Blink that the notification has | |
98 // been send to the browser process to be displayed. | |
99 void DisplayPersistentNotification( | |
100 const blink::WebSecurityOrigin& origin, | |
101 const blink::WebNotificationData& notification_data, | |
102 int64_t service_worker_registration_id, | |
103 std::unique_ptr<blink::WebNotificationShowCallbacks> callbacks, | |
104 const NotificationResources& notification_resources); | |
105 | |
106 scoped_refptr<ThreadSafeSender> thread_safe_sender_; | 84 scoped_refptr<ThreadSafeSender> thread_safe_sender_; |
107 scoped_refptr<NotificationDispatcher> notification_dispatcher_; | 85 scoped_refptr<NotificationDispatcher> notification_dispatcher_; |
108 | 86 |
109 // Tracker which stores all pending Notifications, both page and persistent | |
110 // ones, until all their associated resources have been fetched. | |
111 PendingNotificationsTracker notifications_tracker_; | |
112 | |
113 // Tracks pending requests for getting a list of notifications. | 87 // Tracks pending requests for getting a list of notifications. |
114 IDMap<blink::WebNotificationGetCallbacks, IDMapOwnPointer> | 88 IDMap<blink::WebNotificationGetCallbacks, IDMapOwnPointer> |
115 pending_get_notification_requests_; | 89 pending_get_notification_requests_; |
116 | 90 |
117 // Tracks pending requests for displaying persistent notifications. | 91 // Tracks pending requests for displaying persistent notifications. |
118 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> | 92 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> |
119 pending_show_notification_requests_; | 93 pending_show_notification_requests_; |
120 | 94 |
121 // Map to store the delegate associated with a notification request Id. | 95 // Map to store the delegate associated with a notification request Id. |
122 std::map<int, blink::WebNotificationDelegate*> active_page_notifications_; | 96 std::map<int, blink::WebNotificationDelegate*> active_page_notifications_; |
123 | 97 |
124 DISALLOW_COPY_AND_ASSIGN(NotificationManager); | 98 DISALLOW_COPY_AND_ASSIGN(NotificationManager); |
125 }; | 99 }; |
126 | 100 |
127 } // namespace content | 101 } // namespace content |
128 | 102 |
129 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ | 103 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ |
OLD | NEW |