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

Side by Side Diff: content/child/notifications/pending_notifications_tracker.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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_
6 #define CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_
7
8 #include <map>
9
10 #include "base/id_map.h"
11 #include "base/macros.h"
12 #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
19 namespace base {
20 class SingleThreadTaskRunner;
21 }
22
23 namespace blink {
24 struct WebNotificationData;
25 class WebNotificationDelegate;
26 class WebSerializedOrigin;
27 }
28
29 namespace content {
30
31 class NotificationImageLoader;
32 class NotificationManager;
33
34 // Type definition for the callback signature which is to be invoked when the
35 // resources associated with a notification have been fetched.
36 using NotificationResourcesFetchedCallback =
37 base::Callback<void(const SkBitmap&)>;
38
39 // Tracks all aspects of all pending Web Notifications. Most notably, it's in
40 // charge of ensuring that all resource fetches associated with the notification
41 // are completed as expected. The data associated with the notifications is
42 // stored in this class, to maintain thread integrity of their members.
43 //
44 // The pending notification tracker is owned by the NotificationManager, and
45 // lives on the thread that manager has been associated with.
46 class PendingNotificationsTracker {
47 public:
48 explicit PendingNotificationsTracker(
49 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
50 ~PendingNotificationsTracker();
51
52 // Adds a page notification to the tracker. Resource fetches for the
53 // notification will be started on asynchronously the main thread.
54 void FetchPageNotificationResources(
55 const blink::WebNotificationData& notification_data,
56 blink::WebNotificationDelegate* delegate,
57 const NotificationResourcesFetchedCallback& callback);
58
59 // Adds a persistent notification to the tracker. Resource fetches for the
60 // notification will be started asynchronously on the main thread.
61 void FetchPersistentNotificationResources(
62 const blink::WebNotificationData& notification_data,
63 const NotificationResourcesFetchedCallback& callback);
64
65 // Cancels all pending and in-fligth fetches for the page notification
66 // identified by |delegate|. Returns if the notification was cancelled.
67 bool CancelPageNotificationFetches(blink::WebNotificationDelegate* delegate);
68
69 private:
70 // To be called on the worker thread when the pending page notification
71 // identified by |notification_id| has finished fetching the icon.
72 void DidFetchPageNotification(blink::WebNotificationDelegate* delegate,
73 int notification_id,
74 const SkBitmap& icon);
75
76 // To be called on the worker thread when the pending persistent notification
77 // identified by |notification_id| has finished fetching the icon.
78 void DidFetchPersistentNotification(int notification_id,
79 const SkBitmap& icon);
80
81 // Common code for starting to fetch resources associated with any kind of
82 // notification. Will return the id of the pending notification as allocated
83 // in the |pending_notifications_| map.
84 int FetchNotificationResources(
85 const blink::WebNotificationData& notification_data,
86 const NotificationResourcesFetchedCallback& callback,
87 const scoped_refptr<NotificationImageLoader>& image_loader);
88
89 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
90
91 struct PendingNotification;
92
93 // List of the notifications whose resources are still being fetched.
94 IDMap<PendingNotification, IDMapOwnPointer> pending_notifications_;
95
96 // In order to be able to cancel pending page notifications by delegate, store
97 // a mapping of the delegate to the pending notification id as well.
98 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_;
99
100 base::WeakPtrFactory<PendingNotificationsTracker> weak_factory_;
101
102 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTracker);
103 };
104
105 } // namespace content
106
107 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_
OLDNEW
« no previous file with comments | « content/child/notifications/notification_manager.cc ('k') | content/child/notifications/pending_notifications_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698