| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_COMMON_NOTIFICATION_REGISTRAR_H_ | 5 #ifndef CHROME_COMMON_NOTIFICATION_REGISTRAR_H_ |
| 6 #define CHROME_COMMON_NOTIFICATION_REGISTRAR_H_ | 6 #define CHROME_COMMON_NOTIFICATION_REGISTRAR_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "chrome/browser/chrome_thread.h" |
| 11 #include "chrome/common/notification_observer.h" | 12 #include "chrome/common/notification_observer.h" |
| 12 | 13 |
| 13 // Aids in registering for notifications and ensures that all registered | 14 // Aids in registering for notifications and ensures that all registered |
| 14 // notifications are unregistered when the class is destroyed. | 15 // notifications are unregistered when the class is destroyed. |
| 15 // | 16 // |
| 16 // The intended use is that you make a NotificationRegistrar member in your | 17 // The intended use is that you make a NotificationRegistrar member in your |
| 17 // class and use it to register your notifications instead of going through the | 18 // class and use it to register your notifications instead of going through the |
| 18 // notification service directly. It will automatically unregister them for | 19 // notification service directly. It will automatically unregister them for |
| 19 // you. | 20 // you. |
| 20 class NotificationRegistrar { | 21 class NotificationRegistrar { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 32 NotificationType type, | 33 NotificationType type, |
| 33 const NotificationSource& source); | 34 const NotificationSource& source); |
| 34 | 35 |
| 35 // Unregisters all notifications. | 36 // Unregisters all notifications. |
| 36 void RemoveAll(); | 37 void RemoveAll(); |
| 37 | 38 |
| 38 // Returns true if no notifications are registered. | 39 // Returns true if no notifications are registered. |
| 39 bool IsEmpty() const; | 40 bool IsEmpty() const; |
| 40 | 41 |
| 41 private: | 42 private: |
| 43 void CheckCalledOnValidWellKnownThread(); |
| 44 |
| 42 struct Record; | 45 struct Record; |
| 43 | 46 |
| 44 // We keep registered notifications in a simple vector. This means we'll do | 47 // We keep registered notifications in a simple vector. This means we'll do |
| 45 // brute-force searches when removing them individually, but individual | 48 // brute-force searches when removing them individually, but individual |
| 46 // removal is uncommon, and there will typically only be a couple of | 49 // removal is uncommon, and there will typically only be a couple of |
| 47 // notifications anyway. | 50 // notifications anyway. |
| 48 typedef std::vector<Record> RecordVector; | 51 typedef std::vector<Record> RecordVector; |
| 49 | 52 |
| 50 // Lists all notifications we're currently registered for. | 53 // Lists all notifications we're currently registered for. |
| 51 RecordVector registered_; | 54 RecordVector registered_; |
| 52 | 55 |
| 56 // The thread creating this object. |
| 57 ChromeThread::ID thread_id_; |
| 58 |
| 53 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar); | 59 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar); |
| 54 }; | 60 }; |
| 55 | 61 |
| 56 #endif // CHROME_COMMON_NOTIFICATION_REGISTRAR_H_ | 62 #endif // CHROME_COMMON_NOTIFICATION_REGISTRAR_H_ |
| OLD | NEW |