[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 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 | |
[email protected] | 797c355 | 2011-03-17 00:26:18 | [diff] [blame^] | 5 | #ifndef CONTENT_RENDERER_ACTIVE_NOTIFICATION_TRACKER_H_ |
| 6 | #define CONTENT_RENDERER_ACTIVE_NOTIFICATION_TRACKER_H_ |
[email protected] | 32b76ef | 2010-07-26 23:08:24 | [diff] [blame] | 7 | #pragma once |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 8 | |
| 9 | #include <map> |
| 10 | |
| 11 | #include "base/basictypes.h" |
| 12 | #include "base/id_map.h" |
| 13 | #include "base/hash_tables.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 14 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotification.h" |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 15 | |
| 16 | namespace WebKit { |
| 17 | class WebNotificationPermissionCallback; |
| 18 | } |
| 19 | |
| 20 | // This class manages the set of active Notification objects in either |
| 21 | // a render or worker process. This class should be accessed only on |
| 22 | // the main thread. |
| 23 | class ActiveNotificationTracker { |
| 24 | public: |
[email protected] | 2858bbf | 2010-10-05 23:46:02 | [diff] [blame] | 25 | ActiveNotificationTracker(); |
| 26 | ~ActiveNotificationTracker(); |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 27 | |
| 28 | // Methods for tracking active notification objects. |
| 29 | int RegisterNotification(const WebKit::WebNotification& notification); |
| 30 | void UnregisterNotification(int id); |
| 31 | bool GetId(const WebKit::WebNotification& notification, int& id); |
| 32 | bool GetNotification(int id, WebKit::WebNotification* notification); |
| 33 | |
| 34 | // Methods for tracking active permission requests. |
| 35 | int RegisterPermissionRequest( |
| 36 | WebKit::WebNotificationPermissionCallback* callback); |
| 37 | void OnPermissionRequestComplete(int id); |
| 38 | WebKit::WebNotificationPermissionCallback* GetCallback(int id); |
| 39 | |
[email protected] | 42219753 | 2010-01-25 17:38:23 | [diff] [blame] | 40 | // Clears out all active notifications. Useful on page navigation. |
| 41 | void Clear(); |
| 42 | |
[email protected] | 8a2a6a2 | 2010-08-17 00:37:29 | [diff] [blame] | 43 | // Detaches all active notifications from their presenter. Necessary |
| 44 | // when the Presenter is destroyed. |
| 45 | void DetachAll(); |
| 46 | |
[email protected] | 90e90855 | 2009-10-05 01:40:12 | [diff] [blame] | 47 | private: |
| 48 | typedef std::map<WebKit::WebNotification, int> ReverseTable; |
| 49 | |
| 50 | // Tracking maps for active notifications and permission requests. |
| 51 | IDMap<WebKit::WebNotification> notification_table_; |
| 52 | ReverseTable reverse_notification_table_; |
| 53 | IDMap<WebKit::WebNotificationPermissionCallback> callback_table_; |
| 54 | |
| 55 | DISALLOW_COPY_AND_ASSIGN(ActiveNotificationTracker); |
| 56 | }; |
| 57 | |
[email protected] | 797c355 | 2011-03-17 00:26:18 | [diff] [blame^] | 58 | #endif // CONTENT_RENDERER_ACTIVE_NOTIFICATION_TRACKER_H_ |