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

Side by Side Diff: content/child/notifications/pending_notification_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_NOTIFICATION_TRACKER_H_
6 #define CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATION_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 NotificationManager;
32
33 // Tracks all aspects of all pending Web Notifications. Most notably, it's in
34 // charge of ensuring that all resource fetches associated with the notification
35 // are completed as expected. The data associated with the notifications is
36 // stored in this class, to maintain thread integrity of their members.
37 //
38 // The pending notification tracker is owned by the NotificationManager, and
39 // lives on the thread that manager has been associated with.
40 class PendingNotificationTracker {
41 public:
42 PendingNotificationTracker(
43 NotificationManager* manager,
44 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
45 ~PendingNotificationTracker();
46
47 // Adds a page notification to the tracker. Resource fetches for the
48 // notification will be started on asynchronously the main thread.
49 void FetchPageNotification(
mlamouri (slow - plz ping) 2015/02/18 14:53:58 nit: I find the name confusing, what about FetchPa
Peter Beverloo 2015/02/18 15:11:50 Done.
50 const blink::WebSerializedOrigin& origin,
51 const blink::WebNotificationData& notification_data,
52 blink::WebNotificationDelegate* delegate);
53
54 // Adds a persistent notification to the tracker. Resource fetches for the
55 // notification will be started asynchronously on the main thread.
56 void FetchPersistentNotification(
mlamouri (slow - plz ping) 2015/02/18 14:53:58 ditto
Peter Beverloo 2015/02/18 15:11:50 Done.
57 const blink::WebSerializedOrigin& origin,
58 const blink::WebNotificationData& notification_data,
59 int64 service_worker_registration_id,
60 scoped_ptr<blink::WebNotificationShowCallbacks> callbacks);
61
62 // Cancels all pending and in-fligth fetches for the page notification
63 // identified by |delegate|. Returns if the notification was cancelled.
64 bool CancelPageNotificationFetches(blink::WebNotificationDelegate* delegate);
65
66 private:
67 // To be called on the worker thread when the pending page notification
68 // identified by |notification_id| has finished fetching the icon.
69 void DidFetchPageNotification(int notification_id, const SkBitmap& icon);
70
71 // To be called on the worker thread when the pending persistent notification
72 // identified by |notification_id| has finished fetching the icon.
73 void DidFetchPersistentNotification(int notification_id,
74 const SkBitmap& icon);
75
76 NotificationManager* manager_;
77
78 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
79
80 struct PendingPageNotification;
81 struct PendingPersistentNotification;
82
83 // List of the notifications whose resources are still being fetched.
84 IDMap<PendingPageNotification, IDMapOwnPointer> pending_page_notifications_;
85 IDMap<PendingPersistentNotification, IDMapOwnPointer>
86 pending_persistent_notifications_;
87
88 // In order to be able to cancel pending page notifications by delegate, store
89 // a mapping of the delegate to the pending notification id as well.
90 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_;
91
92 base::WeakPtrFactory<PendingNotificationTracker> weak_factory_;
93
94 DISALLOW_COPY_AND_ASSIGN(PendingNotificationTracker);
95 };
96
97 } // namespace content
98
99 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATION_TRACKER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698