| 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 2ee031d4b6741b5aba12c9a61c13b7457f8c0e57..806c52c5ac306b4666c09e6225395325c638fc62 100644
|
| --- a/content/child/notifications/pending_notifications_tracker.cc
|
| +++ b/content/child/notifications/pending_notifications_tracker.cc
|
| @@ -5,57 +5,38 @@
|
| #include "content/child/notifications/pending_notifications_tracker.h"
|
|
|
| #include "base/bind.h"
|
| -#include "base/location.h"
|
| -#include "base/thread_task_runner_handle.h"
|
| -#include "content/child/notifications/notification_image_loader.h"
|
| -#include "content/child/notifications/notification_manager.h"
|
| -#include "third_party/WebKit/public/platform/modules/notifications/WebNotificationData.h"
|
| -#include "third_party/skia/include/core/SkBitmap.h"
|
| +#include "base/bind_helpers.h"
|
| +#include "base/callback.h"
|
| +#include "content/child/notifications/pending_notification.h"
|
| +#include "content/public/common/notification_resources.h"
|
|
|
| namespace content {
|
|
|
| -// Stores the information associated with a pending notification.
|
| -struct PendingNotificationsTracker::PendingNotification {
|
| - PendingNotification(
|
| - const scoped_refptr<NotificationImageLoader>& image_loader,
|
| - const NotificationResourcesFetchedCallback& callback)
|
| - : image_loader(image_loader), callback(callback) {}
|
| -
|
| - scoped_refptr<NotificationImageLoader> image_loader;
|
| - NotificationResourcesFetchedCallback callback;
|
| -};
|
| -
|
| PendingNotificationsTracker::PendingNotificationsTracker(
|
| scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner)
|
| - : main_thread_task_runner_(main_thread_task_runner), weak_factory_(this) {}
|
| + : next_notification_id_(0),
|
| + main_thread_task_runner_(main_thread_task_runner) {}
|
|
|
| PendingNotificationsTracker::~PendingNotificationsTracker() {}
|
|
|
| -void PendingNotificationsTracker::FetchPageNotificationResources(
|
| +void PendingNotificationsTracker::FetchNotificationResources(
|
| 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()));
|
| -}
|
| -
|
| -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()));
|
| + const NotificationResourcesCallback& resources_callback) {
|
| + int32_t notification_id = next_notification_id_++;
|
| + if (delegate)
|
| + delegate_to_pending_id_map_[delegate] = notification_id;
|
| + base::Closure fetches_finished_callback = base::Bind(
|
| + &PendingNotificationsTracker::FetchesFinished,
|
| + base::Unretained(this) /* The pending notifications are owned by this. */,
|
| + delegate, notification_id, resources_callback);
|
| + PendingNotification* pending_notification = new PendingNotification(
|
| + main_thread_task_runner_, notification_data, fetches_finished_callback);
|
| + pending_notifications_.AddWithID(pending_notification, notification_id);
|
| + pending_notification->FetchResources();
|
| }
|
|
|
| -bool PendingNotificationsTracker::CancelPageNotificationFetches(
|
| +bool PendingNotificationsTracker::CancelResourceFetches(
|
| blink::WebNotificationDelegate* delegate) {
|
| auto iter = delegate_to_pending_id_map_.find(delegate);
|
| if (iter == delegate_to_pending_id_map_.end())
|
| @@ -67,44 +48,19 @@ bool PendingNotificationsTracker::CancelPageNotificationFetches(
|
| return true;
|
| }
|
|
|
| -void PendingNotificationsTracker::DidFetchPageNotification(
|
| +void PendingNotificationsTracker::FetchesFinished(
|
| blink::WebNotificationDelegate* delegate,
|
| - int notification_id,
|
| - const SkBitmap& icon) {
|
| - PendingNotification* pending_notification =
|
| - pending_notifications_.Lookup(notification_id);
|
| - DCHECK(pending_notification);
|
| -
|
| - pending_notification->callback.Run(icon);
|
| -
|
| - delegate_to_pending_id_map_.erase(delegate);
|
| - pending_notifications_.Remove(notification_id);
|
| -}
|
| -
|
| -void PendingNotificationsTracker::DidFetchPersistentNotification(
|
| - int notification_id, const SkBitmap& icon) {
|
| + int32_t notification_id,
|
| + const NotificationResourcesCallback& resources_callback) {
|
| PendingNotification* pending_notification =
|
| pending_notifications_.Lookup(notification_id);
|
| DCHECK(pending_notification);
|
|
|
| - pending_notification->callback.Run(icon);
|
| + resources_callback.Run(pending_notification->GetResources());
|
|
|
| + if (delegate)
|
| + delegate_to_pending_id_map_.erase(delegate);
|
| pending_notifications_.Remove(notification_id);
|
| }
|
|
|
| -int PendingNotificationsTracker::FetchNotificationResources(
|
| - 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));
|
| -
|
| - main_thread_task_runner_->PostTask(
|
| - FROM_HERE,
|
| - base::Bind(&NotificationImageLoader::StartOnMainThread, image_loader,
|
| - notification_id, GURL(notification_data.icon)));
|
| -
|
| - return notification_id;
|
| -}
|
| -
|
| } // namespace content
|
|
|