Index: content/child/notifications/pending_notifications_tracker.cc |
diff --git a/content/child/notifications/pending_notifications_tracker.cc b/content/child/notifications/pending_notifications_tracker.cc |
index 69b5c8e90b7e56cd7856998f8d16a426dd6c24eb..e9ede97abe83dd67f735c3d86dd4d866a5376b5a 100644 |
--- a/content/child/notifications/pending_notifications_tracker.cc |
+++ b/content/child/notifications/pending_notifications_tracker.cc |
@@ -9,6 +9,7 @@ |
#include "base/thread_task_runner_handle.h" |
#include "content/child/notifications/notification_image_loader.h" |
#include "content/child/notifications/notification_manager.h" |
+#include "content/child/notifications/notification_sound_loader.h" |
#include "third_party/WebKit/public/platform/WebSerializedOrigin.h" |
#include "third_party/WebKit/public/platform/modules/notifications/WebNotificationData.h" |
#include "third_party/skia/include/core/SkBitmap.h" |
@@ -18,12 +19,18 @@ namespace content { |
// Stores the information associated with a pending notification. |
struct PendingNotificationsTracker::PendingNotification { |
PendingNotification( |
+ const blink::WebNotificationData& notification, |
const scoped_refptr<NotificationImageLoader>& image_loader, |
+ const scoped_refptr<NotificationSoundLoader>& sound_loader, |
const NotificationResourcesFetchedCallback& callback) |
- : image_loader(image_loader), |
+ : notification(notification), |
+ image_loader(image_loader), |
+ sound_loader(sound_loader), |
callback(callback) {} |
+ blink::WebNotificationData notification; |
scoped_refptr<NotificationImageLoader> image_loader; |
+ scoped_refptr<NotificationSoundLoader> sound_loader; |
NotificationResourcesFetchedCallback callback; |
}; |
@@ -38,27 +45,52 @@ void PendingNotificationsTracker::FetchPageNotificationResources( |
const blink::WebNotificationData& notification_data, |
blink::WebNotificationDelegate* delegate, |
const NotificationResourcesFetchedCallback& callback) { |
- delegate_to_pending_id_map_[delegate] = FetchNotificationResources( |
- notification_data, |
- callback, |
- new NotificationImageLoader( |
- base::Bind( |
- &PendingNotificationsTracker::DidFetchPageNotification, |
- weak_factory_.GetWeakPtr(), delegate), |
- base::ThreadTaskRunnerHandle::Get())); |
+ |
+ if (!notification_data.icon.isEmpty()) { |
+ delegate_to_pending_id_map_[delegate] = FetchNotificationIcon( |
+ notification_data, |
+ callback, |
+ new NotificationImageLoader( |
+ base::Bind( |
+ &PendingNotificationsTracker::DidFetchPageNotificationIcon, |
+ weak_factory_.GetWeakPtr(), delegate), |
+ base::ThreadTaskRunnerHandle::Get())); |
+ } |
+ else if (!notification_data.sound.isEmpty()) { |
+ delegate_to_pending_id_map_[delegate] = FetchNotificationSound( |
+ notification_data, |
+ callback, |
+ new NotificationSoundLoader( |
+ base::Bind( |
+ &PendingNotificationsTracker::DidFetchPageNotificationSound, |
+ weak_factory_.GetWeakPtr(), delegate), |
+ base::ThreadTaskRunnerHandle::Get())); |
+ } |
} |
void PendingNotificationsTracker::FetchPersistentNotificationResources( |
const blink::WebNotificationData& notification_data, |
const NotificationResourcesFetchedCallback& callback) { |
- FetchNotificationResources( |
- notification_data, |
- callback, |
- new NotificationImageLoader( |
- base::Bind( |
- &PendingNotificationsTracker::DidFetchPersistentNotification, |
- weak_factory_.GetWeakPtr()), |
- base::ThreadTaskRunnerHandle::Get())); |
+ if (!notification_data.icon.isEmpty()) { |
+ FetchNotificationIcon( |
+ notification_data, |
+ callback, |
+ new NotificationImageLoader( |
+ base::Bind( |
+ &PendingNotificationsTracker::DidFetchPersistentNotificationIcon, |
+ weak_factory_.GetWeakPtr()), |
+ base::ThreadTaskRunnerHandle::Get())); |
+ } |
+ else if (!notification_data.sound.isEmpty()) { |
+ FetchNotificationSound( |
+ notification_data, |
+ callback, |
+ new NotificationSoundLoader( |
+ base::Bind( |
+ &PendingNotificationsTracker::DidFetchPersistentNotificationSound, |
+ weak_factory_.GetWeakPtr()), |
+ base::ThreadTaskRunnerHandle::Get())); |
+ } |
} |
bool PendingNotificationsTracker::CancelPageNotificationFetches( |
@@ -73,37 +105,96 @@ bool PendingNotificationsTracker::CancelPageNotificationFetches( |
return true; |
} |
-void PendingNotificationsTracker::DidFetchPageNotification( |
+void PendingNotificationsTracker::DidFetchPageNotificationIcon( |
blink::WebNotificationDelegate* delegate, |
int notification_id, |
const SkBitmap& icon) { |
+ |
+ PendingNotification* pending_notification = |
+ pending_notifications_.Lookup(notification_id); |
+ DCHECK(pending_notification); |
+ |
+ if (!pending_notification->notification.sound.isEmpty()) { |
+// Need to check |
+#if 0 |
+ pending_notification->sound_loader = new NotificationSoundLoader( |
+ base::Bind( |
+ &PendingNotificationsTracker::DidFetchPageNotificationSound, |
+ weak_factory_.GetWeakPtr(), delegate), |
+ base::ThreadTaskRunnerHandle::Get()); |
+ |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&NotificationImageLoader::StartOnMainThread, |
+ pending_notification->sound_loader, notification_id, |
+ GURL(pending_notification->notification.sound.spec()))); |
+#endif |
+ } |
+ else { |
+ pending_notification->callback.Run(icon); |
+ |
+ delegate_to_pending_id_map_.erase(delegate); |
+ pending_notifications_.Remove(notification_id); |
+ } |
+} |
+ |
+void PendingNotificationsTracker::DidFetchPageNotificationSound( |
+ blink::WebNotificationDelegate* delegate, |
+ int notification_id, |
+ const SkBitmap& sound) { |
PendingNotification* pending_notification = |
pending_notifications_.Lookup(notification_id); |
DCHECK(pending_notification); |
- pending_notification->callback.Run(icon); |
+ pending_notification->callback.Run(sound); |
delegate_to_pending_id_map_.erase(delegate); |
pending_notifications_.Remove(notification_id); |
} |
-void PendingNotificationsTracker::DidFetchPersistentNotification( |
+void PendingNotificationsTracker::DidFetchPersistentNotificationIcon( |
int notification_id, const SkBitmap& icon) { |
PendingNotification* pending_notification = |
pending_notifications_.Lookup(notification_id); |
DCHECK(pending_notification); |
- pending_notification->callback.Run(icon); |
+ if (!pending_notification->notification.sound.isEmpty()) { |
+// Need to Check |
+#if 0 |
+ pending_notification->sound_loader(new NotificationSoundLoader( |
+ base::Bind( |
+ &PendingNotificationsTracker::DidFetchPersistentNotificationSound, |
+ weak_factory_.GetWeakPtr()), |
+ base::ThreadTaskRunnerHandle::Get())); |
+ |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&NotificationImageLoader::StartOnMainThread, |
+ pending_notification->sound_loader, notification_id, |
+ GURL(pending_notification->notification.sound.spec()))); |
+#endif |
+ } |
+ else { |
+ pending_notification->callback.Run(icon); |
+ pending_notifications_.Remove(notification_id); |
+ } |
+} |
+void PendingNotificationsTracker::DidFetchPersistentNotificationSound( |
+ int notification_id, const SkBitmap& sound) { |
+ PendingNotification* pending_notification = |
+ pending_notifications_.Lookup(notification_id); |
+ DCHECK(pending_notification); |
+ |
+ pending_notification->callback.Run(sound); |
pending_notifications_.Remove(notification_id); |
} |
-int PendingNotificationsTracker::FetchNotificationResources( |
+int PendingNotificationsTracker::FetchNotificationIcon( |
const blink::WebNotificationData& notification_data, |
const NotificationResourcesFetchedCallback& callback, |
const scoped_refptr<NotificationImageLoader>& image_loader) { |
int notification_id = pending_notifications_.Add( |
- new PendingNotification(image_loader, callback)); |
+ new PendingNotification( |
+ notification_data, image_loader, nullptr, callback)); |
main_thread_task_runner_->PostTask( |
FROM_HERE, base::Bind(&NotificationImageLoader::StartOnMainThread, |
@@ -113,4 +204,19 @@ int PendingNotificationsTracker::FetchNotificationResources( |
return notification_id; |
} |
+int PendingNotificationsTracker::FetchNotificationSound( |
+ const blink::WebNotificationData& notification_data, |
+ const NotificationResourcesFetchedCallback& callback, |
+ const scoped_refptr<NotificationSoundLoader>& sound_loader) { |
+ int notification_id = pending_notifications_.Add( |
+ new PendingNotification( |
+ notification_data, nullptr, sound_loader, callback)); |
+ |
+ main_thread_task_runner_->PostTask( |
+ FROM_HERE, base::Bind(&NotificationSoundLoader::StartOnMainThread, |
+ sound_loader, notification_id, |
+ GURL(notification_data.sound.spec()))); |
+ |
+ return notification_id; |
+} |
} // namespace content |