OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_value_store.h" | 5 #include "chrome/browser/prefs/pref_value_store.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/prefs/pref_model_associator.h" | 8 #include "chrome/browser/prefs/pref_model_associator.h" |
9 #include "chrome/browser/prefs/pref_notifier.h" | 9 #include "chrome/browser/prefs/pref_notifier.h" |
10 | 10 |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
94 | 94 |
95 return new PrefValueStore( | 95 return new PrefValueStore( |
96 managed_prefs, extension_prefs, command_line_prefs, user_prefs, | 96 managed_prefs, extension_prefs, command_line_prefs, user_prefs, |
97 recommended_prefs, default_prefs, pref_sync_associator, pref_notifier); | 97 recommended_prefs, default_prefs, pref_sync_associator, pref_notifier); |
98 } | 98 } |
99 | 99 |
100 bool PrefValueStore::GetValue(const std::string& name, | 100 bool PrefValueStore::GetValue(const std::string& name, |
101 base::Value::Type type, | 101 base::Value::Type type, |
102 const Value** out_value) const { | 102 const Value** out_value) const { |
103 *out_value = NULL; | 103 *out_value = NULL; |
104 // Check the |PrefStore|s in order of their priority from highest to lowest | 104 // Check the |PrefStore|s in order of their priority from highest to lowest, |
105 // to find the value of the preference described by the given preference name. | 105 // looking for the first preference value with the given |name| and |type|. |
106 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { | 106 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { |
107 if (GetValueFromStore(name.c_str(), static_cast<PrefStoreType>(i), | 107 if (GetValueFromStoreWithType(name.c_str(), |
Mattias Nissler (ping if slow)
2012/07/27 13:21:45
nit: In function calls, you may put multiple argum
bartfab (slow)
2012/07/27 13:24:42
Done.
| |
108 out_value)) { | 108 type, |
109 if (!(*out_value)->IsType(type)) { | 109 static_cast<PrefStoreType>(i), |
110 LOG(WARNING) << "Expected type for " << name << " is " << type | 110 out_value)) |
111 << " but got " << (*out_value)->GetType() | |
112 << " in store " << i; | |
113 continue; | |
114 } | |
115 return true; | 111 return true; |
116 } | |
117 } | 112 } |
118 return false; | 113 return false; |
119 } | 114 } |
120 | 115 |
116 bool PrefValueStore::GetRecommendedValue(const std::string& name, | |
117 base::Value::Type type, | |
118 const Value** out_value) const { | |
119 return GetValueFromStoreWithType(name.c_str(), | |
Mattias Nissler (ping if slow)
2012/07/27 13:21:45
same here.
bartfab (slow)
2012/07/27 13:24:42
Done.
| |
120 type, | |
121 RECOMMENDED_STORE, | |
122 out_value); | |
123 } | |
124 | |
121 void PrefValueStore::NotifyPrefChanged( | 125 void PrefValueStore::NotifyPrefChanged( |
122 const char* path, | 126 const char* path, |
123 PrefValueStore::PrefStoreType new_store) { | 127 PrefValueStore::PrefStoreType new_store) { |
124 DCHECK(new_store != INVALID_STORE); | 128 DCHECK(new_store != INVALID_STORE); |
125 | 129 // A notification is sent when the pref value in any store changes. If this |
126 // If the pref is controlled by a higher-priority store, its effective value | 130 // store is currently being overridden by a higher-priority store, the |
127 // cannot have changed. | 131 // effective value of the pref will not have changed. |
128 PrefStoreType controller = ControllingPrefStoreForPref(path); | 132 pref_notifier_->OnPreferenceChanged(path); |
129 if (controller == INVALID_STORE || controller >= new_store) { | 133 if (pref_sync_associator_) |
130 pref_notifier_->OnPreferenceChanged(path); | 134 pref_sync_associator_->ProcessPrefChange(path); |
131 if (pref_sync_associator_) | |
132 pref_sync_associator_->ProcessPrefChange(path); | |
133 } | |
134 } | 135 } |
135 | 136 |
136 bool PrefValueStore::PrefValueInManagedStore(const char* name) const { | 137 bool PrefValueStore::PrefValueInManagedStore(const char* name) const { |
137 return PrefValueInStore(name, MANAGED_STORE); | 138 return PrefValueInStore(name, MANAGED_STORE); |
138 } | 139 } |
139 | 140 |
140 bool PrefValueStore::PrefValueInExtensionStore(const char* name) const { | 141 bool PrefValueStore::PrefValueInExtensionStore(const char* name) const { |
141 return PrefValueInStore(name, EXTENSION_STORE); | 142 return PrefValueInStore(name, EXTENSION_STORE); |
142 } | 143 } |
143 | 144 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
232 case PrefStore::READ_NO_VALUE: | 233 case PrefStore::READ_NO_VALUE: |
233 break; | 234 break; |
234 } | 235 } |
235 } | 236 } |
236 | 237 |
237 // No valid value found for the given preference name: set the return false. | 238 // No valid value found for the given preference name: set the return false. |
238 *out_value = NULL; | 239 *out_value = NULL; |
239 return false; | 240 return false; |
240 } | 241 } |
241 | 242 |
243 bool PrefValueStore::GetValueFromStoreWithType(const char* name, | |
244 base::Value::Type type, | |
245 PrefStoreType store, | |
246 const Value** out_value) const { | |
247 if (GetValueFromStore(name, store, out_value)) { | |
248 if ((*out_value)->IsType(type)) | |
249 return true; | |
250 | |
251 LOG(WARNING) << "Expected type for " << name << " is " << type | |
252 << " but got " << (*out_value)->GetType() | |
253 << " in store " << store; | |
254 } | |
255 | |
256 *out_value = NULL; | |
257 return false; | |
258 } | |
259 | |
242 void PrefValueStore::OnPrefValueChanged(PrefValueStore::PrefStoreType type, | 260 void PrefValueStore::OnPrefValueChanged(PrefValueStore::PrefStoreType type, |
243 const std::string& key) { | 261 const std::string& key) { |
244 NotifyPrefChanged(key.c_str(), type); | 262 NotifyPrefChanged(key.c_str(), type); |
245 } | 263 } |
246 | 264 |
247 void PrefValueStore::OnInitializationCompleted( | 265 void PrefValueStore::OnInitializationCompleted( |
248 PrefValueStore::PrefStoreType type, bool succeeded) { | 266 PrefValueStore::PrefStoreType type, bool succeeded) { |
249 if (initialization_failed_) | 267 if (initialization_failed_) |
250 return; | 268 return; |
251 if (!succeeded) { | 269 if (!succeeded) { |
(...skipping 13 matching lines...) Expand all Loading... | |
265 if (initialization_failed_) | 283 if (initialization_failed_) |
266 return; | 284 return; |
267 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { | 285 for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { |
268 scoped_refptr<PrefStore> store = | 286 scoped_refptr<PrefStore> store = |
269 GetPrefStore(static_cast<PrefStoreType>(i)); | 287 GetPrefStore(static_cast<PrefStoreType>(i)); |
270 if (store && !store->IsInitializationComplete()) | 288 if (store && !store->IsInitializationComplete()) |
271 return; | 289 return; |
272 } | 290 } |
273 pref_notifier_->OnInitializationCompleted(true); | 291 pref_notifier_->OnInitializationCompleted(true); |
274 } | 292 } |
OLD | NEW |