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

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

Issue 1620203004: Notification action icons prototype. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make it work on Android and clean up. 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 "base/memory/weak_ptr.h"
15 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onManager.h"
16
17 class SkBitmap;
18 14
19 namespace base { 15 namespace base {
20 class SingleThreadTaskRunner; 16 class SingleThreadTaskRunner;
21 } 17 }
22 18
23 namespace blink { 19 namespace blink {
24 struct WebNotificationData; 20 struct WebNotificationData;
25 class WebNotificationDelegate; 21 class WebNotificationDelegate;
26 } 22 }
27 23
28 namespace content { 24 namespace content {
29 25
30 class NotificationImageLoader; 26 class PendingNotification;
31 class NotificationManager; 27 struct NotificationResources;
32 28
33 // Type definition for the callback signature which is to be invoked when the 29 // Type definition for the callback signature which is to be invoked when the
34 // resources associated with a notification have been fetched. 30 // resources associated with a notification have been fetched.
35 using NotificationResourcesFetchedCallback = 31 using NotificationResourcesCallback =
36 base::Callback<void(const SkBitmap&)>; 32 base::Callback<void(const NotificationResources&)>;
37 33
38 // Tracks all aspects of all pending Web Notifications. Most notably, it's in 34 // Tracks all pending Web Notifications as PendingNotification instances. The
39 // charge of ensuring that all resource fetches associated with the notification 35 // pending notifications (and their associated data) are stored in this class.
40 // are completed as expected. The data associated with the notifications is
41 // stored in this class, to maintain thread integrity of their members.
42 //
43 // The pending notification tracker is owned by the NotificationManager, and 36 // The pending notification tracker is owned by the NotificationManager, and
44 // lives on the thread that manager has been associated with. 37 // lives on the thread that manager has been associated with.
45 class PendingNotificationsTracker { 38 class PendingNotificationsTracker {
46 public: 39 public:
47 explicit PendingNotificationsTracker( 40 explicit PendingNotificationsTracker(
48 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner); 41 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
49 ~PendingNotificationsTracker(); 42 ~PendingNotificationsTracker();
50 43
51 // Adds a page notification to the tracker. Resource fetches for the 44 // Adds a pending notification fo which to fetch resources. The |delegate| may
52 // notification will be started on asynchronously the main thread. 45 // be null, but if it is not it can be used to cancel the fetches. Resource
53 void FetchPageNotificationResources( 46 // fetches will be started asynchronously on the main thread.
47 void FetchNotificationResources(
54 const blink::WebNotificationData& notification_data, 48 const blink::WebNotificationData& notification_data,
55 blink::WebNotificationDelegate* delegate, 49 blink::WebNotificationDelegate* delegate,
56 const NotificationResourcesFetchedCallback& callback); 50 const NotificationResourcesCallback& resources_callback);
57 51
58 // Adds a persistent notification to the tracker. Resource fetches for the 52 // Cancels all pending and in-flight fetches for the notification
59 // notification will be started asynchronously on the main thread. 53 // identified by |delegate|. Returns whether the notification was cancelled.
60 void FetchPersistentNotificationResources( 54 bool CancelResourceFetches(blink::WebNotificationDelegate* delegate);
61 const blink::WebNotificationData& notification_data,
62 const NotificationResourcesFetchedCallback& callback);
63
64 // Cancels all pending and in-fligth fetches for the page notification
65 // identified by |delegate|. Returns if the notification was cancelled.
66 bool CancelPageNotificationFetches(blink::WebNotificationDelegate* delegate);
67 55
68 private: 56 private:
69 // To be called on the worker thread when the pending page notification 57 // To be called on the worker thread when the pending notification
70 // identified by |notification_id| has finished fetching the icon. 58 // identified by |notification_id| has finished fetching the resources. The
71 void DidFetchPageNotification(blink::WebNotificationDelegate* delegate, 59 // |delegate| may be null.
72 int notification_id, 60 void FetchesFinished(blink::WebNotificationDelegate* delegate,
73 const SkBitmap& icon); 61 int notification_id,
62 const NotificationResourcesCallback& resources_callback);
74 63
75 // To be called on the worker thread when the pending persistent notification 64 // Used to generate ids for tracking pending notifications.
76 // identified by |notification_id| has finished fetching the icon. 65 int32_t next_notification_id_;
77 void DidFetchPersistentNotification(int notification_id,
78 const SkBitmap& icon);
79
80 // Common code for starting to fetch resources associated with any kind of
81 // notification. Will return the id of the pending notification as allocated
82 // in the |pending_notifications_| map.
83 int FetchNotificationResources(
84 const blink::WebNotificationData& notification_data,
85 const NotificationResourcesFetchedCallback& callback,
86 const scoped_refptr<NotificationImageLoader>& image_loader);
87 66
88 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; 67 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
89 68
90 struct PendingNotification; 69 // The notifications whose resources are still being fetched.
91
92 // List of the notifications whose resources are still being fetched.
93 IDMap<PendingNotification, IDMapOwnPointer> pending_notifications_; 70 IDMap<PendingNotification, IDMapOwnPointer> pending_notifications_;
94 71
95 // In order to be able to cancel pending page notifications by delegate, store 72 // In order to be able to cancel pending page notifications by delegate, store
96 // a mapping of the delegate to the pending notification id as well. 73 // a mapping of the delegate to the pending notification id as well.
97 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_; 74 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_;
98 75
99 base::WeakPtrFactory<PendingNotificationsTracker> weak_factory_;
100
101 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTracker); 76 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTracker);
102 }; 77 };
103 78
104 } // namespace content 79 } // namespace content
105 80
106 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_ 81 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_
OLDNEW
« no previous file with comments | « content/child/notifications/pending_notification.cc ('k') | content/child/notifications/pending_notifications_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698