Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / content / renderer / active_notification_tracker.cc
blob2a958a5877d5f2c391dd739159b33cd4b19662dc
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;
13 namespace content {
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())
23 return false;
24 id = iter->second;
25 return true;
28 bool ActiveNotificationTracker::GetNotification(
29 int id, WebNotification* notification) {
30 WebNotification* lookup = notification_table_.Lookup(id);
31 if (!lookup)
32 return false;
34 *notification = *lookup;
35 return true;
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];
43 } else {
44 WebNotification* notification = new WebNotification(proxy);
45 int id = notification_table_.Add(notification);
46 reverse_notification_table_[proxy] = id;
47 return 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());
56 if (notification)
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