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

Side by Side Diff: chrome/common/desktop_notifications/active_notification_tracker.cc

Issue 6677096: Move a bunch of files from chrome\common to content\common. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 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 | Annotate | Revision Log
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 "base/scoped_ptr.h"
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotification.h"
10 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPermis sionCallback.h"
11
12 using WebKit::WebNotification;
13 using WebKit::WebNotificationPermissionCallback;
14
15 ActiveNotificationTracker::ActiveNotificationTracker() {}
16
17 ActiveNotificationTracker::~ActiveNotificationTracker() {}
18
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;
26 }
27
28 bool ActiveNotificationTracker::GetNotification(
29 int id, WebNotification* notification) {
30 WebNotification* lookup = notification_table_.Lookup(id);
31 if (!lookup)
32 return false;
33
34 *notification = *lookup;
35 return true;
36 }
37
38 int ActiveNotificationTracker::RegisterNotification(
39 const WebKit::WebNotification& proxy) {
40 WebNotification* notification = new WebNotification(proxy);
41 int id = notification_table_.Add(notification);
42 reverse_notification_table_[proxy] = id;
43 return id;
44 }
45
46 void ActiveNotificationTracker::UnregisterNotification(int id) {
47 // We want to free the notification after removing it from the table.
48 scoped_ptr<WebNotification> notification(notification_table_.Lookup(id));
49 notification_table_.Remove(id);
50 DCHECK(notification.get());
51 if (notification.get())
52 reverse_notification_table_.erase(*notification);
53 }
54
55 void ActiveNotificationTracker::Clear() {
56 while (!reverse_notification_table_.empty()) {
57 ReverseTable::iterator iter = reverse_notification_table_.begin();
58 UnregisterNotification((*iter).second);
59 }
60 }
61
62 void ActiveNotificationTracker::DetachAll() {
63 ReverseTable::iterator iter;
64 for (iter = reverse_notification_table_.begin();
65 iter != reverse_notification_table_.end();
66 ++iter) {
67 WebNotification notification(iter->first);
68 notification.detachPresenter();
69 }
70 }
71
72 WebNotificationPermissionCallback* ActiveNotificationTracker::GetCallback(
73 int id) {
74 return callback_table_.Lookup(id);
75 }
76
77 int ActiveNotificationTracker::RegisterPermissionRequest(
78 WebNotificationPermissionCallback* callback) {
79 return callback_table_.Add(callback);
80 }
81
82 void ActiveNotificationTracker::OnPermissionRequestComplete(int id) {
83 callback_table_.Remove(id);
84 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698