[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / content / renderer / active_notification_tracker.h
blobd201052e7ca1eec850f7a588ef4c51d7f70b810f
1 // Copyright (c) 2012 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 #ifndef CONTENT_RENDERER_ACTIVE_NOTIFICATION_TRACKER_H_
6 #define CONTENT_RENDERER_ACTIVE_NOTIFICATION_TRACKER_H_
8 #include <map>
10 #include "base/basictypes.h"
11 #include "base/id_map.h"
12 #include "base/hash_tables.h"
13 #include "content/common/content_export.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotification.h"
16 namespace WebKit {
17 class WebNotificationPermissionCallback;
20 namespace content {
22 // This class manages the set of active Notification objects in either
23 // a render or worker process. This class should be accessed only on
24 // the main thread.
25 class CONTENT_EXPORT ActiveNotificationTracker {
26 public:
27 ActiveNotificationTracker();
28 ~ActiveNotificationTracker();
30 // Methods for tracking active notification objects.
31 int RegisterNotification(const WebKit::WebNotification& notification);
32 void UnregisterNotification(int id);
33 bool GetId(const WebKit::WebNotification& notification, int& id);
34 bool GetNotification(int id, WebKit::WebNotification* notification);
36 // Methods for tracking active permission requests.
37 int RegisterPermissionRequest(
38 WebKit::WebNotificationPermissionCallback* callback);
39 void OnPermissionRequestComplete(int id);
40 WebKit::WebNotificationPermissionCallback* GetCallback(int id);
42 // Clears out all active notifications. Useful on page navigation.
43 void Clear();
45 // Detaches all active notifications from their presenter. Necessary
46 // when the Presenter is destroyed.
47 void DetachAll();
49 private:
50 typedef std::map<WebKit::WebNotification, int> ReverseTable;
52 // Tracking maps for active notifications and permission requests.
53 IDMap<WebKit::WebNotification> notification_table_;
54 ReverseTable reverse_notification_table_;
55 IDMap<WebKit::WebNotificationPermissionCallback> callback_table_;
57 DISALLOW_COPY_AND_ASSIGN(ActiveNotificationTracker);
60 } // namespace content
62 #endif // CONTENT_RENDERER_ACTIVE_NOTIFICATION_TRACKER_H_