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