Chromium Code Reviews| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 290 DCHECK(CalledOnValidThread()); | 290 DCHECK(CalledOnValidThread()); |
| 291 // Lookup the preference in the default store. | 291 // Lookup the preference in the default store. |
| 292 const base::Value* value = NULL; | 292 const base::Value* value = NULL; |
| 293 if (!pref_registry_->defaults()->GetValue(path, &value)) { | 293 if (!pref_registry_->defaults()->GetValue(path, &value)) { |
| 294 NOTREACHED() << "Default value missing for pref: " << path; | 294 NOTREACHED() << "Default value missing for pref: " << path; |
| 295 return NULL; | 295 return NULL; |
| 296 } | 296 } |
| 297 return value; | 297 return value; |
| 298 } | 298 } |
| 299 | 299 |
| 300 void PrefService::MarkUserStoreNeedsEmptyValue(const std::string& key) const { | |
| 301 user_pref_store_->MarkNeedsEmptyValue(key); | |
| 302 } | |
| 303 | |
| 304 const base::ListValue* PrefService::GetList(const char* path) const { | 300 const base::ListValue* PrefService::GetList(const char* path) const { |
| 305 DCHECK(CalledOnValidThread()); | 301 DCHECK(CalledOnValidThread()); |
| 306 | 302 |
| 307 const base::Value* value = GetPreferenceValue(path); | 303 const base::Value* value = GetPreferenceValue(path); |
| 308 if (!value) { | 304 if (!value) { |
| 309 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 305 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
| 310 return NULL; | 306 return NULL; |
| 311 } | 307 } |
| 312 if (value->GetType() != base::Value::TYPE_LIST) { | 308 if (value->GetType() != base::Value::TYPE_LIST) { |
| 313 NOTREACHED(); | 309 NOTREACHED(); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 342 | 338 |
| 343 // TODO(joi): Once MarkNeedsEmptyValue is gone, we can probably | 339 // TODO(joi): Once MarkNeedsEmptyValue is gone, we can probably |
| 344 // completely get rid of this method. There will be one difference in | 340 // completely get rid of this method. There will be one difference in |
| 345 // semantics; currently all registered preferences are stored right | 341 // semantics; currently all registered preferences are stored right |
| 346 // away in the prefs_map_, if we remove this they would be stored only | 342 // away in the prefs_map_, if we remove this they would be stored only |
| 347 // opportunistically. | 343 // opportunistically. |
| 348 void PrefService::AddRegisteredPreference(const char* path, | 344 void PrefService::AddRegisteredPreference(const char* path, |
| 349 base::Value* default_value) { | 345 base::Value* default_value) { |
| 350 DCHECK(CalledOnValidThread()); | 346 DCHECK(CalledOnValidThread()); |
| 351 | 347 |
| 352 // For ListValue and DictionaryValue with non empty default, empty value | 348 //REMOVE? |
|
Mattias Nissler (ping if slow)
2013/11/22 08:03:38
Yes, as well as PrefService::AddInitialPreferences
gab
2013/11/22 23:24:21
Hmmm interesting that I didn't get a PRESUBMIT che
| |
| 353 // for |path| needs to be persisted in |user_pref_store_|. So that | |
| 354 // non empty default is not used when user sets an empty ListValue or | |
| 355 // DictionaryValue. | |
| 356 bool needs_empty_value = false; | |
| 357 base::Value::Type orig_type = default_value->GetType(); | |
| 358 if (orig_type == base::Value::TYPE_LIST) { | |
| 359 const base::ListValue* list = NULL; | |
| 360 if (default_value->GetAsList(&list) && !list->empty()) | |
| 361 needs_empty_value = true; | |
| 362 } else if (orig_type == base::Value::TYPE_DICTIONARY) { | |
| 363 const base::DictionaryValue* dict = NULL; | |
| 364 if (default_value->GetAsDictionary(&dict) && !dict->empty()) | |
| 365 needs_empty_value = true; | |
| 366 } | |
| 367 if (needs_empty_value) | |
| 368 user_pref_store_->MarkNeedsEmptyValue(path); | |
| 369 } | 349 } |
| 370 | 350 |
| 371 void PrefService::ClearPref(const char* path) { | 351 void PrefService::ClearPref(const char* path) { |
| 372 DCHECK(CalledOnValidThread()); | 352 DCHECK(CalledOnValidThread()); |
| 373 | 353 |
| 374 const Preference* pref = FindPreference(path); | 354 const Preference* pref = FindPreference(path); |
| 375 if (!pref) { | 355 if (!pref) { |
| 376 NOTREACHED() << "Trying to clear an unregistered pref: " << path; | 356 NOTREACHED() << "Trying to clear an unregistered pref: " << path; |
| 377 return; | 357 return; |
| 378 } | 358 } |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 DCHECK(found_value->IsType(default_type)); | 574 DCHECK(found_value->IsType(default_type)); |
| 595 return found_value; | 575 return found_value; |
| 596 } else { | 576 } else { |
| 597 // Every registered preference has at least a default value. | 577 // Every registered preference has at least a default value. |
| 598 NOTREACHED() << "no valid value found for registered pref " << path; | 578 NOTREACHED() << "no valid value found for registered pref " << path; |
| 599 } | 579 } |
| 600 } | 580 } |
| 601 | 581 |
| 602 return NULL; | 582 return NULL; |
| 603 } | 583 } |
| OLD | NEW |