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

Unified Diff: chrome/common/desktop_notifications/active_notification_tracker.cc

Issue 194079: renderer process notifications support (Closed)
Patch Set: last change for code review Created 11 years, 3 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: chrome/common/desktop_notifications/active_notification_tracker.cc
diff --git a/chrome/common/desktop_notifications/active_notification_tracker.cc b/chrome/common/desktop_notifications/active_notification_tracker.cc
new file mode 100644
index 0000000000000000000000000000000000000000..230d76a257f84edcd5c60d50130b546863b7c0b2
--- /dev/null
+++ b/chrome/common/desktop_notifications/active_notification_tracker.cc
@@ -0,0 +1,69 @@
+// Copyright (c) 2009 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.
+
+#include "chrome/common/desktop_notifications/active_notification_tracker.h"
+
+#include "base/message_loop.h"
+#include "webkit/api/public/WebNotification.h"
+#include "webkit/api/public/WebNotificationPermissionCallback.h"
+
+using WebKit::WebNotification;
+using WebKit::WebNotificationPermissionCallback;
+
+bool ActiveNotificationTracker::GetId(
+ const WebNotification& notification, int& id) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ ReverseTable::iterator iter = reverse_notification_table_.find(notification);
+ if (iter == reverse_notification_table_.end())
+ return false;
+ id = iter->second;
+ return true;
+}
+
+bool ActiveNotificationTracker::GetNotification(
+ int id, WebNotification* notification) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ WebNotification* lookup = notification_table_.Lookup(id);
+ if (!lookup)
+ return false;
+
+ *notification = *lookup;
+ return true;
+}
+
+int ActiveNotificationTracker::RegisterNotification(
+ const WebKit::WebNotification& proxy) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ WebNotification* notification = new WebNotification(proxy);
+ int id = notification_table_.Add(notification);
+ reverse_notification_table_[proxy] = id;
+ return id;
+}
+
+void ActiveNotificationTracker::UnregisterNotification(int id) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ // We want to free the notification after removing it from the table.
+ scoped_ptr<WebNotification> notification(notification_table_.Lookup(id));
+ notification_table_.Remove(id);
+ DCHECK(notification.get());
+ if (notification.get())
+ reverse_notification_table_.erase(*notification);
+}
+
+WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback(
+ int id) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ return callback_table_.Lookup(id);
+}
+
+int ActiveNotificationTracker::RegisterPermissionRequest(
+ WebNotificationPermissionCallback* callback) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ return callback_table_.Add(callback);
+}
+
+void ActiveNotificationTracker::OnPermissionRequestComplete(int id) {
+ DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
+ callback_table_.Remove(id);
+}

Powered by Google App Engine
This is Rietveld 408576698