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 "components/prefs/pref_service.h" | 5 #include "components/prefs/pref_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 | 281 |
282 const base::DictionaryValue* PrefService::GetDictionary( | 282 const base::DictionaryValue* PrefService::GetDictionary( |
283 const std::string& path) const { | 283 const std::string& path) const { |
284 DCHECK(CalledOnValidThread()); | 284 DCHECK(CalledOnValidThread()); |
285 | 285 |
286 const base::Value* value = GetPreferenceValue(path); | 286 const base::Value* value = GetPreferenceValue(path); |
287 if (!value) { | 287 if (!value) { |
288 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 288 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
289 return NULL; | 289 return NULL; |
290 } | 290 } |
291 if (value->GetType() != base::Value::TYPE_DICTIONARY) { | 291 if (value->GetType() != base::Value::Type::DICTIONARY) { |
292 NOTREACHED(); | 292 NOTREACHED(); |
293 return NULL; | 293 return NULL; |
294 } | 294 } |
295 return static_cast<const base::DictionaryValue*>(value); | 295 return static_cast<const base::DictionaryValue*>(value); |
296 } | 296 } |
297 | 297 |
298 const base::Value* PrefService::GetUserPrefValue( | 298 const base::Value* PrefService::GetUserPrefValue( |
299 const std::string& path) const { | 299 const std::string& path) const { |
300 DCHECK(CalledOnValidThread()); | 300 DCHECK(CalledOnValidThread()); |
301 | 301 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 } | 338 } |
339 | 339 |
340 const base::ListValue* PrefService::GetList(const std::string& path) const { | 340 const base::ListValue* PrefService::GetList(const std::string& path) const { |
341 DCHECK(CalledOnValidThread()); | 341 DCHECK(CalledOnValidThread()); |
342 | 342 |
343 const base::Value* value = GetPreferenceValue(path); | 343 const base::Value* value = GetPreferenceValue(path); |
344 if (!value) { | 344 if (!value) { |
345 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 345 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
346 return NULL; | 346 return NULL; |
347 } | 347 } |
348 if (value->GetType() != base::Value::TYPE_LIST) { | 348 if (value->GetType() != base::Value::Type::LIST) { |
349 NOTREACHED(); | 349 NOTREACHED(); |
350 return NULL; | 350 return NULL; |
351 } | 351 } |
352 return static_cast<const base::ListValue*>(value); | 352 return static_cast<const base::ListValue*>(value); |
353 } | 353 } |
354 | 354 |
355 void PrefService::AddPrefObserver(const std::string& path, PrefObserver* obs) { | 355 void PrefService::AddPrefObserver(const std::string& path, PrefObserver* obs) { |
356 pref_notifier_->AddPrefObserver(path, obs); | 356 pref_notifier_->AddPrefObserver(path, obs); |
357 } | 357 } |
358 | 358 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 bool rv = value->GetAsString(&result); | 446 bool rv = value->GetAsString(&result); |
447 DCHECK(rv); | 447 DCHECK(rv); |
448 | 448 |
449 uint64_t val; | 449 uint64_t val; |
450 base::StringToUint64(result, &val); | 450 base::StringToUint64(result, &val); |
451 return val; | 451 return val; |
452 } | 452 } |
453 | 453 |
454 base::Value* PrefService::GetMutableUserPref(const std::string& path, | 454 base::Value* PrefService::GetMutableUserPref(const std::string& path, |
455 base::Value::Type type) { | 455 base::Value::Type type) { |
456 CHECK(type == base::Value::TYPE_DICTIONARY || type == base::Value::TYPE_LIST); | 456 CHECK(type == base::Value::Type::DICTIONARY || |
| 457 type == base::Value::Type::LIST); |
457 DCHECK(CalledOnValidThread()); | 458 DCHECK(CalledOnValidThread()); |
458 | 459 |
459 const Preference* pref = FindPreference(path); | 460 const Preference* pref = FindPreference(path); |
460 if (!pref) { | 461 if (!pref) { |
461 NOTREACHED() << "Trying to get an unregistered pref: " << path; | 462 NOTREACHED() << "Trying to get an unregistered pref: " << path; |
462 return NULL; | 463 return NULL; |
463 } | 464 } |
464 if (pref->GetType() != type) { | 465 if (pref->GetType() != type) { |
465 NOTREACHED() << "Wrong type for GetMutableValue: " << path; | 466 NOTREACHED() << "Wrong type for GetMutableValue: " << path; |
466 return NULL; | 467 return NULL; |
467 } | 468 } |
468 | 469 |
469 // Look for an existing preference in the user store. If it doesn't | 470 // Look for an existing preference in the user store. If it doesn't |
470 // exist or isn't the correct type, create a new user preference. | 471 // exist or isn't the correct type, create a new user preference. |
471 base::Value* value = NULL; | 472 base::Value* value = NULL; |
472 if (!user_pref_store_->GetMutableValue(path, &value) || | 473 if (!user_pref_store_->GetMutableValue(path, &value) || |
473 !value->IsType(type)) { | 474 !value->IsType(type)) { |
474 if (type == base::Value::TYPE_DICTIONARY) { | 475 if (type == base::Value::Type::DICTIONARY) { |
475 value = new base::DictionaryValue; | 476 value = new base::DictionaryValue; |
476 } else if (type == base::Value::TYPE_LIST) { | 477 } else if (type == base::Value::Type::LIST) { |
477 value = new base::ListValue; | 478 value = new base::ListValue; |
478 } else { | 479 } else { |
479 NOTREACHED(); | 480 NOTREACHED(); |
480 } | 481 } |
481 user_pref_store_->SetValueSilently(path, base::WrapUnique(value), | 482 user_pref_store_->SetValueSilently(path, base::WrapUnique(value), |
482 GetWriteFlags(pref)); | 483 GetWriteFlags(pref)); |
483 } | 484 } |
484 return value; | 485 return value; |
485 } | 486 } |
486 | 487 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 DCHECK(found_value->IsType(default_type)); | 614 DCHECK(found_value->IsType(default_type)); |
614 return found_value; | 615 return found_value; |
615 } else { | 616 } else { |
616 // Every registered preference has at least a default value. | 617 // Every registered preference has at least a default value. |
617 NOTREACHED() << "no valid value found for registered pref " << path; | 618 NOTREACHED() << "no valid value found for registered pref " << path; |
618 } | 619 } |
619 } | 620 } |
620 | 621 |
621 return NULL; | 622 return NULL; |
622 } | 623 } |
OLD | NEW |