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 #include "content/child/notifications/pending_notifications_tracker.h" | 5 #include "content/child/notifications/pending_notifications_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/thread_task_runner_handle.h" | 9 #include "base/thread_task_runner_handle.h" |
10 #include "content/child/notifications/notification_image_loader.h" | 10 #include "content/child/notifications/notification_image_loader.h" |
11 #include "content/child/notifications/notification_manager.h" | 11 #include "content/public/common/notification_resources.h" |
Peter Beverloo
2016/01/26 15:43:23
Something to think about: so far we've named _most
Michael van Ouwerkerk
2016/01/26 16:24:21
Right, it's true that "notification" is very overl
| |
12 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" | 12 #include "third_party/WebKit/public/platform/modules/notifications/WebNotificati onData.h" |
13 #include "third_party/skia/include/core/SkBitmap.h" | 13 #include "third_party/skia/include/core/SkBitmap.h" |
14 | 14 |
15 namespace content { | 15 namespace content { |
16 | 16 |
17 // Stores the information associated with a pending notification. | 17 // Stores the information associated with a pending notification. |
18 struct PendingNotificationsTracker::PendingNotification { | 18 struct PendingNotificationsTracker::PendingNotification { |
19 PendingNotification( | 19 PendingNotification( |
20 const scoped_refptr<NotificationImageLoader>& image_loader, | 20 const scoped_refptr<NotificationImageLoader>& image_loader, |
21 const NotificationResourcesFetchedCallback& callback) | 21 const NotificationResourcesFetchedCallback& callback) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 } | 68 } |
69 | 69 |
70 void PendingNotificationsTracker::DidFetchPageNotification( | 70 void PendingNotificationsTracker::DidFetchPageNotification( |
71 blink::WebNotificationDelegate* delegate, | 71 blink::WebNotificationDelegate* delegate, |
72 int notification_id, | 72 int notification_id, |
73 const SkBitmap& icon) { | 73 const SkBitmap& icon) { |
74 PendingNotification* pending_notification = | 74 PendingNotification* pending_notification = |
75 pending_notifications_.Lookup(notification_id); | 75 pending_notifications_.Lookup(notification_id); |
76 DCHECK(pending_notification); | 76 DCHECK(pending_notification); |
77 | 77 |
78 pending_notification->callback.Run(icon); | 78 NotificationResources notification_resources; |
79 notification_resources.notification_icon = icon; | |
80 pending_notification->callback.Run(notification_resources); | |
79 | 81 |
80 delegate_to_pending_id_map_.erase(delegate); | 82 delegate_to_pending_id_map_.erase(delegate); |
81 pending_notifications_.Remove(notification_id); | 83 pending_notifications_.Remove(notification_id); |
82 } | 84 } |
83 | 85 |
84 void PendingNotificationsTracker::DidFetchPersistentNotification( | 86 void PendingNotificationsTracker::DidFetchPersistentNotification( |
85 int notification_id, const SkBitmap& icon) { | 87 int notification_id, const SkBitmap& icon) { |
86 PendingNotification* pending_notification = | 88 PendingNotification* pending_notification = |
87 pending_notifications_.Lookup(notification_id); | 89 pending_notifications_.Lookup(notification_id); |
88 DCHECK(pending_notification); | 90 DCHECK(pending_notification); |
89 | 91 |
90 pending_notification->callback.Run(icon); | 92 NotificationResources notification_resources; |
93 notification_resources.notification_icon = icon; | |
94 pending_notification->callback.Run(notification_resources); | |
91 | 95 |
92 pending_notifications_.Remove(notification_id); | 96 pending_notifications_.Remove(notification_id); |
93 } | 97 } |
94 | 98 |
95 int PendingNotificationsTracker::FetchNotificationResources( | 99 int PendingNotificationsTracker::FetchNotificationResources( |
96 const blink::WebNotificationData& notification_data, | 100 const blink::WebNotificationData& notification_data, |
97 const NotificationResourcesFetchedCallback& callback, | 101 const NotificationResourcesFetchedCallback& callback, |
98 const scoped_refptr<NotificationImageLoader>& image_loader) { | 102 const scoped_refptr<NotificationImageLoader>& image_loader) { |
99 int notification_id = pending_notifications_.Add( | 103 int notification_id = pending_notifications_.Add( |
100 new PendingNotification(image_loader, callback)); | 104 new PendingNotification(image_loader, callback)); |
101 | 105 |
102 main_thread_task_runner_->PostTask( | 106 main_thread_task_runner_->PostTask( |
103 FROM_HERE, | 107 FROM_HERE, |
104 base::Bind(&NotificationImageLoader::StartOnMainThread, image_loader, | 108 base::Bind(&NotificationImageLoader::StartOnMainThread, image_loader, |
105 notification_id, GURL(notification_data.icon))); | 109 notification_id, GURL(notification_data.icon))); |
106 | 110 |
107 return notification_id; | 111 return notification_id; |
108 } | 112 } |
109 | 113 |
110 } // namespace content | 114 } // namespace content |
OLD | NEW |