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 COMPONENTS_PREFS_PREF_NOTIFIER_IMPL_H_ | 5 #ifndef COMPONENTS_PREFS_PREF_NOTIFIER_IMPL_H_ |
6 #define COMPONENTS_PREFS_PREF_NOTIFIER_IMPL_H_ | 6 #define COMPONENTS_PREFS_PREF_NOTIFIER_IMPL_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
| 9 #include <memory> |
9 #include <string> | 10 #include <string> |
10 | 11 |
11 #include "base/callback.h" | 12 #include "base/callback.h" |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
13 #include "base/containers/hash_tables.h" | 14 #include "base/containers/hash_tables.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/observer_list.h" | 16 #include "base/observer_list.h" |
16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
17 #include "components/prefs/base_prefs_export.h" | 18 #include "components/prefs/base_prefs_export.h" |
18 #include "components/prefs/pref_notifier.h" | 19 #include "components/prefs/pref_notifier.h" |
(...skipping 23 matching lines...) Expand all Loading... |
42 | 43 |
43 protected: | 44 protected: |
44 // PrefNotifier overrides. | 45 // PrefNotifier overrides. |
45 void OnPreferenceChanged(const std::string& pref_name) override; | 46 void OnPreferenceChanged(const std::string& pref_name) override; |
46 void OnInitializationCompleted(bool succeeded) override; | 47 void OnInitializationCompleted(bool succeeded) override; |
47 | 48 |
48 // A map from pref names to a list of observers. Observers get fired in the | 49 // A map from pref names to a list of observers. Observers get fired in the |
49 // order they are added. These should only be accessed externally for unit | 50 // order they are added. These should only be accessed externally for unit |
50 // testing. | 51 // testing. |
51 typedef base::ObserverList<PrefObserver> PrefObserverList; | 52 typedef base::ObserverList<PrefObserver> PrefObserverList; |
52 typedef base::hash_map<std::string, PrefObserverList*> PrefObserverMap; | 53 typedef base::hash_map<std::string, std::unique_ptr<PrefObserverList>> |
| 54 PrefObserverMap; |
53 | 55 |
54 typedef std::list<base::Callback<void(bool)>> PrefInitObserverList; | 56 typedef std::list<base::Callback<void(bool)>> PrefInitObserverList; |
55 | 57 |
56 const PrefObserverMap* pref_observers() const { return &pref_observers_; } | 58 const PrefObserverMap* pref_observers() const { return &pref_observers_; } |
57 | 59 |
58 private: | 60 private: |
59 // For the given pref_name, fire any observer of the pref. Virtual so it can | 61 // For the given pref_name, fire any observer of the pref. Virtual so it can |
60 // be mocked for unit testing. | 62 // be mocked for unit testing. |
61 virtual void FireObservers(const std::string& path); | 63 virtual void FireObservers(const std::string& path); |
62 | 64 |
63 // Weak reference; the notifier is owned by the PrefService. | 65 // Weak reference; the notifier is owned by the PrefService. |
64 PrefService* pref_service_; | 66 PrefService* pref_service_; |
65 | 67 |
66 PrefObserverMap pref_observers_; | 68 PrefObserverMap pref_observers_; |
67 PrefInitObserverList init_observers_; | 69 PrefInitObserverList init_observers_; |
68 | 70 |
69 base::ThreadChecker thread_checker_; | 71 base::ThreadChecker thread_checker_; |
70 | 72 |
71 DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl); | 73 DISALLOW_COPY_AND_ASSIGN(PrefNotifierImpl); |
72 }; | 74 }; |
73 | 75 |
74 #endif // COMPONENTS_PREFS_PREF_NOTIFIER_IMPL_H_ | 76 #endif // COMPONENTS_PREFS_PREF_NOTIFIER_IMPL_H_ |
OLD | NEW |