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

Unified Diff: content/child/notifications/pending_notification_tracker.h

Issue 939513002: Factor out a PendingNotificationTracker from the NotificationManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@n-sounds
Patch Set: Created 5 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_notification_tracker.h
diff --git a/content/child/notifications/pending_notification_tracker.h b/content/child/notifications/pending_notification_tracker.h
new file mode 100644
index 0000000000000000000000000000000000000000..a1d57536a73679b06fc4f0d6e47453332ee115fc
--- /dev/null
+++ b/content/child/notifications/pending_notification_tracker.h
@@ -0,0 +1,99 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATION_TRACKER_H_
+#define CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATION_TRACKER_H_
+
+#include <map>
+
+#include "base/id_map.h"
+#include "base/macros.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/memory/weak_ptr.h"
+#include "third_party/WebKit/public/platform/modules/notifications/WebNotificationManager.h"
+
+class SkBitmap;
+
+namespace base {
+class SingleThreadTaskRunner;
+}
+
+namespace blink {
+struct WebNotificationData;
+class WebNotificationDelegate;
+class WebSerializedOrigin;
+}
+
+namespace content {
+
+class NotificationManager;
+
+// Tracks all aspects of all pending Web Notifications. Most notably, it's in
+// charge of ensuring that all resource fetches associated with the notification
+// are completed as expected. The data associated with the notifications is
+// stored in this class, to maintain thread integrity of their members.
+//
+// The pending notification tracker is owned by the NotificationManager, and
+// lives on the thread that manager has been associated with.
+class PendingNotificationTracker {
+ public:
+ PendingNotificationTracker(
+ NotificationManager* manager,
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner);
+ ~PendingNotificationTracker();
+
+ // Adds a page notification to the tracker. Resource fetches for the
+ // notification will be started on asynchronously the main thread.
+ void FetchPageNotification(
mlamouri (slow - plz ping) 2015/02/18 14:53:58 nit: I find the name confusing, what about FetchPa
Peter Beverloo 2015/02/18 15:11:50 Done.
+ const blink::WebSerializedOrigin& origin,
+ const blink::WebNotificationData& notification_data,
+ blink::WebNotificationDelegate* delegate);
+
+ // Adds a persistent notification to the tracker. Resource fetches for the
+ // notification will be started asynchronously on the main thread.
+ void FetchPersistentNotification(
mlamouri (slow - plz ping) 2015/02/18 14:53:58 ditto
Peter Beverloo 2015/02/18 15:11:50 Done.
+ const blink::WebSerializedOrigin& origin,
+ const blink::WebNotificationData& notification_data,
+ int64 service_worker_registration_id,
+ scoped_ptr<blink::WebNotificationShowCallbacks> callbacks);
+
+ // Cancels all pending and in-fligth fetches for the page notification
+ // identified by |delegate|. Returns if the notification was cancelled.
+ bool CancelPageNotificationFetches(blink::WebNotificationDelegate* delegate);
+
+ private:
+ // To be called on the worker thread when the pending page notification
+ // identified by |notification_id| has finished fetching the icon.
+ void DidFetchPageNotification(int notification_id, const SkBitmap& icon);
+
+ // To be called on the worker thread when the pending persistent notification
+ // identified by |notification_id| has finished fetching the icon.
+ void DidFetchPersistentNotification(int notification_id,
+ const SkBitmap& icon);
+
+ NotificationManager* manager_;
+
+ scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_;
+
+ struct PendingPageNotification;
+ struct PendingPersistentNotification;
+
+ // List of the notifications whose resources are still being fetched.
+ IDMap<PendingPageNotification, IDMapOwnPointer> pending_page_notifications_;
+ IDMap<PendingPersistentNotification, IDMapOwnPointer>
+ pending_persistent_notifications_;
+
+ // In order to be able to cancel pending page notifications by delegate, store
+ // a mapping of the delegate to the pending notification id as well.
+ std::map<blink::WebNotificationDelegate*, int> delegate_to_pending_id_map_;
+
+ base::WeakPtrFactory<PendingNotificationTracker> weak_factory_;
+
+ DISALLOW_COPY_AND_ASSIGN(PendingNotificationTracker);
+};
+
+} // namespace content
+
+#endif // CONTENT_CHILD_NOTIFICATIONS_PENDING_NOTIFICATION_TRACKER_H_

Powered by Google App Engine
This is Rietveld 408576698