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