| OLD | NEW |
| 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/id_map.h" | 10 #include "base/id_map.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace blink { | 23 namespace blink { |
| 24 struct WebNotificationData; | 24 struct WebNotificationData; |
| 25 class WebNotificationDelegate; | 25 class WebNotificationDelegate; |
| 26 class WebSerializedOrigin; | 26 class WebSerializedOrigin; |
| 27 } | 27 } |
| 28 | 28 |
| 29 namespace content { | 29 namespace content { |
| 30 | 30 |
| 31 class NotificationImageLoader; | 31 class NotificationImageLoader; |
| 32 class NotificationSoundLoader; |
| 32 class NotificationManager; | 33 class NotificationManager; |
| 33 | 34 |
| 34 // Type definition for the callback signature which is to be invoked when the | 35 // Type definition for the callback signature which is to be invoked when the |
| 35 // resources associated with a notification have been fetched. | 36 // resources associated with a notification have been fetched. |
| 36 using NotificationResourcesFetchedCallback = | 37 using NotificationResourcesFetchedCallback = |
| 37 base::Callback<void(const SkBitmap&)>; | 38 base::Callback<void(const SkBitmap&)>; |
| 38 | 39 |
| 39 // Tracks all aspects of all pending Web Notifications. Most notably, it's in | 40 // 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 // charge of ensuring that all resource fetches associated with the notification |
| 41 // are completed as expected. The data associated with the notifications is | 42 // are completed as expected. The data associated with the notifications is |
| (...skipping 20 matching lines...) Expand all Loading... |
| 62 const blink::WebNotificationData& notification_data, | 63 const blink::WebNotificationData& notification_data, |
| 63 const NotificationResourcesFetchedCallback& callback); | 64 const NotificationResourcesFetchedCallback& callback); |
| 64 | 65 |
| 65 // Cancels all pending and in-fligth fetches for the page notification | 66 // Cancels all pending and in-fligth fetches for the page notification |
| 66 // identified by |delegate|. Returns if the notification was cancelled. | 67 // identified by |delegate|. Returns if the notification was cancelled. |
| 67 bool CancelPageNotificationFetches(blink::WebNotificationDelegate* delegate); | 68 bool CancelPageNotificationFetches(blink::WebNotificationDelegate* delegate); |
| 68 | 69 |
| 69 private: | 70 private: |
| 70 // To be called on the worker thread when the pending page notification | 71 // To be called on the worker thread when the pending page notification |
| 71 // identified by |notification_id| has finished fetching the icon. | 72 // identified by |notification_id| has finished fetching the icon. |
| 72 void DidFetchPageNotification(blink::WebNotificationDelegate* delegate, | 73 void DidFetchPageNotificationIcon(blink::WebNotificationDelegate* delegate, |
| 73 int notification_id, | 74 int notification_id, |
| 74 const SkBitmap& icon); | 75 const SkBitmap& icon); |
| 75 | 76 |
| 77 // To be called on the worker thread when the pending page notification |
| 78 // identified by |notification_id| has finished fetching the sound. |
| 79 void DidFetchPageNotificationSound(blink::WebNotificationDelegate* delegate, |
| 80 int notification_id, |
| 81 const SkBitmap& sound); |
| 82 |
| 76 // To be called on the worker thread when the pending persistent notification | 83 // To be called on the worker thread when the pending persistent notification |
| 77 // identified by |notification_id| has finished fetching the icon. | 84 // identified by |notification_id| has finished fetching the icon. |
| 78 void DidFetchPersistentNotification(int notification_id, | 85 void DidFetchPersistentNotificationIcon(int notification_id, |
| 79 const SkBitmap& icon); | 86 const SkBitmap& icon); |
| 80 | 87 |
| 81 // Common code for starting to fetch resources associated with any kind of | 88 // To be called on the worker thread when the pending persistent notification |
| 89 // identified by |notification_id| has finished fetching the sound. |
| 90 void DidFetchPersistentNotificationSound(int notification_id, |
| 91 const SkBitmap& sound); |
| 92 |
| 93 // Common code for starting to fetch icon associated with any kind of |
| 82 // notification. Will return the id of the pending notification as allocated | 94 // notification. Will return the id of the pending notification as allocated |
| 83 // in the |pending_notifications_| map. | 95 // in the |pending_notifications_| map. |
| 84 int FetchNotificationResources( | 96 int FetchNotificationIcon( |
| 85 const blink::WebNotificationData& notification_data, | 97 const blink::WebNotificationData& notification_data, |
| 86 const NotificationResourcesFetchedCallback& callback, | 98 const NotificationResourcesFetchedCallback& callback, |
| 87 const scoped_refptr<NotificationImageLoader>& image_loader); | 99 const scoped_refptr<NotificationImageLoader>& image_loader); |
| 88 | 100 |
| 101 // Common code for starting to fetch sound associated with any kind of |
| 102 // notification. Will return the id of the pending notification as allocated |
| 103 // in the |pending_notifications_| map. |
| 104 int FetchNotificationSound( |
| 105 const blink::WebNotificationData& notification_data, |
| 106 const NotificationResourcesFetchedCallback& callback, |
| 107 const scoped_refptr<NotificationSoundLoader>& sound_loader); |
| 108 |
| 89 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; | 109 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_; |
| 90 | 110 |
| 91 struct PendingNotification; | 111 struct PendingNotification; |
| 92 | 112 |
| 93 // List of the notifications whose resources are still being fetched. | 113 // List of the notifications whose resources are still being fetched. |
| 94 IDMap<PendingNotification, IDMapOwnPointer> pending_notifications_; | 114 IDMap<PendingNotification, IDMapOwnPointer> pending_notifications_; |
| 95 | 115 |
| 96 // In order to be able to cancel pending page notifications by delegate, store | 116 // 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. | 117 // a mapping of the delegate to the pending notification id as well. |
| 98 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_; | 118 std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_; |
| 99 | 119 |
| 100 base::WeakPtrFactory<PendingNotificationsTracker> weak_factory_; | 120 base::WeakPtrFactory<PendingNotificationsTracker> weak_factory_; |
| 101 | 121 |
| 102 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTracker); | 122 DISALLOW_COPY_AND_ASSIGN(PendingNotificationsTracker); |
| 103 }; | 123 }; |
| 104 | 124 |
| 105 } // namespace content | 125 } // namespace content |
| 106 | 126 |
| 107 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_ | 127 #endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATIONS_TRACKER_H_ |
| OLD | NEW |