| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #ifndef CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_ | 5 #ifndef CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_ |
| 6 #define CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_ | 6 #define CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class CONTENT_EXPORT NotificationRegistrar { | 26 class CONTENT_EXPORT NotificationRegistrar { |
| 27 public: | 27 public: |
| 28 // This class must not be derived from (we don't have a virtual destructor so | 28 // This class must not be derived from (we don't have a virtual destructor so |
| 29 // it won't work). Instead, use it as a member in your class. | 29 // it won't work). Instead, use it as a member in your class. |
| 30 NotificationRegistrar(); | 30 NotificationRegistrar(); |
| 31 ~NotificationRegistrar(); | 31 ~NotificationRegistrar(); |
| 32 | 32 |
| 33 // Wrappers around NotificationService::[Add|Remove]Observer. | 33 // Wrappers around NotificationService::[Add|Remove]Observer. |
| 34 void Add(NotificationObserver* observer, | 34 void Add(NotificationObserver* observer, |
| 35 int type, | 35 int type, |
| 36 const content::NotificationSource& source); | 36 const NotificationSource& source); |
| 37 void Remove(NotificationObserver* observer, | 37 void Remove(NotificationObserver* observer, |
| 38 int type, | 38 int type, |
| 39 const content::NotificationSource& source); | 39 const NotificationSource& source); |
| 40 | 40 |
| 41 // Unregisters all notifications. | 41 // Unregisters all notifications. |
| 42 void RemoveAll(); | 42 void RemoveAll(); |
| 43 | 43 |
| 44 // Returns true if no notifications are registered. | 44 // Returns true if no notifications are registered. |
| 45 bool IsEmpty() const; | 45 bool IsEmpty() const; |
| 46 | 46 |
| 47 // Returns true if there is already a registered notification with the | 47 // Returns true if there is already a registered notification with the |
| 48 // specified details. | 48 // specified details. |
| 49 bool IsRegistered(NotificationObserver* observer, | 49 bool IsRegistered(NotificationObserver* observer, |
| 50 int type, | 50 int type, |
| 51 const content::NotificationSource& source); | 51 const NotificationSource& source); |
| 52 | 52 |
| 53 private: | 53 private: |
| 54 struct Record; | 54 struct Record; |
| 55 | 55 |
| 56 // We keep registered notifications in a simple vector. This means we'll do | 56 // We keep registered notifications in a simple vector. This means we'll do |
| 57 // brute-force searches when removing them individually, but individual | 57 // brute-force searches when removing them individually, but individual |
| 58 // removal is uncommon, and there will typically only be a couple of | 58 // removal is uncommon, and there will typically only be a couple of |
| 59 // notifications anyway. | 59 // notifications anyway. |
| 60 typedef std::vector<Record> RecordVector; | 60 typedef std::vector<Record> RecordVector; |
| 61 | 61 |
| 62 // Lists all notifications we're currently registered for. | 62 // Lists all notifications we're currently registered for. |
| 63 RecordVector registered_; | 63 RecordVector registered_; |
| 64 | 64 |
| 65 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar); | 65 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar); |
| 66 }; | 66 }; |
| 67 | 67 |
| 68 } // namespace content | 68 } // namespace content |
| 69 | 69 |
| 70 #endif // CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_ | 70 #endif // CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_ |
| OLD | NEW |