cc: Remove unused disable_hi_res_timer_tasks_on_battery flag.
[chromium-blink-merge.git] / components / pref_registry / pref_registry_syncable.cc
blob49d0020a39f103a4713da81afaa8ffb82b1e8900
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.
5 #include "components/pref_registry/pref_registry_syncable.h"
7 #include "base/files/file_path.h"
8 #include "base/prefs/default_pref_store.h"
9 #include "base/strings/string_number_conversions.h"
10 #include "base/values.h"
12 namespace user_prefs {
14 PrefRegistrySyncable::PrefRegistrySyncable() {
17 PrefRegistrySyncable::~PrefRegistrySyncable() {
20 const PrefRegistrySyncable::PrefToStatus&
21 PrefRegistrySyncable::syncable_preferences() const {
22 return syncable_preferences_;
25 void PrefRegistrySyncable::SetSyncableRegistrationCallback(
26 const SyncableRegistrationCallback& cb) {
27 callback_ = cb;
30 void PrefRegistrySyncable::RegisterBooleanPref(const char* path,
31 bool default_value,
32 PrefSyncStatus sync_status) {
33 RegisterSyncablePreference(
34 path, new base::FundamentalValue(default_value), sync_status);
37 void PrefRegistrySyncable::RegisterIntegerPref(const char* path,
38 int default_value,
39 PrefSyncStatus sync_status) {
40 RegisterSyncablePreference(
41 path, new base::FundamentalValue(default_value), sync_status);
44 void PrefRegistrySyncable::RegisterDoublePref(const char* path,
45 double default_value,
46 PrefSyncStatus sync_status) {
47 RegisterSyncablePreference(
48 path, new base::FundamentalValue(default_value), sync_status);
51 void PrefRegistrySyncable::RegisterStringPref(const char* path,
52 const std::string& default_value,
53 PrefSyncStatus sync_status) {
54 RegisterSyncablePreference(
55 path, new base::StringValue(default_value), sync_status);
58 void PrefRegistrySyncable::RegisterFilePathPref(
59 const char* path,
60 const base::FilePath& default_value,
61 PrefSyncStatus sync_status) {
62 RegisterSyncablePreference(
63 path, new base::StringValue(default_value.value()), sync_status);
66 void PrefRegistrySyncable::RegisterListPref(const char* path,
67 PrefSyncStatus sync_status) {
68 RegisterSyncablePreference(path, new base::ListValue(), sync_status);
71 void PrefRegistrySyncable::RegisterListPref(const char* path,
72 base::ListValue* default_value,
73 PrefSyncStatus sync_status) {
74 RegisterSyncablePreference(path, default_value, sync_status);
77 void PrefRegistrySyncable::RegisterDictionaryPref(const char* path,
78 PrefSyncStatus sync_status) {
79 RegisterSyncablePreference(path, new base::DictionaryValue(), sync_status);
82 void PrefRegistrySyncable::RegisterDictionaryPref(
83 const char* path,
84 base::DictionaryValue* default_value,
85 PrefSyncStatus sync_status) {
86 RegisterSyncablePreference(path, default_value, sync_status);
89 void PrefRegistrySyncable::RegisterInt64Pref(
90 const char* path,
91 int64 default_value,
92 PrefSyncStatus sync_status) {
93 RegisterSyncablePreference(
94 path,
95 new base::StringValue(base::Int64ToString(default_value)),
96 sync_status);
99 void PrefRegistrySyncable::RegisterUint64Pref(
100 const char* path,
101 uint64 default_value,
102 PrefSyncStatus sync_status) {
103 RegisterSyncablePreference(
104 path,
105 new base::StringValue(base::Uint64ToString(default_value)),
106 sync_status);
109 void PrefRegistrySyncable::RegisterSyncablePreference(
110 const char* path,
111 base::Value* default_value,
112 PrefSyncStatus sync_status) {
113 PrefRegistry::RegisterPreference(path, default_value);
115 if (sync_status == PrefRegistrySyncable::SYNCABLE_PREF ||
116 sync_status == PrefRegistrySyncable::SYNCABLE_PRIORITY_PREF) {
117 syncable_preferences_[path] = sync_status;
119 if (!callback_.is_null())
120 callback_.Run(path, sync_status);
124 scoped_refptr<PrefRegistrySyncable> PrefRegistrySyncable::ForkForIncognito() {
125 // TODO(joi): We can directly reuse the same PrefRegistry once
126 // PrefService no longer registers for callbacks on registration and
127 // unregistration.
128 scoped_refptr<PrefRegistrySyncable> registry(new PrefRegistrySyncable());
129 registry->defaults_ = defaults_;
130 return registry;
133 } // namespace user_prefs