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 #include "chrome/browser/prefs/pref_notifier_impl.h" | 5 #include "chrome/browser/prefs/pref_notifier_impl.h" |
6 | 6 |
7 #include "base/stl_util-inl.h" | 7 #include "base/stl_util-inl.h" |
8 #include "chrome/browser/prefs/pref_service.h" | 8 #include "chrome/browser/prefs/pref_service.h" |
9 #include "content/common/notification_observer.h" | 9 #include "content/common/notification_observer.h" |
10 #include "content/common/notification_service.h" | 10 #include "content/common/notification_service.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 | 68 |
69 NotificationObserverList* observer_list = observer_iterator->second; | 69 NotificationObserverList* observer_list = observer_iterator->second; |
70 observer_list->RemoveObserver(obs); | 70 observer_list->RemoveObserver(obs); |
71 } | 71 } |
72 | 72 |
73 void PrefNotifierImpl::OnPreferenceChanged(const std::string& path) { | 73 void PrefNotifierImpl::OnPreferenceChanged(const std::string& path) { |
74 FireObservers(path); | 74 FireObservers(path); |
75 } | 75 } |
76 | 76 |
77 void PrefNotifierImpl::OnInitializationCompleted() { | 77 void PrefNotifierImpl::OnInitializationCompleted() { |
78 pref_notifier_ready_ = true; | |
79 NotifyInitializationCompleted(); | |
80 } | |
81 | |
82 void PrefNotifierImpl::OnPersistentPrefsRead(bool success) { | |
Mattias Nissler (ping if slow)
2011/04/27 12:16:30
We should really get this trigger through OnInitia
altimofeev
2011/05/04 13:46:14
Done.
| |
83 if (!success) { | |
84 NotifyInitializationFailed(); | |
85 return; | |
86 } | |
87 persistent_prefs_ready_ = true; | |
88 NotifyInitializationCompleted(); | |
89 } | |
90 | |
91 void PrefNotifierImpl::NotifyInitializationCompleted() { | |
92 if (!pref_notifier_ready_ || !persistent_prefs_ready_) | |
93 return; | |
94 | |
78 DCHECK(CalledOnValidThread()); | 95 DCHECK(CalledOnValidThread()); |
79 | |
80 NotificationService::current()->Notify( | 96 NotificationService::current()->Notify( |
81 NotificationType::PREF_INITIALIZATION_COMPLETED, | 97 NotificationType::PREF_INITIALIZATION_COMPLETED, |
82 Source<PrefService>(pref_service_), | 98 Source<PrefService>(pref_service_), |
83 NotificationService::NoDetails()); | 99 NotificationService::NoDetails()); |
84 } | 100 } |
85 | 101 |
102 void PrefNotifierImpl::NotifyInitializationFailed() { | |
Mattias Nissler (ping if slow)
2011/04/27 12:16:30
We shouldn't have a second notification, but rathe
altimofeev
2011/05/04 13:46:14
Done.
| |
103 DCHECK(CalledOnValidThread()); | |
104 NotificationService::current()->Notify( | |
105 NotificationType::PREF_INITIALIZATION_FAILED, | |
106 Source<PrefService>(pref_service_), | |
107 NotificationService::NoDetails()); | |
108 } | |
109 | |
86 void PrefNotifierImpl::FireObservers(const std::string& path) { | 110 void PrefNotifierImpl::FireObservers(const std::string& path) { |
87 DCHECK(CalledOnValidThread()); | 111 DCHECK(CalledOnValidThread()); |
88 | 112 |
89 // Only send notifications for registered preferences. | 113 // Only send notifications for registered preferences. |
90 if (!pref_service_->FindPreference(path.c_str())) | 114 if (!pref_service_->FindPreference(path.c_str())) |
91 return; | 115 return; |
92 | 116 |
93 const PrefObserverMap::iterator observer_iterator = | 117 const PrefObserverMap::iterator observer_iterator = |
94 pref_observers_.find(path); | 118 pref_observers_.find(path); |
95 if (observer_iterator == pref_observers_.end()) | 119 if (observer_iterator == pref_observers_.end()) |
96 return; | 120 return; |
97 | 121 |
98 NotificationObserverList::Iterator it(*(observer_iterator->second)); | 122 NotificationObserverList::Iterator it(*(observer_iterator->second)); |
99 NotificationObserver* observer; | 123 NotificationObserver* observer; |
100 while ((observer = it.GetNext()) != NULL) { | 124 while ((observer = it.GetNext()) != NULL) { |
101 observer->Observe(NotificationType::PREF_CHANGED, | 125 observer->Observe(NotificationType::PREF_CHANGED, |
102 Source<PrefService>(pref_service_), | 126 Source<PrefService>(pref_service_), |
103 Details<const std::string>(&path)); | 127 Details<const std::string>(&path)); |
104 } | 128 } |
105 } | 129 } |
OLD | NEW |