pref_registry_simple.cc 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  3. // found in the LICENSE file.
  4. #include "components/prefs/pref_registry_simple.h"
  5. #include <utility>
  6. #include "base/files/file_path.h"
  7. #include "base/strings/string_number_conversions.h"
  8. #include "base/strings/string_util.h"
  9. #include "base/values.h"
  10. PrefRegistrySimple::PrefRegistrySimple() = default;
  11. PrefRegistrySimple::~PrefRegistrySimple() = default;
  12. void PrefRegistrySimple::RegisterBooleanPref(const std::string& path,
  13. bool default_value,
  14. uint32_t flags) {
  15. RegisterPreference(path, base::Value(default_value), flags);
  16. }
  17. void PrefRegistrySimple::RegisterIntegerPref(const std::string& path,
  18. int default_value,
  19. uint32_t flags) {
  20. RegisterPreference(path, base::Value(default_value), flags);
  21. }
  22. void PrefRegistrySimple::RegisterDoublePref(const std::string& path,
  23. double default_value,
  24. uint32_t flags) {
  25. RegisterPreference(path, base::Value(default_value), flags);
  26. }
  27. void PrefRegistrySimple::RegisterStringPref(const std::string& path,
  28. const std::string& default_value,
  29. uint32_t flags) {
  30. RegisterPreference(path, base::Value(default_value), flags);
  31. }
  32. void PrefRegistrySimple::RegisterFilePathPref(
  33. const std::string& path,
  34. const base::FilePath& default_value,
  35. uint32_t flags) {
  36. RegisterPreference(path, base::Value(default_value.AsUTF8Unsafe()), flags);
  37. }
  38. void PrefRegistrySimple::RegisterListPref(const std::string& path,
  39. uint32_t flags) {
  40. RegisterPreference(path, base::Value(base::Value::Type::LIST), flags);
  41. }
  42. void PrefRegistrySimple::RegisterListPref(const std::string& path,
  43. base::Value default_value,
  44. uint32_t flags) {
  45. RegisterPreference(path, std::move(default_value), flags);
  46. }
  47. void PrefRegistrySimple::RegisterListPref(const std::string& path,
  48. base::Value::List default_value,
  49. uint32_t flags) {
  50. RegisterPreference(path, base::Value(std::move(default_value)), flags);
  51. }
  52. void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
  53. uint32_t flags) {
  54. RegisterPreference(path, base::Value(base::Value::Type::DICTIONARY), flags);
  55. }
  56. void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
  57. base::Value default_value,
  58. uint32_t flags) {
  59. RegisterPreference(path, std::move(default_value), flags);
  60. }
  61. void PrefRegistrySimple::RegisterDictionaryPref(const std::string& path,
  62. base::Value::Dict default_value,
  63. uint32_t flags) {
  64. RegisterPreference(path, base::Value(std::move(default_value)), flags);
  65. }
  66. void PrefRegistrySimple::RegisterInt64Pref(const std::string& path,
  67. int64_t default_value,
  68. uint32_t flags) {
  69. RegisterPreference(path, base::Value(base::NumberToString(default_value)),
  70. flags);
  71. }
  72. void PrefRegistrySimple::RegisterUint64Pref(const std::string& path,
  73. uint64_t default_value,
  74. uint32_t flags) {
  75. RegisterPreference(path, base::Value(base::NumberToString(default_value)),
  76. flags);
  77. }
  78. void PrefRegistrySimple::RegisterTimePref(const std::string& path,
  79. base::Time default_value,
  80. uint32_t flags) {
  81. RegisterInt64Pref(
  82. path, default_value.ToDeltaSinceWindowsEpoch().InMicroseconds(), flags);
  83. }
  84. void PrefRegistrySimple::RegisterTimeDeltaPref(const std::string& path,
  85. base::TimeDelta default_value,
  86. uint32_t flags) {
  87. RegisterInt64Pref(path, default_value.InMicroseconds(), flags);
  88. }