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

Side by Side 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, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/common/desktop_notifications/active_notification_tracker.h"
6
7 #include "base/message_loop.h"
8 #include "webkit/api/public/WebNotification.h"
9 #include "webkit/api/public/WebNotificationPermissionCallback.h"
10
11 using WebKit::WebNotification;
12 using WebKit::WebNotificationPermissionCallback;
13
14 bool ActiveNotificationTracker::GetId(
15 const WebNotification& notification, int& id) {
16 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
17 ReverseTable::iterator iter = reverse_notification_table_.find(notification);
18 if (iter == reverse_notification_table_.end())
19 return false;
20 id = iter->second;
21 return true;
22 }
23
24 bool ActiveNotificationTracker::GetNotification(
25 int id, WebNotification* notification) {
26 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
27 WebNotification* lookup = notification_table_.Lookup(id);
28 if (!lookup)
29 return false;
30
31 *notification = *lookup;
32 return true;
33 }
34
35 int ActiveNotificationTracker::RegisterNotification(
36 const WebKit::WebNotification& proxy) {
37 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
38 WebNotification* notification = new WebNotification(proxy);
39 int id = notification_table_.Add(notification);
40 reverse_notification_table_[proxy] = id;
41 return id;
42 }
43
44 void ActiveNotificationTracker::UnregisterNotification(int id) {
45 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
46 // We want to free the notification after removing it from the table.
47 scoped_ptr<WebNotification> notification(notification_table_.Lookup(id));
48 notification_table_.Remove(id);
49 DCHECK(notification.get());
50 if (notification.get())
51 reverse_notification_table_.erase(*notification);
52 }
53
54 WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback(
55 int id) {
56 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
57 return callback_table_.Lookup(id);
58 }
59
60 int ActiveNotificationTracker::RegisterPermissionRequest(
61 WebNotificationPermissionCallback* callback) {
62 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
63 return callback_table_.Add(callback);
64 }
65
66 void ActiveNotificationTracker::OnPermissionRequestComplete(int id) {
67 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_UI);
68 callback_table_.Remove(id);
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698