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

Side by Side Diff: content/child/notifications/pending_notifications_tracker.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: Address peter's comments. 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
(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/callback_forward.h"
11 #include "base/id_map.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "content/common/content_export.h"
15
16 namespace base {
17 class SingleThreadTaskRunner;
18 }
19
20 namespace blink {
21 struct WebNotificationData;
22 class WebNotificationDelegate;
23 }
24
25 namespace content {
26
27 class PendingNotification;
28 class PendingNotificationsTrackerTest;
29 struct NotificationResources;
30
31 // Tracks all pending Web Notifications as PendingNotification instances. The
32 // pending notifications (and their associated data) are stored in this class.
33 // The pending notification tracker is owned by the NotificationManager, and
34 // lives on the thread that manager has been associated with.
35 class CONTENT_EXPORT PendingNotificationsTracker {
36 public:
37 explicit PendingNotificationsTracker(
38 const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner);
39 ~PendingNotificationsTracker();
40
41 // Type definition for the callback signature which is to be invoked when the
42 // resources associated with a notification have been fetched.
43 using ResourcesCallback = base::Callback<void(const NotificationResources&)>;
44
45 // Adds a pending notification for which to fetch resources. The |delegate|
46 // may be null, but non-null values can be used to cancel the fetches.
47 // Resource fetches will be started asynchronously on the main thread.
48 void FetchResources(const blink::WebNotificationData& notification_data,
49 blink::WebNotificationDelegate* delegate,
50 const ResourcesCallback& resources_callback);
51
52 // Cancels all pending and in-flight fetches for the notification identified
53 // by |delegate|, which may not be null. Returns whether the notification was
54 // cancelled.
55 bool CancelResourceFetches(blink::WebNotificationDelegate* delegate);
56
57 private:
58 friend class PendingNotificationsTrackerTest;
59
60 // To be called on the worker thread when the pending notification
61 // identified by |notification_id| has finished fetching the resources. The
62 // |delegate| may be null.
63 void FetchesFinished(blink::WebNotificationDelegate* delegate,
64 int notification_id,
65 const ResourcesCallback& resources_callback);
66
67 // Used to generate ids for tracking pending notifications.
68 int32_t next_notification_id_;
69
70 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_;
71
72 // The notifications whose resources are still being fetched.
73 IDMap<PendingNotification, IDMapOwnPointer> pending_notifications_;
74
75 // In order to be able to cancel pending page notifications by delegate, store
76 // a mapping of the delegate to the pending notification id as well.
77 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_;
78
79 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTracker);
80 };
81
82 } // namespace content
83
84 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698