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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 return; | 378 return; |
379 } | 379 } |
380 user_pref_store_->RemoveValue(path, GetWriteFlags(pref)); | 380 user_pref_store_->RemoveValue(path, GetWriteFlags(pref)); |
381 } | 381 } |
382 | 382 |
383 void PrefService::ClearMutableValues() { | 383 void PrefService::ClearMutableValues() { |
384 user_pref_store_->ClearMutableValues(); | 384 user_pref_store_->ClearMutableValues(); |
385 } | 385 } |
386 | 386 |
387 void PrefService::Set(const std::string& path, const base::Value& value) { | 387 void PrefService::Set(const std::string& path, const base::Value& value) { |
388 SetUserPrefValue(path, value.DeepCopy()); | 388 SetUserPrefValue(path, value.CreateDeepCopy()); |
389 } | 389 } |
390 | 390 |
391 void PrefService::SetBoolean(const std::string& path, bool value) { | 391 void PrefService::SetBoolean(const std::string& path, bool value) { |
392 SetUserPrefValue(path, new base::Value(value)); | 392 SetUserPrefValue(path, base::MakeUnique<base::Value>(value)); |
393 } | 393 } |
394 | 394 |
395 void PrefService::SetInteger(const std::string& path, int value) { | 395 void PrefService::SetInteger(const std::string& path, int value) { |
396 SetUserPrefValue(path, new base::Value(value)); | 396 SetUserPrefValue(path, base::MakeUnique<base::Value>(value)); |
397 } | 397 } |
398 | 398 |
399 void PrefService::SetDouble(const std::string& path, double value) { | 399 void PrefService::SetDouble(const std::string& path, double value) { |
400 SetUserPrefValue(path, new base::Value(value)); | 400 SetUserPrefValue(path, base::MakeUnique<base::Value>(value)); |
401 } | 401 } |
402 | 402 |
403 void PrefService::SetString(const std::string& path, const std::string& value) { | 403 void PrefService::SetString(const std::string& path, const std::string& value) { |
404 SetUserPrefValue(path, new base::Value(value)); | 404 SetUserPrefValue(path, base::MakeUnique<base::Value>(value)); |
405 } | 405 } |
406 | 406 |
407 void PrefService::SetFilePath(const std::string& path, | 407 void PrefService::SetFilePath(const std::string& path, |
408 const base::FilePath& value) { | 408 const base::FilePath& value) { |
409 SetUserPrefValue(path, base::CreateFilePathValue(value)); | 409 SetUserPrefValue(path, base::CreateFilePathValue(value)); |
410 } | 410 } |
411 | 411 |
412 void PrefService::SetInt64(const std::string& path, int64_t value) { | 412 void PrefService::SetInt64(const std::string& path, int64_t value) { |
413 SetUserPrefValue(path, new base::Value(base::Int64ToString(value))); | 413 SetUserPrefValue(path, |
| 414 base::MakeUnique<base::Value>(base::Int64ToString(value))); |
414 } | 415 } |
415 | 416 |
416 int64_t PrefService::GetInt64(const std::string& path) const { | 417 int64_t PrefService::GetInt64(const std::string& path) const { |
417 DCHECK(CalledOnValidThread()); | 418 DCHECK(CalledOnValidThread()); |
418 | 419 |
419 const base::Value* value = GetPreferenceValue(path); | 420 const base::Value* value = GetPreferenceValue(path); |
420 if (!value) { | 421 if (!value) { |
421 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 422 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
422 return 0; | 423 return 0; |
423 } | 424 } |
424 std::string result("0"); | 425 std::string result("0"); |
425 bool rv = value->GetAsString(&result); | 426 bool rv = value->GetAsString(&result); |
426 DCHECK(rv); | 427 DCHECK(rv); |
427 | 428 |
428 int64_t val; | 429 int64_t val; |
429 base::StringToInt64(result, &val); | 430 base::StringToInt64(result, &val); |
430 return val; | 431 return val; |
431 } | 432 } |
432 | 433 |
433 void PrefService::SetUint64(const std::string& path, uint64_t value) { | 434 void PrefService::SetUint64(const std::string& path, uint64_t value) { |
434 SetUserPrefValue(path, new base::Value(base::Uint64ToString(value))); | 435 SetUserPrefValue(path, |
| 436 base::MakeUnique<base::Value>(base::Uint64ToString(value))); |
435 } | 437 } |
436 | 438 |
437 uint64_t PrefService::GetUint64(const std::string& path) const { | 439 uint64_t PrefService::GetUint64(const std::string& path) const { |
438 DCHECK(CalledOnValidThread()); | 440 DCHECK(CalledOnValidThread()); |
439 | 441 |
440 const base::Value* value = GetPreferenceValue(path); | 442 const base::Value* value = GetPreferenceValue(path); |
441 if (!value) { | 443 if (!value) { |
442 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 444 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
443 return 0; | 445 return 0; |
444 } | 446 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
484 } | 486 } |
485 return value; | 487 return value; |
486 } | 488 } |
487 | 489 |
488 void PrefService::ReportUserPrefChanged(const std::string& key) { | 490 void PrefService::ReportUserPrefChanged(const std::string& key) { |
489 DCHECK(CalledOnValidThread()); | 491 DCHECK(CalledOnValidThread()); |
490 user_pref_store_->ReportValueChanged(key, GetWriteFlags(FindPreference(key))); | 492 user_pref_store_->ReportValueChanged(key, GetWriteFlags(FindPreference(key))); |
491 } | 493 } |
492 | 494 |
493 void PrefService::SetUserPrefValue(const std::string& path, | 495 void PrefService::SetUserPrefValue(const std::string& path, |
494 base::Value* new_value) { | 496 std::unique_ptr<base::Value> new_value) { |
495 std::unique_ptr<base::Value> owned_value(new_value); | |
496 DCHECK(CalledOnValidThread()); | 497 DCHECK(CalledOnValidThread()); |
497 | 498 |
498 const Preference* pref = FindPreference(path); | 499 const Preference* pref = FindPreference(path); |
499 if (!pref) { | 500 if (!pref) { |
500 NOTREACHED() << "Trying to write an unregistered pref: " << path; | 501 NOTREACHED() << "Trying to write an unregistered pref: " << path; |
501 return; | 502 return; |
502 } | 503 } |
503 if (pref->GetType() != new_value->GetType()) { | 504 if (pref->GetType() != new_value->GetType()) { |
504 NOTREACHED() << "Trying to set pref " << path | 505 NOTREACHED() << "Trying to set pref " << path |
505 << " of type " << pref->GetType() | 506 << " of type " << pref->GetType() |
506 << " to value of type " << new_value->GetType(); | 507 << " to value of type " << new_value->GetType(); |
507 return; | 508 return; |
508 } | 509 } |
509 | 510 |
510 user_pref_store_->SetValue(path, std::move(owned_value), GetWriteFlags(pref)); | 511 user_pref_store_->SetValue(path, std::move(new_value), GetWriteFlags(pref)); |
511 } | 512 } |
512 | 513 |
513 void PrefService::UpdateCommandLinePrefStore(PrefStore* command_line_store) { | 514 void PrefService::UpdateCommandLinePrefStore(PrefStore* command_line_store) { |
514 pref_value_store_->UpdateCommandLinePrefStore(command_line_store); | 515 pref_value_store_->UpdateCommandLinePrefStore(command_line_store); |
515 } | 516 } |
516 | 517 |
517 /////////////////////////////////////////////////////////////////////////////// | 518 /////////////////////////////////////////////////////////////////////////////// |
518 // PrefService::Preference | 519 // PrefService::Preference |
519 | 520 |
520 PrefService::Preference::Preference(const PrefService* service, | 521 PrefService::Preference::Preference(const PrefService* service, |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 DCHECK(found_value->IsType(default_type)); | 615 DCHECK(found_value->IsType(default_type)); |
615 return found_value; | 616 return found_value; |
616 } else { | 617 } else { |
617 // Every registered preference has at least a default value. | 618 // Every registered preference has at least a default value. |
618 NOTREACHED() << "no valid value found for registered pref " << path; | 619 NOTREACHED() << "no valid value found for registered pref " << path; |
619 } | 620 } |
620 } | 621 } |
621 | 622 |
622 return NULL; | 623 return NULL; |
623 } | 624 } |
OLD | NEW |