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

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

Issue 1644083002: Fetch notification action icons and pass them through in resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ActionIconBlink
Patch Set: Rebase. Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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_PENDING_NOTIFICATIONS_TRACKER_H_ 5 #ifndef CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_
6 #define CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_ 6 #define CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_
7 7
8 #include <map> 8 #include <map>
9 9
10 #include "base/callback_forward.h"
10 #include "base/id_map.h" 11 #include "base/id_map.h"
11 #include "base/macros.h" 12 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 13 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h" 14 #include "content/common/content_export.h"
14 #include "base/memory/weak_ptr.h"
15
16 class SkBitmap;
17 15
18 namespace base { 16 namespace base {
19 class SingleThreadTaskRunner; 17 class SingleThreadTaskRunner;
20 } 18 }
21 19
22 namespace blink { 20 namespace blink {
23 struct WebNotificationData; 21 struct WebNotificationData;
24 class WebNotificationDelegate; 22 class WebNotificationDelegate;
25 } 23 }
26 24
27 namespace content { 25 namespace content {
28 26
29 class NotificationImageLoader; 27 class PendingNotification;
28 class PendingNotificationsTrackerTest;
30 struct NotificationResources; 29 struct NotificationResources;
31 30
32 // Type definition for the callback signature which is to be invoked when the 31 // Type definition for the callback signature which is to be invoked when the
33 // resources associated with a notification have been fetched. 32 // resources associated with a notification have been fetched.
34 using NotificationResourcesFetchedCallback = 33 using NotificationResourcesCallback =
Peter Beverloo 2016/02/05 15:43:21 This can live in the PendingNotificationsTracker c
Michael van Ouwerkerk 2016/02/08 14:38:53 Done.
35 base::Callback<void(const NotificationResources&)>; 34 base::Callback<void(const NotificationResources&)>;
36 35
37 // Tracks all aspects of all pending Web Notifications. Most notably, it's in 36 // Tracks all pending Web Notifications as PendingNotification instances. The
38 // charge of ensuring that all resource fetches associated with the notification 37 // pending notifications (and their associated data) are stored in this class.
39 // are completed as expected. The data associated with the notifications is
40 // stored in this class, to maintain thread integrity of their members.
41 //
42 // The pending notification tracker is owned by the NotificationManager, and 38 // The pending notification tracker is owned by the NotificationManager, and
43 // lives on the thread that manager has been associated with. 39 // lives on the thread that manager has been associated with.
44 class PendingNotificationsTracker { 40 class CONTENT_EXPORT PendingNotificationsTracker {
45 public: 41 public:
46 explicit PendingNotificationsTracker( 42 explicit PendingNotificationsTracker(
47 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner); 43 const scoped_refptr<base::SingleThreadTaskRunner>&
44 main_thread_task_runner);
48 ~PendingNotificationsTracker(); 45 ~PendingNotificationsTracker();
49 46
50 // Adds a page notification to the tracker. Resource fetches for the 47 // Adds a pending notification for which to fetch resources. The |delegate|
51 // notification will be started on asynchronously the main thread. 48 // may be null, but if it is not it can be used to cancel the fetches.
Peter Beverloo 2016/02/05 15:43:21 nit: s/but if it is not it/but non-null values/
Michael van Ouwerkerk 2016/02/08 14:38:53 Done.
52 void FetchPageNotificationResources( 49 // Resource fetches will be started asynchronously on the main thread.
50 void FetchNotificationResources(
Peter Beverloo 2016/02/05 15:43:21 Up to you, but for consistency reasons with Fetche
Michael van Ouwerkerk 2016/02/08 14:38:53 Done.
53 const blink::WebNotificationData& notification_data, 51 const blink::WebNotificationData& notification_data,
54 blink::WebNotificationDelegate* delegate, 52 blink::WebNotificationDelegate* delegate,
55 const NotificationResourcesFetchedCallback& callback); 53 const NotificationResourcesCallback& resources_callback);
56 54
57 // Adds a persistent notification to the tracker. Resource fetches for the 55 // Cancels all pending and in-flight fetches for the notification
58 // notification will be started asynchronously on the main thread. 56 // identified by |delegate|. Returns whether the notification was cancelled.
59 void FetchPersistentNotificationResources( 57 bool CancelResourceFetches(blink::WebNotificationDelegate* delegate);
Peter Beverloo 2016/02/05 15:43:21 Should this method explicitly disallow non-NULL va
Michael van Ouwerkerk 2016/02/08 14:38:53 Sure, we can explicitly disallow null values (and
60 const blink::WebNotificationData& notification_data,
61 const NotificationResourcesFetchedCallback& callback);
62
63 // Cancels all pending and in-fligth fetches for the page notification
64 // identified by |delegate|. Returns if the notification was cancelled.
65 bool CancelPageNotificationFetches(blink::WebNotificationDelegate* delegate);
66 58
67 private: 59 private:
68 // To be called on the worker thread when the pending page notification 60 friend class PendingNotificationsTrackerTest;
69 // identified by |notification_id| has finished fetching the icon.
70 void DidFetchPageNotification(blink::WebNotificationDelegate* delegate,
71 int notification_id,
72 const SkBitmap& icon);
73 61
74 // To be called on the worker thread when the pending persistent notification 62 // To be called on the worker thread when the pending notification
75 // identified by |notification_id| has finished fetching the icon. 63 // identified by |notification_id| has finished fetching the resources. The
76 void DidFetchPersistentNotification(int notification_id, 64 // |delegate| may be null.
77 const SkBitmap& icon); 65 void FetchesFinished(blink::WebNotificationDelegate* delegate,
66 int notification_id,
67 const NotificationResourcesCallback& resources_callback);
78 68
79 // Common code for starting to fetch resources associated with any kind of 69 // Used to generate ids for tracking pending notifications.
80 // notification. Will return the id of the pending notification as allocated 70 int32_t next_notification_id_;
81 // in the |pending_notifications_| map.
82 int FetchNotificationResources(
83 const blink::WebNotificationData& notification_data,
84 const NotificationResourcesFetchedCallback& callback,
85 const scoped_refptr<NotificationImageLoader>& image_loader);
86 71
87 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; 72 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
88 73
89 struct PendingNotification; 74 // The notifications whose resources are still being fetched.
90
91 // List of the notifications whose resources are still being fetched.
92 IDMap<PendingNotification, IDMapOwnPointer> pending_notifications_; 75 IDMap<PendingNotification, IDMapOwnPointer> pending_notifications_;
93 76
94 // In order to be able to cancel pending page notifications by delegate, store 77 // In order to be able to cancel pending page notifications by delegate, store
95 // a mapping of the delegate to the pending notification id as well. 78 // a mapping of the delegate to the pending notification id as well.
96 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_; 79 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_;
97 80
98 base::WeakPtrFactory<PendingNotificationsTracker> weak_factory_;
99
100 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTracker); 81 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTracker);
101 }; 82 };
102 83
103 } // namespace content 84 } // namespace content
104 85
105 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_ 86 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698