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 "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 } | 175 } |
176 | 176 |
177 bool PrefService::HasPrefPath(const char* path) const { | 177 bool PrefService::HasPrefPath(const char* path) const { |
178 const Preference* pref = FindPreference(path); | 178 const Preference* pref = FindPreference(path); |
179 return pref && !pref->IsDefaultValue(); | 179 return pref && !pref->IsDefaultValue(); |
180 } | 180 } |
181 | 181 |
182 DictionaryValue* PrefService::GetPreferenceValues() const { | 182 DictionaryValue* PrefService::GetPreferenceValues() const { |
183 DCHECK(CalledOnValidThread()); | 183 DCHECK(CalledOnValidThread()); |
184 DictionaryValue* out = new DictionaryValue; | 184 DictionaryValue* out = new DictionaryValue; |
185 PrefRegistry::const_iterator i = pref_registry_->begin(); | 185 PrefRegistry::const_iterator i = pref_registry_->defaults()->begin(); |
186 for (; i != pref_registry_->end(); ++i) { | 186 for (; i != pref_registry_->defaults()->end(); ++i) { |
187 const Value* value = GetPreferenceValue(i->first); | 187 const Value* value = GetPreferenceValue(i->first); |
188 DCHECK(value); | 188 DCHECK(value); |
189 out->Set(i->first, value->DeepCopy()); | 189 out->Set(i->first, value->DeepCopy()); |
190 } | 190 } |
191 return out; | 191 return out; |
192 } | 192 } |
193 | 193 |
194 const PrefService::Preference* PrefService::FindPreference( | 194 const PrefService::Preference* PrefService::FindPreference( |
195 const char* pref_name) const { | 195 const char* pref_name) const { |
196 DCHECK(CalledOnValidThread()); | 196 DCHECK(CalledOnValidThread()); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 return NULL; | 266 return NULL; |
267 | 267 |
268 if (!value->IsType(pref->GetType())) { | 268 if (!value->IsType(pref->GetType())) { |
269 NOTREACHED() << "Pref value type doesn't match registered type."; | 269 NOTREACHED() << "Pref value type doesn't match registered type."; |
270 return NULL; | 270 return NULL; |
271 } | 271 } |
272 | 272 |
273 return value; | 273 return value; |
274 } | 274 } |
275 | 275 |
276 void PrefService::SetDefaultPrefValue(const char* path, | |
277 base::Value* value) { | |
278 DCHECK(CalledOnValidThread()); | |
279 DCHECK(pref_registry_->defaults()->GetValue(path, NULL)) | |
280 << "Setting default for unregistered pref: " << path; | |
281 pref_registry_->defaults()->SetDefaultValue(path, value); | |
Mattias Nissler (ping if slow)
2013/02/27 10:50:52
We should CHECK() that the type doesn't change her
Jói
2013/02/27 16:30:56
Done.
| |
282 } | |
283 | |
276 const base::Value* PrefService::GetDefaultPrefValue(const char* path) const { | 284 const base::Value* PrefService::GetDefaultPrefValue(const char* path) const { |
277 DCHECK(CalledOnValidThread()); | 285 DCHECK(CalledOnValidThread()); |
278 // Lookup the preference in the default store. | 286 // Lookup the preference in the default store. |
279 const base::Value* value = NULL; | 287 const base::Value* value = NULL; |
280 if (!pref_registry_->defaults()->GetValue(path, &value)) { | 288 if (!pref_registry_->defaults()->GetValue(path, &value)) { |
281 NOTREACHED() << "Default value missing for pref: " << path; | 289 NOTREACHED() << "Default value missing for pref: " << path; |
282 return NULL; | 290 return NULL; |
283 } | 291 } |
284 return value; | 292 return value; |
285 } | 293 } |
(...skipping 23 matching lines...) Expand all Loading... | |
309 | 317 |
310 void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) { | 318 void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) { |
311 pref_notifier_->AddInitObserver(obs); | 319 pref_notifier_->AddInitObserver(obs); |
312 } | 320 } |
313 | 321 |
314 PrefRegistry* PrefService::DeprecatedGetPrefRegistry() { | 322 PrefRegistry* PrefService::DeprecatedGetPrefRegistry() { |
315 return pref_registry_.get(); | 323 return pref_registry_.get(); |
316 } | 324 } |
317 | 325 |
318 void PrefService::AddInitialPreferences() { | 326 void PrefService::AddInitialPreferences() { |
319 for (PrefRegistry::const_iterator it = pref_registry_->begin(); | 327 for (PrefRegistry::const_iterator it = pref_registry_->defaults()->begin(); |
320 it != pref_registry_->end(); | 328 it != pref_registry_->defaults()->end(); |
321 ++it) { | 329 ++it) { |
322 AddRegisteredPreference(it->first.c_str(), it->second); | 330 AddRegisteredPreference(it->first.c_str(), it->second); |
323 } | 331 } |
324 } | 332 } |
325 | 333 |
326 // TODO(joi): Once MarkNeedsEmptyValue is gone, we can probably | 334 // TODO(joi): Once MarkNeedsEmptyValue is gone, we can probably |
327 // completely get rid of this method. There will be one difference in | 335 // completely get rid of this method. There will be one difference in |
328 // semantics; currently all registered preferences are stored right | 336 // semantics; currently all registered preferences are stored right |
329 // away in the prefs_map_, if we remove this they would be stored only | 337 // away in the prefs_map_, if we remove this they would be stored only |
330 // opportunistically. | 338 // opportunistically. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
575 DCHECK(found_value->IsType(default_type)); | 583 DCHECK(found_value->IsType(default_type)); |
576 return found_value; | 584 return found_value; |
577 } else { | 585 } else { |
578 // Every registered preference has at least a default value. | 586 // Every registered preference has at least a default value. |
579 NOTREACHED() << "no valid value found for registered pref " << path; | 587 NOTREACHED() << "no valid value found for registered pref " << path; |
580 } | 588 } |
581 } | 589 } |
582 | 590 |
583 return NULL; | 591 return NULL; |
584 } | 592 } |
OLD | NEW |