Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1155)

Side by Side Diff: content/child/notifications/notification_manager.h

Issue 1847863002: Move notification resource loading from content/child to blink (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Call stop when all fetches have finished. Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 // blink::WebNotificationManager implementation.
47 void show(const blink::WebSecurityOrigin& origin, 45 // Shows a page notification. Will inform the browser process about all
48 const blink::WebNotificationData& notification_data, 46 // available data. The |delegate|, owned by Blink, will be used to feed back
49 blink::WebNotificationDelegate* delegate) override; 47 // events associated with the notification to the JavaScript object.
48 void show(
49 const blink::WebSecurityOrigin& origin,
50 const blink::WebNotificationData& notification_data,
51 std::unique_ptr<blink::WebNotificationResources> notification_resources,
52 blink::WebNotificationDelegate* delegate) override;
53 // Shows a persistent notification. Will inform the browser process about all
54 // available data. The |callbacks| will be used to inform the Promise pending
55 // in Blink that the notification has been sent to the browser process to be
56 // displayed.
Peter Beverloo 2016/04/15 11:07:29 This seems like an odd place to document behaviour
Michael van Ouwerkerk 2016/04/18 11:26:53 Let's not then. Done.
50 void showPersistent( 57 void showPersistent(
51 const blink::WebSecurityOrigin& origin, 58 const blink::WebSecurityOrigin& origin,
52 const blink::WebNotificationData& notification_data, 59 const blink::WebNotificationData& notification_data,
60 std::unique_ptr<blink::WebNotificationResources> notification_resources,
53 blink::WebServiceWorkerRegistration* service_worker_registration, 61 blink::WebServiceWorkerRegistration* service_worker_registration,
54 blink::WebNotificationShowCallbacks* callbacks) override; 62 blink::WebNotificationShowCallbacks* callbacks) override;
55 void getNotifications( 63 void getNotifications(
56 const blink::WebString& filter_tag, 64 const blink::WebString& filter_tag,
57 blink::WebServiceWorkerRegistration* service_worker_registration, 65 blink::WebServiceWorkerRegistration* service_worker_registration,
58 blink::WebNotificationGetCallbacks* callbacks) override; 66 blink::WebNotificationGetCallbacks* callbacks) override;
59 void close(blink::WebNotificationDelegate* delegate) override; 67 void close(blink::WebNotificationDelegate* delegate) override;
60 void closePersistent(const blink::WebSecurityOrigin& origin, 68 void closePersistent(const blink::WebSecurityOrigin& origin,
61 int64_t persistent_notification_id) override; 69 int64_t persistent_notification_id) override;
62 void notifyDelegateDestroyed( 70 void notifyDelegateDestroyed(
63 blink::WebNotificationDelegate* delegate) override; 71 blink::WebNotificationDelegate* delegate) override;
64 blink::WebNotificationPermission checkPermission( 72 blink::WebNotificationPermission checkPermission(
65 const blink::WebSecurityOrigin& origin) override; 73 const blink::WebSecurityOrigin& origin) override;
66 size_t maxActions() override; 74 size_t maxActions() override;
67 75
68 // Called by the NotificationDispatcher. 76 // Called by the NotificationDispatcher.
69 bool OnMessageReceived(const IPC::Message& message); 77 bool OnMessageReceived(const IPC::Message& message);
70 78
71 private: 79 private:
72 NotificationManager(ThreadSafeSender* thread_safe_sender, 80 NotificationManager(ThreadSafeSender* thread_safe_sender,
73 base::SingleThreadTaskRunner* main_thread_task_runner,
74 NotificationDispatcher* notification_dispatcher); 81 NotificationDispatcher* notification_dispatcher);
75 82
76 // IPC message handlers. 83 // IPC message handlers.
77 void OnDidShow(int notification_id); 84 void OnDidShow(int notification_id);
78 void OnDidShowPersistent(int request_id, bool success); 85 void OnDidShowPersistent(int request_id, bool success);
79 void OnDidClose(int notification_id); 86 void OnDidClose(int notification_id);
80 void OnDidClick(int notification_id); 87 void OnDidClick(int notification_id);
81 void OnDidGetNotifications( 88 void OnDidGetNotifications(
82 int request_id, 89 int request_id,
83 const std::vector<PersistentNotificationInfo>& notification_infos); 90 const std::vector<PersistentNotificationInfo>& notification_infos);
84 91
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_; 92 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
107 scoped_refptr<NotificationDispatcher> notification_dispatcher_; 93 scoped_refptr<NotificationDispatcher> notification_dispatcher_;
108 94
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. 95 // Tracks pending requests for getting a list of notifications.
114 IDMap<blink::WebNotificationGetCallbacks, IDMapOwnPointer> 96 IDMap<blink::WebNotificationGetCallbacks, IDMapOwnPointer>
115 pending_get_notification_requests_; 97 pending_get_notification_requests_;
116 98
117 // Tracks pending requests for displaying persistent notifications. 99 // Tracks pending requests for displaying persistent notifications.
118 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> 100 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer>
119 pending_show_notification_requests_; 101 pending_show_notification_requests_;
120 102
121 // Map to store the delegate associated with a notification request Id. 103 // Map to store the delegate associated with a notification request Id.
122 std::map<int, blink::WebNotificationDelegate*> active_page_notifications_; 104 std::map<int, blink::WebNotificationDelegate*> active_page_notifications_;
123 105
124 DISALLOW_COPY_AND_ASSIGN(NotificationManager); 106 DISALLOW_COPY_AND_ASSIGN(NotificationManager);
125 }; 107 };
126 108
127 } // namespace content 109 } // namespace content
128 110
129 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ 111 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698