| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/threading/non_thread_safe.h" | 11 #include "base/sequence_checker.h" |
| 12 #include "content/common/content_export.h" | 12 #include "content/common/content_export.h" |
| 13 | 13 |
| 14 namespace content { | 14 namespace content { |
| 15 | 15 |
| 16 class NotificationObserver; | 16 class NotificationObserver; |
| 17 class NotificationSource; | 17 class NotificationSource; |
| 18 | 18 |
| 19 // Aids in registering for notifications and ensures that all registered | 19 // Aids in registering for notifications and ensures that all registered |
| 20 // notifications are unregistered when the class is destroyed. | 20 // notifications are unregistered when the class is destroyed. |
| 21 // | 21 // |
| 22 // The intended use is that you make a NotificationRegistrar member in your | 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 | 23 // class and use it to register your notifications instead of going through the |
| 24 // notification service directly. It will automatically unregister them for | 24 // notification service directly. It will automatically unregister them for |
| 25 // you. | 25 // you. |
| 26 class CONTENT_EXPORT NotificationRegistrar : | 26 class CONTENT_EXPORT NotificationRegistrar { |
| 27 NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
| 28 public: | 27 public: |
| 29 // 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 |
| 30 // 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. |
| 31 NotificationRegistrar(); | 30 NotificationRegistrar(); |
| 32 ~NotificationRegistrar(); | 31 ~NotificationRegistrar(); |
| 33 | 32 |
| 34 // Wrappers around NotificationService::[Add|Remove]Observer. | 33 // Wrappers around NotificationService::[Add|Remove]Observer. |
| 35 void Add(NotificationObserver* observer, | 34 void Add(NotificationObserver* observer, |
| 36 int type, | 35 int type, |
| 37 const NotificationSource& source); | 36 const NotificationSource& source); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 56 | 55 |
| 57 // 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 |
| 58 // brute-force searches when removing them individually, but individual | 57 // brute-force searches when removing them individually, but individual |
| 59 // 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 |
| 60 // notifications anyway. | 59 // notifications anyway. |
| 61 typedef std::vector<Record> RecordVector; | 60 typedef std::vector<Record> RecordVector; |
| 62 | 61 |
| 63 // Lists all notifications we're currently registered for. | 62 // Lists all notifications we're currently registered for. |
| 64 RecordVector registered_; | 63 RecordVector registered_; |
| 65 | 64 |
| 65 SEQUENCE_CHECKER(sequence_checker_); |
| 66 |
| 66 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar); | 67 DISALLOW_COPY_AND_ASSIGN(NotificationRegistrar); |
| 67 }; | 68 }; |
| 68 | 69 |
| 69 } // namespace content | 70 } // namespace content |
| 70 | 71 |
| 71 #endif // CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_ | 72 #endif // CONTENT_PUBLIC_BROWSER_NOTIFICATION_REGISTRAR_H_ |
| OLD | NEW |