Content settings: remove some plugin-related code/resources when... there are no...
[chromium-blink-merge.git] / content / public / browser / notification_registrar.h
blob89d8795330d6e3aa6d838f6352a854377db3158b
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_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_
6 #define CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_
8 #include <vector>
10 #include "base/basictypes.h"
11 #include "base/threading/non_thread_safe.h"
12 #include "content/common/content_export.h"
14 namespace content {
16 class NotificationObserver;
17 class NotificationSource;
19 // Aids in registering for notifications and ensures that all registered
20 // notifications are unregistered when the class is destroyed.
22 // The intended use is that you make a NotificationRegistrar member in your
23 // class and use it to register your notifications instead of going through the
24 // notification service directly. It will automatically unregister them for
25 // you.
26 class CONTENT_EXPORT NotificationRegistrar :
27 NON_EXPORTED_BASE(public base::NonThreadSafe) {
28 public:
29 // This class must not be derived from (we don't have a virtual destructor so
30 // it won't work). Instead, use it as a member in your class.
31 NotificationRegistrar();
32 ~NotificationRegistrar();
34 // Wrappers around NotificationService::[Add|Remove]Observer.
35 void Add(NotificationObserver* observer,
36 int type,
37 const NotificationSource& source);
38 void Remove(NotificationObserver* observer,
39 int type,
40 const NotificationSource& source);
42 // Unregisters all notifications.
43 void RemoveAll();
45 // Returns true if no notifications are registered.
46 bool IsEmpty() const;
48 // Returns true if there is already a registered notification with the
49 // specified details.
50 bool IsRegistered(NotificationObserver* observer,
51 int type,
52 const NotificationSource& source);
54 private:
55 struct Record;
57 // We keep registered notifications in a simple vector. This means we'll do
58 // brute-force searches when removing them individually, but individual
59 // removal is uncommon, and there will typically only be a couple of
60 // notifications anyway.
61 typedef std::vector<Record> RecordVector;
63 // Lists all notifications we're currently registered for.
64 RecordVector registered_;
66 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar);
69 } // namespace content
71 #endif // CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_