Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2010 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. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ | |
| 6 #define CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <string> | |
| 10 | |
| 11 #include "base/hash_tables.h" | |
| 12 #include "base/non_thread_safe.h" | |
| 13 #include "base/observer_list.h" | |
| 14 #include "chrome/browser/prefs/pref_notifier.h" | |
| 15 | |
| 16 class PrefService; | |
| 17 class NotificationObserver; | |
| 18 | |
| 19 // The PrefNotifier implementation used by the PrefService. | |
| 20 class PrefNotifierImpl : public PrefNotifier, | |
| 21 public NonThreadSafe { | |
| 22 public: | |
| 23 explicit PrefNotifierImpl(PrefService* pref_service); | |
| 24 virtual ~PrefNotifierImpl(); | |
| 25 | |
| 26 // If the pref at the given path changes, we call the observer's Observe | |
| 27 // method with PREF_CHANGED. | |
| 28 void AddPrefObserver(const char* path, NotificationObserver* obs); | |
| 29 void RemovePrefObserver(const char* path, NotificationObserver* obs); | |
| 30 | |
| 31 // PrefNotifier overrides. | |
| 32 virtual void OnPreferenceChanged(const std::string& pref_name); | |
| 33 virtual void OnInitializationCompleted(); | |
| 34 | |
| 35 protected: | |
| 36 // A map from pref names to a list of observers. Observers get fired in the | |
| 37 // order they are added. These should only be accessed externally for unit | |
|
danno
2010/12/06 09:20:14
nit: consistency with number of spaces after ".",
Mattias Nissler (ping if slow)
2010/12/06 10:58:12
Done.
| |
| 38 // testing. | |
| 39 typedef ObserverList<NotificationObserver> NotificationObserverList; | |
| 40 typedef base::hash_map<std::string, NotificationObserverList*> | |
| 41 PrefObserverMap; | |
|
danno
2010/12/06 09:20:14
nit: space between the typedefs and the method bel
Mattias Nissler (ping if slow)
2010/12/06 10:58:12
Done.
| |
| 42 const PrefObserverMap* pref_observers() { return &pref_observers_; } | |
|
danno
2010/12/06 09:20:14
method const too?
Mattias Nissler (ping if slow)
2010/12/06 10:58:12
Done.
| |
| 43 | |
| 44 private: | |
| 45 // For the given pref_name, fire any observer of the pref. Virtual so it can | |
| 46 // be mocked for unit testing. | |
| 47 virtual void FireObservers(const std::string& path); | |
| 48 | |
| 49 // Weak reference; the notifier is owned by the PrefService. | |
| 50 PrefService* pref_service_; | |
| 51 | |
| 52 PrefObserverMap pref_observers_; | |
| 53 | |
| 54 DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl); | |
| 55 }; | |
| 56 | |
| 57 #endif // CHROME_BROWSER_PREFS_PREF_NOTIFIER_IMPL_H_ | |
| OLD | NEW |