| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/pref_service.h" | 5 #include "chrome/browser/pref_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 pref_filename, | 112 pref_filename, |
| 113 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)), | 113 ChromeThread::GetMessageLoopProxyForThread(ChromeThread::FILE)), |
| 114 /* user prefs */ | 114 /* user prefs */ |
| 115 NULL /* no advised prefs */); | 115 NULL /* no advised prefs */); |
| 116 return new PrefService(value_store); | 116 return new PrefService(value_store); |
| 117 } | 117 } |
| 118 | 118 |
| 119 PrefService::PrefService(PrefValueStore* pref_value_store) | 119 PrefService::PrefService(PrefValueStore* pref_value_store) |
| 120 : pref_value_store_(pref_value_store) { | 120 : pref_value_store_(pref_value_store) { |
| 121 InitFromStorage(); | 121 InitFromStorage(); |
| 122 registrar_.Add(this, |
| 123 NotificationType(NotificationType::POLICY_CHANGED), |
| 124 NotificationService::AllSources()); |
| 122 } | 125 } |
| 123 | 126 |
| 124 PrefService::~PrefService() { | 127 PrefService::~PrefService() { |
| 125 DCHECK(CalledOnValidThread()); | 128 DCHECK(CalledOnValidThread()); |
| 126 | 129 |
| 127 // Verify that there are no pref observers when we shut down. | 130 // Verify that there are no pref observers when we shut down. |
| 128 for (PrefObserverMap::iterator it = pref_observers_.begin(); | 131 for (PrefObserverMap::iterator it = pref_observers_.begin(); |
| 129 it != pref_observers_.end(); ++it) { | 132 it != pref_observers_.end(); ++it) { |
| 130 NotificationObserverList::Iterator obs_iterator(*(it->second)); | 133 NotificationObserverList::Iterator obs_iterator(*(it->second)); |
| 131 if (obs_iterator.GetNext()) { | 134 if (obs_iterator.GetNext()) { |
| (...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 } | 822 } |
| 820 | 823 |
| 821 bool PrefService::Preference::IsExtensionControlled() const { | 824 bool PrefService::Preference::IsExtensionControlled() const { |
| 822 return pref_value_store_->PrefValueFromExtensionStore(name_.c_str()); | 825 return pref_value_store_->PrefValueFromExtensionStore(name_.c_str()); |
| 823 } | 826 } |
| 824 | 827 |
| 825 bool PrefService::Preference::IsUserControlled() const { | 828 bool PrefService::Preference::IsUserControlled() const { |
| 826 return pref_value_store_->PrefValueFromUserStore(name_.c_str()); | 829 return pref_value_store_->PrefValueFromUserStore(name_.c_str()); |
| 827 } | 830 } |
| 828 | 831 |
| 832 void PrefService::FireObserversForRefreshedManagedPrefs( |
| 833 std::vector<std::string> changed_prefs_paths) { |
| 834 DCHECK(CalledOnValidThread()); |
| 835 std::vector<std::string>::const_iterator current; |
| 836 for (current = changed_prefs_paths.begin(); |
| 837 current != changed_prefs_paths.end(); |
| 838 ++current) { |
| 839 FireObservers(UTF8ToWide(current->data()).data()); |
| 840 } |
| 841 } |
| 842 |
| 829 bool PrefService::Preference::IsUserModifiable() const { | 843 bool PrefService::Preference::IsUserModifiable() const { |
| 830 return pref_value_store_->PrefValueUserModifiable(name_.c_str()); | 844 return pref_value_store_->PrefValueUserModifiable(name_.c_str()); |
| 831 } | 845 } |
| 846 |
| 847 void PrefService::Observe(NotificationType type, |
| 848 const NotificationSource& source, |
| 849 const NotificationDetails& details) { |
| 850 if (type == NotificationType::POLICY_CHANGED) { |
| 851 PrefValueStore::AfterRefreshCallback callback = |
| 852 NewCallback(this, |
| 853 &PrefService::FireObserversForRefreshedManagedPrefs); |
| 854 // The notification of the policy refresh can come from any thread, |
| 855 // but the manipulation of the PrefValueStore must happen on the UI |
| 856 // thread, thus the policy refresh must be explicitly started on it. |
| 857 ChromeThread::PostTask( |
| 858 ChromeThread::UI, FROM_HERE, |
| 859 NewRunnableMethod( |
| 860 pref_value_store_.get(), |
| 861 &PrefValueStore::RefreshPolicyPrefs, |
| 862 ConfigurationPolicyPrefStore::CreateManagedPolicyPrefStore(), |
| 863 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(), |
| 864 callback)); |
| 865 } |
| 866 } |
| OLD | NEW |