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 CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ |
6 #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ | 6 #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 public: | 25 public: |
26 explicit PrefNotifierImpl(PrefService* pref_service); | 26 explicit PrefNotifierImpl(PrefService* pref_service); |
27 virtual ~PrefNotifierImpl(); | 27 virtual ~PrefNotifierImpl(); |
28 | 28 |
29 // If the pref at the given path changes, we call the observer's Observe | 29 // If the pref at the given path changes, we call the observer's Observe |
30 // method with PREF_CHANGED. | 30 // method with PREF_CHANGED. |
31 void AddPrefObserver(const char* path, content::NotificationObserver* obs); | 31 void AddPrefObserver(const char* path, content::NotificationObserver* obs); |
32 void RemovePrefObserver(const char* path, content::NotificationObserver* obs); | 32 void RemovePrefObserver(const char* path, content::NotificationObserver* obs); |
33 | 33 |
34 // PrefNotifier overrides. | 34 // PrefNotifier overrides. |
35 virtual void OnPreferenceChanged(const std::string& pref_name); | 35 virtual void OnPreferenceChanged(const std::string& pref_name) OVERRIDE; |
36 virtual void OnInitializationCompleted(bool succeeded); | 36 virtual void OnInitializationCompleted(bool succeeded) OVERRIDE; |
37 | 37 |
38 protected: | 38 protected: |
39 // A map from pref names to a list of observers. Observers get fired in the | 39 // A map from pref names to a list of observers. Observers get fired in the |
40 // order they are added. These should only be accessed externally for unit | 40 // order they are added. These should only be accessed externally for unit |
41 // testing. | 41 // testing. |
42 typedef ObserverList<content::NotificationObserver> NotificationObserverList; | 42 typedef ObserverList<content::NotificationObserver> NotificationObserverList; |
43 typedef base::hash_map<std::string, NotificationObserverList*> | 43 typedef base::hash_map<std::string, NotificationObserverList*> |
44 PrefObserverMap; | 44 PrefObserverMap; |
45 | 45 |
46 const PrefObserverMap* pref_observers() const { return &pref_observers_; } | 46 const PrefObserverMap* pref_observers() const { return &pref_observers_; } |
47 | 47 |
48 private: | 48 private: |
49 // For the given pref_name, fire any observer of the pref. Virtual so it can | 49 // For the given pref_name, fire any observer of the pref. Virtual so it can |
50 // be mocked for unit testing. | 50 // be mocked for unit testing. |
51 virtual void FireObservers(const std::string& path); | 51 virtual void FireObservers(const std::string& path); |
52 | 52 |
53 // Weak reference; the notifier is owned by the PrefService. | 53 // Weak reference; the notifier is owned by the PrefService. |
54 PrefService* pref_service_; | 54 PrefService* pref_service_; |
55 | 55 |
56 PrefObserverMap pref_observers_; | 56 PrefObserverMap pref_observers_; |
57 | 57 |
58 DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl); | 58 DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl); |
59 }; | 59 }; |
60 | 60 |
61 #endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ | 61 #endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ |
OLD | NEW |