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

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

Issue 939513002: Factor out a PendingNotificationTracker from the NotificationManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-sounds
Patch Set: Created 5 years, 10 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 <map> 8 #include <map>
9 #include <set> 9 #include <set>
10 10
11 #include "base/id_map.h"
12 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/single_thread_task_runner.h" 12 #include "base/single_thread_task_runner.h"
15 #include "content/child/notifications/notification_dispatcher.h" 13 #include "content/child/notifications/notification_dispatcher.h"
16 #include "content/child/notifications/notification_image_loader.h" 14 #include "content/child/notifications/pending_notification_tracker.h"
17 #include "content/child/worker_task_runner.h" 15 #include "content/child/worker_task_runner.h"
18 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onManager.h" 16 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onManager.h"
19 17
20 class SkBitmap; 18 class SkBitmap;
21 19
22 namespace blink {
23 class WebURL;
24 }
25
26 namespace content { 20 namespace content {
27 21
28 class ThreadSafeSender; 22 class ThreadSafeSender;
29 23
30 class NotificationManager : public blink::WebNotificationManager, 24 class NotificationManager : public blink::WebNotificationManager,
31 public WorkerTaskRunner::Observer { 25 public WorkerTaskRunner::Observer {
32 public: 26 public:
33 ~NotificationManager() override; 27 ~NotificationManager() override;
34 28
35 // |thread_safe_sender| and |notification_dispatcher| are used if 29 // |thread_safe_sender| and |notification_dispatcher| are used if
36 // calling this leads to construction. 30 // calling this leads to construction.
37 static NotificationManager* ThreadSpecificInstance( 31 static NotificationManager* ThreadSpecificInstance(
38 ThreadSafeSender* thread_safe_sender, 32 ThreadSafeSender* thread_safe_sender,
39 base::SingleThreadTaskRunner* main_thread_task_runner, 33 base::SingleThreadTaskRunner* main_thread_task_runner,
40 NotificationDispatcher* notification_dispatcher); 34 NotificationDispatcher* notification_dispatcher);
41 35
36 // To be called when a page notification is ready to be displayed. Will
37 // inform the browser process about all available data.
38 void DisplayPageNotification(
39 const blink::WebSerializedOrigin& origin,
40 const blink::WebNotificationData& notification_data,
41 blink::WebNotificationDelegate* delegate,
mlamouri (slow - plz ping) 2015/02/18 14:53:58 Could you explain in the comment what |delegate| i
Peter Beverloo 2015/02/18 15:11:50 Done.
42 const SkBitmap& icon);
mlamouri (slow - plz ping) 2015/02/18 14:53:58 Could you move the |icon| above |delegate|?
Peter Beverloo 2015/02/18 15:11:50 Why? Everything but |icon| is present in show() an
43
44 // To be called when a persistent notification is ready to be displayed. Will
45 // inform the browser process about all available data.
46 void DisplayPersistentNotification(
47 const blink::WebSerializedOrigin& origin,
48 const blink::WebNotificationData& notification_data,
49 int64 service_worker_registration_id,
50 scoped_ptr<blink::WebNotificationShowCallbacks> callbacks,
mlamouri (slow - plz ping) 2015/02/18 14:53:58 Could you explain in the comment what |callbacks|
Peter Beverloo 2015/02/18 15:11:50 Done.
51 const SkBitmap& icon);
mlamouri (slow - plz ping) 2015/02/18 14:53:58 Could you move the |icon| below |notification_data
Peter Beverloo 2015/02/18 15:11:50 Dito.
52
42 // WorkerTaskRunner::Observer implementation. 53 // WorkerTaskRunner::Observer implementation.
43 void OnWorkerRunLoopStopped() override; 54 void OnWorkerRunLoopStopped() override;
44 55
45 // blink::WebNotificationManager implementation. 56 // blink::WebNotificationManager implementation.
46 virtual void show(const blink::WebSerializedOrigin& origin, 57 virtual void show(const blink::WebSerializedOrigin& origin,
47 const blink::WebNotificationData& notification_data, 58 const blink::WebNotificationData& notification_data,
48 blink::WebNotificationDelegate* delegate); 59 blink::WebNotificationDelegate* delegate);
49 virtual void showPersistent( 60 virtual void showPersistent(
50 const blink::WebSerializedOrigin& origin, 61 const blink::WebSerializedOrigin& origin,
51 const blink::WebNotificationData& notification_data, 62 const blink::WebNotificationData& notification_data,
(...skipping 14 matching lines...) Expand all
66 NotificationManager( 77 NotificationManager(
67 ThreadSafeSender* thread_safe_sender, 78 ThreadSafeSender* thread_safe_sender,
68 base::SingleThreadTaskRunner* main_thread_task_runner, 79 base::SingleThreadTaskRunner* main_thread_task_runner,
69 NotificationDispatcher* notification_dispatcher); 80 NotificationDispatcher* notification_dispatcher);
70 81
71 // IPC message handlers. 82 // IPC message handlers.
72 void OnDidShow(int notification_id); 83 void OnDidShow(int notification_id);
73 void OnDidClose(int notification_id); 84 void OnDidClose(int notification_id);
74 void OnDidClick(int notification_id); 85 void OnDidClick(int notification_id);
75 86
76 // Asynchronously starts loading |image_url| on the main thread and returns a
77 // reference to the notification image loaded responsible for this. |callback|
78 // will be invoked on the calling thread when the load is complete.
79 scoped_refptr<NotificationImageLoader> CreateImageLoader(
80 const blink::WebURL& image_url,
81 const NotificationImageLoadedCallback& callback) const;
82
83 // Sends an IPC to the browser process to display the notification,
84 // accompanied by the downloaded icon.
85 void DisplayNotification(const blink::WebSerializedOrigin& origin,
86 const blink::WebNotificationData& notification_data,
87 blink::WebNotificationDelegate* delegate,
88 scoped_refptr<NotificationImageLoader> image_loader);
89
90 // Sends an IPC to the browser process to display the persistent notification,
91 // accompanied by the downloaded icon.
92 void DisplayPersistentNotification(
93 const blink::WebSerializedOrigin& origin,
94 const blink::WebNotificationData& notification_data,
95 int64 service_worker_registration_id,
96 int request_id,
97 scoped_refptr<NotificationImageLoader> image_loader);
98
99 // Removes the notification identified by |delegate| from the set of
100 // pending notifications, and returns whether it could be found.
101 bool RemovePendingPageNotification(blink::WebNotificationDelegate* delegate);
102
103 scoped_refptr<ThreadSafeSender> thread_safe_sender_; 87 scoped_refptr<ThreadSafeSender> thread_safe_sender_;
104 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
105 scoped_refptr<NotificationDispatcher> notification_dispatcher_; 88 scoped_refptr<NotificationDispatcher> notification_dispatcher_;
106 89
107 // Tracking display requests for persistent notifications. 90 // Tracker which stores all pending Notifications, both page and persistent
108 IDMap<blink::WebNotificationShowCallbacks, IDMapOwnPointer> 91 // ones, until all their associated resources have been fetched.
109 persistent_notification_requests_; 92 PendingNotificationTracker pending_notifications_;
110
111 // A map tracking Page-bound notifications whose icon is still being
112 // downloaded. These downloads can be cancelled by the developer.
113 std::map<blink::WebNotificationDelegate*,
114 scoped_refptr<NotificationImageLoader>>
115 pending_page_notifications_;
116
117 // A set tracking Persistent notifications whose icon is still being
118 // downloaded. These downloads cannot be cancelled by the developer.
119 std::set<scoped_refptr<NotificationImageLoader>>
120 pending_persistent_notifications_;
121 93
122 // Map to store the delegate associated with a notification request Id. 94 // Map to store the delegate associated with a notification request Id.
123 std::map<int, blink::WebNotificationDelegate*> active_notifications_; 95 std::map<int, blink::WebNotificationDelegate*> active_page_notifications_;
124
125 base::WeakPtrFactory<NotificationManager> weak_factory_;
126 96
127 DISALLOW_COPY_AND_ASSIGN(NotificationManager); 97 DISALLOW_COPY_AND_ASSIGN(NotificationManager);
128 }; 98 };
129 99
130 } // namespace content 100 } // namespace content
131 101
132 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_ 102 #endif // CONTENT_CHILD_NOTIFICATIONS_NOTIFICATION_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698