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

Unified Diff: content/child/notifications/pending_notifications_tracker.cc

Issue 1644083002: Fetch notification action icons and pass them through in resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ActionIconBlink
Patch Set: Rebase. Created 4 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 side-by-side diff with in-line comments
Download patch
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 588af7552e3d26983581af1316e1a652cd66894d..c57bf94bec10e851a5452198e28439f8aca8bbd4 100644
--- a/content/child/notifications/pending_notifications_tracker.cc
+++ b/content/child/notifications/pending_notifications_tracker.cc
@@ -5,58 +5,47 @@
#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 "base/bind_helpers.h"
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/child/notifications/pending_notification.h"
#include "content/public/common/notification_resources.h"
-#include "third_party/WebKit/public/platform/modules/notifications/WebNotificationData.h"
-#include "third_party/skia/include/core/SkBitmap.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) {}
+ const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner)
+ : next_notification_id_(0), main_task_runner_(main_task_runner) {}
PendingNotificationsTracker::~PendingNotificationsTracker() {}
-void PendingNotificationsTracker::FetchPageNotificationResources(
+void PendingNotificationsTracker::FetchResources(
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()));
-}
+ const ResourcesCallback& resources_callback) {
+ int32_t notification_id = next_notification_id_++;
-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 (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);
+
+ scoped_ptr<PendingNotification> pending_notification(
+ new PendingNotification(main_task_runner_));
+ pending_notification->FetchResources(notification_data,
+ fetches_finished_callback);
+
+ pending_notifications_.AddWithID(pending_notification.release(),
+ notification_id);
}
-bool PendingNotificationsTracker::CancelPageNotificationFetches(
+bool PendingNotificationsTracker::CancelResourceFetches(
blink::WebNotificationDelegate* delegate) {
+ DCHECK(delegate);
+
auto iter = delegate_to_pending_id_map_.find(delegate);
if (iter == delegate_to_pending_id_map_.end())
return false;
@@ -67,48 +56,19 @@ bool PendingNotificationsTracker::CancelPageNotificationFetches(
return true;
}
-void PendingNotificationsTracker::DidFetchPageNotification(
+void PendingNotificationsTracker::FetchesFinished(
blink::WebNotificationDelegate* delegate,
- int notification_id,
- const SkBitmap& icon) {
+ int32_t notification_id,
+ const ResourcesCallback& resources_callback) {
PendingNotification* pending_notification =
pending_notifications_.Lookup(notification_id);
DCHECK(pending_notification);
- NotificationResources notification_resources;
- notification_resources.notification_icon = icon;
- pending_notification->callback.Run(notification_resources);
+ resources_callback.Run(pending_notification->GetResources());
- delegate_to_pending_id_map_.erase(delegate);
+ if (delegate)
+ delegate_to_pending_id_map_.erase(delegate);
pending_notifications_.Remove(notification_id);
}
-void PendingNotificationsTracker::DidFetchPersistentNotification(
- int notification_id, const SkBitmap& icon) {
- PendingNotification* pending_notification =
- pending_notifications_.Lookup(notification_id);
- DCHECK(pending_notification);
-
- NotificationResources notification_resources;
- notification_resources.notification_icon = icon;
- pending_notification->callback.Run(notification_resources);
-
- 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

Powered by Google App Engine
This is Rietveld 408576698