1 // Copyright (c) 2011 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.
5 #include "content/renderer/active_notification_tracker.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/message_loop/message_loop.h"
9 #include "third_party/WebKit/public/web/WebNotification.h"
11 using blink::WebNotification
;
15 ActiveNotificationTracker::ActiveNotificationTracker() {}
17 ActiveNotificationTracker::~ActiveNotificationTracker() {}
19 bool ActiveNotificationTracker::GetId(
20 const WebNotification
& notification
, int& id
) {
21 ReverseTable::iterator iter
= reverse_notification_table_
.find(notification
);
22 if (iter
== reverse_notification_table_
.end())
28 bool ActiveNotificationTracker::GetNotification(
29 int id
, WebNotification
* notification
) {
30 WebNotification
* lookup
= notification_table_
.Lookup(id
);
34 *notification
= *lookup
;
38 int ActiveNotificationTracker::RegisterNotification(
39 const blink::WebNotification
& proxy
) {
40 if (reverse_notification_table_
.find(proxy
)
41 != reverse_notification_table_
.end()) {
42 return reverse_notification_table_
[proxy
];
44 WebNotification
* notification
= new WebNotification(proxy
);
45 int id
= notification_table_
.Add(notification
);
46 reverse_notification_table_
[proxy
] = id
;
51 void ActiveNotificationTracker::UnregisterNotification(int id
) {
52 // We want to free the notification after removing it from the table.
53 scoped_ptr
<WebNotification
> notification(notification_table_
.Lookup(id
));
54 notification_table_
.Remove(id
);
55 DCHECK(notification
.get());
57 reverse_notification_table_
.erase(*notification
);
60 void ActiveNotificationTracker::Clear() {
61 while (!reverse_notification_table_
.empty()) {
62 ReverseTable::iterator iter
= reverse_notification_table_
.begin();
63 UnregisterNotification((*iter
).second
);
67 } // namespace content