OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/desktop_notifications/active_notification_tracker.h" | 5 #include "chrome/common/desktop_notifications/active_notification_tracker.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "third_party/WebKit/WebKit/chromium/public/WebNotification.h" | 8 #include "third_party/WebKit/WebKit/chromium/public/WebNotification.h" |
9 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPermissionCal
lback.h" | 9 #include "third_party/WebKit/WebKit/chromium/public/WebNotificationPermissionCal
lback.h" |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 void ActiveNotificationTracker::UnregisterNotification(int id) { | 44 void ActiveNotificationTracker::UnregisterNotification(int id) { |
45 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); | 45 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); |
46 // We want to free the notification after removing it from the table. | 46 // We want to free the notification after removing it from the table. |
47 scoped_ptr<WebNotification> notification(notification_table_.Lookup(id)); | 47 scoped_ptr<WebNotification> notification(notification_table_.Lookup(id)); |
48 notification_table_.Remove(id); | 48 notification_table_.Remove(id); |
49 DCHECK(notification.get()); | 49 DCHECK(notification.get()); |
50 if (notification.get()) | 50 if (notification.get()) |
51 reverse_notification_table_.erase(*notification); | 51 reverse_notification_table_.erase(*notification); |
52 } | 52 } |
53 | 53 |
| 54 void ActiveNotificationTracker::Clear() { |
| 55 ReverseTable::iterator iter = reverse_notification_table_.begin(); |
| 56 while (iter != reverse_notification_table_.end()) { |
| 57 UnregisterNotification((*iter).second); |
| 58 ++iter; |
| 59 } |
| 60 } |
| 61 |
54 WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback( | 62 WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback( |
55 int id) { | 63 int id) { |
56 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); | 64 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); |
57 return callback_table_.Lookup(id); | 65 return callback_table_.Lookup(id); |
58 } | 66 } |
59 | 67 |
60 int ActiveNotificationTracker::RegisterPermissionRequest( | 68 int ActiveNotificationTracker::RegisterPermissionRequest( |
61 WebNotificationPermissionCallback* callback) { | 69 WebNotificationPermissionCallback* callback) { |
62 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); | 70 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); |
63 return callback_table_.Add(callback); | 71 return callback_table_.Add(callback); |
64 } | 72 } |
65 | 73 |
66 void ActiveNotificationTracker::OnPermissionRequestComplete(int id) { | 74 void ActiveNotificationTracker::OnPermissionRequestComplete(int id) { |
67 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); | 75 DCHECK(MessageLoop::current()->type() == MessageLoop::TYPE_DEFAULT); |
68 callback_table_.Remove(id); | 76 callback_table_.Remove(id); |
69 } | 77 } |
OLD | NEW |