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 "base/prefs/pref_service.h" | 5 #include "base/prefs/pref_service.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 user_pref_store_.get(), | 79 user_pref_store_.get(), |
80 new ReadErrorHandler(read_error_callback_))); | 80 new ReadErrorHandler(read_error_callback_))); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void PrefService::CommitPendingWrite() { | 84 void PrefService::CommitPendingWrite() { |
85 DCHECK(CalledOnValidThread()); | 85 DCHECK(CalledOnValidThread()); |
86 user_pref_store_->CommitPendingWrite(); | 86 user_pref_store_->CommitPendingWrite(); |
87 } | 87 } |
88 | 88 |
89 bool PrefService::GetBoolean(const char* path) const { | 89 bool PrefService::GetBoolean(const std::string& path) const { |
90 DCHECK(CalledOnValidThread()); | 90 DCHECK(CalledOnValidThread()); |
91 | 91 |
92 bool result = false; | 92 bool result = false; |
93 | 93 |
94 const base::Value* value = GetPreferenceValue(path); | 94 const base::Value* value = GetPreferenceValue(path); |
95 if (!value) { | 95 if (!value) { |
96 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 96 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
97 return result; | 97 return result; |
98 } | 98 } |
99 bool rv = value->GetAsBoolean(&result); | 99 bool rv = value->GetAsBoolean(&result); |
100 DCHECK(rv); | 100 DCHECK(rv); |
101 return result; | 101 return result; |
102 } | 102 } |
103 | 103 |
104 int PrefService::GetInteger(const char* path) const { | 104 int PrefService::GetInteger(const std::string& path) const { |
105 DCHECK(CalledOnValidThread()); | 105 DCHECK(CalledOnValidThread()); |
106 | 106 |
107 int result = 0; | 107 int result = 0; |
108 | 108 |
109 const base::Value* value = GetPreferenceValue(path); | 109 const base::Value* value = GetPreferenceValue(path); |
110 if (!value) { | 110 if (!value) { |
111 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 111 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
112 return result; | 112 return result; |
113 } | 113 } |
114 bool rv = value->GetAsInteger(&result); | 114 bool rv = value->GetAsInteger(&result); |
115 DCHECK(rv); | 115 DCHECK(rv); |
116 return result; | 116 return result; |
117 } | 117 } |
118 | 118 |
119 double PrefService::GetDouble(const char* path) const { | 119 double PrefService::GetDouble(const std::string& path) const { |
120 DCHECK(CalledOnValidThread()); | 120 DCHECK(CalledOnValidThread()); |
121 | 121 |
122 double result = 0.0; | 122 double result = 0.0; |
123 | 123 |
124 const base::Value* value = GetPreferenceValue(path); | 124 const base::Value* value = GetPreferenceValue(path); |
125 if (!value) { | 125 if (!value) { |
126 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 126 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
127 return result; | 127 return result; |
128 } | 128 } |
129 bool rv = value->GetAsDouble(&result); | 129 bool rv = value->GetAsDouble(&result); |
130 DCHECK(rv); | 130 DCHECK(rv); |
131 return result; | 131 return result; |
132 } | 132 } |
133 | 133 |
134 std::string PrefService::GetString(const char* path) const { | 134 std::string PrefService::GetString(const std::string& path) const { |
135 DCHECK(CalledOnValidThread()); | 135 DCHECK(CalledOnValidThread()); |
136 | 136 |
137 std::string result; | 137 std::string result; |
138 | 138 |
139 const base::Value* value = GetPreferenceValue(path); | 139 const base::Value* value = GetPreferenceValue(path); |
140 if (!value) { | 140 if (!value) { |
141 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 141 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
142 return result; | 142 return result; |
143 } | 143 } |
144 bool rv = value->GetAsString(&result); | 144 bool rv = value->GetAsString(&result); |
145 DCHECK(rv); | 145 DCHECK(rv); |
146 return result; | 146 return result; |
147 } | 147 } |
148 | 148 |
149 base::FilePath PrefService::GetFilePath(const char* path) const { | 149 base::FilePath PrefService::GetFilePath(const std::string& path) const { |
150 DCHECK(CalledOnValidThread()); | 150 DCHECK(CalledOnValidThread()); |
151 | 151 |
152 base::FilePath result; | 152 base::FilePath result; |
153 | 153 |
154 const base::Value* value = GetPreferenceValue(path); | 154 const base::Value* value = GetPreferenceValue(path); |
155 if (!value) { | 155 if (!value) { |
156 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 156 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
157 return base::FilePath(result); | 157 return base::FilePath(result); |
158 } | 158 } |
159 bool rv = base::GetValueAsFilePath(*value, &result); | 159 bool rv = base::GetValueAsFilePath(*value, &result); |
160 DCHECK(rv); | 160 DCHECK(rv); |
161 return result; | 161 return result; |
162 } | 162 } |
163 | 163 |
164 bool PrefService::HasPrefPath(const char* path) const { | 164 bool PrefService::HasPrefPath(const std::string& path) const { |
165 const Preference* pref = FindPreference(path); | 165 const Preference* pref = FindPreference(path); |
166 return pref && !pref->IsDefaultValue(); | 166 return pref && !pref->IsDefaultValue(); |
167 } | 167 } |
168 | 168 |
169 scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() const { | 169 scoped_ptr<base::DictionaryValue> PrefService::GetPreferenceValues() const { |
170 DCHECK(CalledOnValidThread()); | 170 DCHECK(CalledOnValidThread()); |
171 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue); | 171 scoped_ptr<base::DictionaryValue> out(new base::DictionaryValue); |
172 PrefRegistry::const_iterator i = pref_registry_->begin(); | 172 PrefRegistry::const_iterator i = pref_registry_->begin(); |
173 for (; i != pref_registry_->end(); ++i) { | 173 for (; i != pref_registry_->end(); ++i) { |
174 const base::Value* value = GetPreferenceValue(i->first); | 174 const base::Value* value = GetPreferenceValue(i->first); |
(...skipping 10 matching lines...) Expand all Loading... |
185 PrefRegistry::const_iterator i = pref_registry_->begin(); | 185 PrefRegistry::const_iterator i = pref_registry_->begin(); |
186 for (; i != pref_registry_->end(); ++i) { | 186 for (; i != pref_registry_->end(); ++i) { |
187 const base::Value* value = GetPreferenceValue(i->first); | 187 const base::Value* value = GetPreferenceValue(i->first); |
188 DCHECK(value); | 188 DCHECK(value); |
189 out->SetWithoutPathExpansion(i->first, value->DeepCopy()); | 189 out->SetWithoutPathExpansion(i->first, value->DeepCopy()); |
190 } | 190 } |
191 return out.Pass(); | 191 return out.Pass(); |
192 } | 192 } |
193 | 193 |
194 const PrefService::Preference* PrefService::FindPreference( | 194 const PrefService::Preference* PrefService::FindPreference( |
195 const char* pref_name) const { | 195 const std::string& pref_name) const { |
196 DCHECK(CalledOnValidThread()); | 196 DCHECK(CalledOnValidThread()); |
197 PreferenceMap::iterator it = prefs_map_.find(pref_name); | 197 PreferenceMap::iterator it = prefs_map_.find(pref_name); |
198 if (it != prefs_map_.end()) | 198 if (it != prefs_map_.end()) |
199 return &(it->second); | 199 return &(it->second); |
200 const base::Value* default_value = NULL; | 200 const base::Value* default_value = NULL; |
201 if (!pref_registry_->defaults()->GetValue(pref_name, &default_value)) | 201 if (!pref_registry_->defaults()->GetValue(pref_name, &default_value)) |
202 return NULL; | 202 return NULL; |
203 it = prefs_map_.insert( | 203 it = prefs_map_.insert( |
204 std::make_pair(pref_name, Preference( | 204 std::make_pair(pref_name, Preference( |
205 this, pref_name, default_value->GetType()))).first; | 205 this, pref_name, default_value->GetType()))).first; |
(...skipping 12 matching lines...) Expand all Loading... |
218 switch (user_pref_store_->GetReadError()) { | 218 switch (user_pref_store_->GetReadError()) { |
219 case PersistentPrefStore::PREF_READ_ERROR_NONE: | 219 case PersistentPrefStore::PREF_READ_ERROR_NONE: |
220 return INITIALIZATION_STATUS_SUCCESS; | 220 return INITIALIZATION_STATUS_SUCCESS; |
221 case PersistentPrefStore::PREF_READ_ERROR_NO_FILE: | 221 case PersistentPrefStore::PREF_READ_ERROR_NO_FILE: |
222 return INITIALIZATION_STATUS_CREATED_NEW_PREF_STORE; | 222 return INITIALIZATION_STATUS_CREATED_NEW_PREF_STORE; |
223 default: | 223 default: |
224 return INITIALIZATION_STATUS_ERROR; | 224 return INITIALIZATION_STATUS_ERROR; |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 bool PrefService::IsManagedPreference(const char* pref_name) const { | 228 bool PrefService::IsManagedPreference(const std::string& pref_name) const { |
229 const Preference* pref = FindPreference(pref_name); | 229 const Preference* pref = FindPreference(pref_name); |
230 return pref && pref->IsManaged(); | 230 return pref && pref->IsManaged(); |
231 } | 231 } |
232 | 232 |
233 bool PrefService::IsUserModifiablePreference(const char* pref_name) const { | 233 bool PrefService::IsUserModifiablePreference( |
| 234 const std::string& pref_name) const { |
234 const Preference* pref = FindPreference(pref_name); | 235 const Preference* pref = FindPreference(pref_name); |
235 return pref && pref->IsUserModifiable(); | 236 return pref && pref->IsUserModifiable(); |
236 } | 237 } |
237 | 238 |
238 const base::DictionaryValue* PrefService::GetDictionary( | 239 const base::DictionaryValue* PrefService::GetDictionary( |
239 const char* path) const { | 240 const std::string& path) const { |
240 DCHECK(CalledOnValidThread()); | 241 DCHECK(CalledOnValidThread()); |
241 | 242 |
242 const base::Value* value = GetPreferenceValue(path); | 243 const base::Value* value = GetPreferenceValue(path); |
243 if (!value) { | 244 if (!value) { |
244 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 245 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
245 return NULL; | 246 return NULL; |
246 } | 247 } |
247 if (value->GetType() != base::Value::TYPE_DICTIONARY) { | 248 if (value->GetType() != base::Value::TYPE_DICTIONARY) { |
248 NOTREACHED(); | 249 NOTREACHED(); |
249 return NULL; | 250 return NULL; |
250 } | 251 } |
251 return static_cast<const base::DictionaryValue*>(value); | 252 return static_cast<const base::DictionaryValue*>(value); |
252 } | 253 } |
253 | 254 |
254 const base::Value* PrefService::GetUserPrefValue(const char* path) const { | 255 const base::Value* PrefService::GetUserPrefValue( |
| 256 const std::string& path) const { |
255 DCHECK(CalledOnValidThread()); | 257 DCHECK(CalledOnValidThread()); |
256 | 258 |
257 const Preference* pref = FindPreference(path); | 259 const Preference* pref = FindPreference(path); |
258 if (!pref) { | 260 if (!pref) { |
259 NOTREACHED() << "Trying to get an unregistered pref: " << path; | 261 NOTREACHED() << "Trying to get an unregistered pref: " << path; |
260 return NULL; | 262 return NULL; |
261 } | 263 } |
262 | 264 |
263 // Look for an existing preference in the user store. If it doesn't | 265 // Look for an existing preference in the user store. If it doesn't |
264 // exist, return NULL. | 266 // exist, return NULL. |
265 base::Value* value = NULL; | 267 base::Value* value = NULL; |
266 if (!user_pref_store_->GetMutableValue(path, &value)) | 268 if (!user_pref_store_->GetMutableValue(path, &value)) |
267 return NULL; | 269 return NULL; |
268 | 270 |
269 if (!value->IsType(pref->GetType())) { | 271 if (!value->IsType(pref->GetType())) { |
270 NOTREACHED() << "Pref value type doesn't match registered type."; | 272 NOTREACHED() << "Pref value type doesn't match registered type."; |
271 return NULL; | 273 return NULL; |
272 } | 274 } |
273 | 275 |
274 return value; | 276 return value; |
275 } | 277 } |
276 | 278 |
277 void PrefService::SetDefaultPrefValue(const char* path, | 279 void PrefService::SetDefaultPrefValue(const std::string& path, |
278 base::Value* value) { | 280 base::Value* value) { |
279 DCHECK(CalledOnValidThread()); | 281 DCHECK(CalledOnValidThread()); |
280 pref_registry_->SetDefaultPrefValue(path, value); | 282 pref_registry_->SetDefaultPrefValue(path, value); |
281 } | 283 } |
282 | 284 |
283 const base::Value* PrefService::GetDefaultPrefValue(const char* path) const { | 285 const base::Value* PrefService::GetDefaultPrefValue( |
| 286 const std::string& path) const { |
284 DCHECK(CalledOnValidThread()); | 287 DCHECK(CalledOnValidThread()); |
285 // Lookup the preference in the default store. | 288 // Lookup the preference in the default store. |
286 const base::Value* value = NULL; | 289 const base::Value* value = NULL; |
287 if (!pref_registry_->defaults()->GetValue(path, &value)) { | 290 if (!pref_registry_->defaults()->GetValue(path, &value)) { |
288 NOTREACHED() << "Default value missing for pref: " << path; | 291 NOTREACHED() << "Default value missing for pref: " << path; |
289 return NULL; | 292 return NULL; |
290 } | 293 } |
291 return value; | 294 return value; |
292 } | 295 } |
293 | 296 |
294 const base::ListValue* PrefService::GetList(const char* path) const { | 297 const base::ListValue* PrefService::GetList(const std::string& path) const { |
295 DCHECK(CalledOnValidThread()); | 298 DCHECK(CalledOnValidThread()); |
296 | 299 |
297 const base::Value* value = GetPreferenceValue(path); | 300 const base::Value* value = GetPreferenceValue(path); |
298 if (!value) { | 301 if (!value) { |
299 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 302 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
300 return NULL; | 303 return NULL; |
301 } | 304 } |
302 if (value->GetType() != base::Value::TYPE_LIST) { | 305 if (value->GetType() != base::Value::TYPE_LIST) { |
303 NOTREACHED(); | 306 NOTREACHED(); |
304 return NULL; | 307 return NULL; |
305 } | 308 } |
306 return static_cast<const base::ListValue*>(value); | 309 return static_cast<const base::ListValue*>(value); |
307 } | 310 } |
308 | 311 |
309 void PrefService::AddPrefObserver(const char* path, PrefObserver* obs) { | 312 void PrefService::AddPrefObserver(const std::string& path, PrefObserver* obs) { |
310 pref_notifier_->AddPrefObserver(path, obs); | 313 pref_notifier_->AddPrefObserver(path, obs); |
311 } | 314 } |
312 | 315 |
313 void PrefService::RemovePrefObserver(const char* path, PrefObserver* obs) { | 316 void PrefService::RemovePrefObserver(const std::string& path, |
| 317 PrefObserver* obs) { |
314 pref_notifier_->RemovePrefObserver(path, obs); | 318 pref_notifier_->RemovePrefObserver(path, obs); |
315 } | 319 } |
316 | 320 |
317 void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) { | 321 void PrefService::AddPrefInitObserver(base::Callback<void(bool)> obs) { |
318 pref_notifier_->AddInitObserver(obs); | 322 pref_notifier_->AddInitObserver(obs); |
319 } | 323 } |
320 | 324 |
321 PrefRegistry* PrefService::DeprecatedGetPrefRegistry() { | 325 PrefRegistry* PrefService::DeprecatedGetPrefRegistry() { |
322 return pref_registry_.get(); | 326 return pref_registry_.get(); |
323 } | 327 } |
324 | 328 |
325 void PrefService::ClearPref(const char* path) { | 329 void PrefService::ClearPref(const std::string& path) { |
326 DCHECK(CalledOnValidThread()); | 330 DCHECK(CalledOnValidThread()); |
327 | 331 |
328 const Preference* pref = FindPreference(path); | 332 const Preference* pref = FindPreference(path); |
329 if (!pref) { | 333 if (!pref) { |
330 NOTREACHED() << "Trying to clear an unregistered pref: " << path; | 334 NOTREACHED() << "Trying to clear an unregistered pref: " << path; |
331 return; | 335 return; |
332 } | 336 } |
333 user_pref_store_->RemoveValue(path); | 337 user_pref_store_->RemoveValue(path); |
334 } | 338 } |
335 | 339 |
336 void PrefService::Set(const char* path, const base::Value& value) { | 340 void PrefService::Set(const std::string& path, const base::Value& value) { |
337 SetUserPrefValue(path, value.DeepCopy()); | 341 SetUserPrefValue(path, value.DeepCopy()); |
338 } | 342 } |
339 | 343 |
340 void PrefService::SetBoolean(const char* path, bool value) { | 344 void PrefService::SetBoolean(const std::string& path, bool value) { |
341 SetUserPrefValue(path, new base::FundamentalValue(value)); | 345 SetUserPrefValue(path, new base::FundamentalValue(value)); |
342 } | 346 } |
343 | 347 |
344 void PrefService::SetInteger(const char* path, int value) { | 348 void PrefService::SetInteger(const std::string& path, int value) { |
345 SetUserPrefValue(path, new base::FundamentalValue(value)); | 349 SetUserPrefValue(path, new base::FundamentalValue(value)); |
346 } | 350 } |
347 | 351 |
348 void PrefService::SetDouble(const char* path, double value) { | 352 void PrefService::SetDouble(const std::string& path, double value) { |
349 SetUserPrefValue(path, new base::FundamentalValue(value)); | 353 SetUserPrefValue(path, new base::FundamentalValue(value)); |
350 } | 354 } |
351 | 355 |
352 void PrefService::SetString(const char* path, const std::string& value) { | 356 void PrefService::SetString(const std::string& path, const std::string& value) { |
353 SetUserPrefValue(path, new base::StringValue(value)); | 357 SetUserPrefValue(path, new base::StringValue(value)); |
354 } | 358 } |
355 | 359 |
356 void PrefService::SetFilePath(const char* path, const base::FilePath& value) { | 360 void PrefService::SetFilePath(const std::string& path, |
| 361 const base::FilePath& value) { |
357 SetUserPrefValue(path, base::CreateFilePathValue(value)); | 362 SetUserPrefValue(path, base::CreateFilePathValue(value)); |
358 } | 363 } |
359 | 364 |
360 void PrefService::SetInt64(const char* path, int64 value) { | 365 void PrefService::SetInt64(const std::string& path, int64 value) { |
361 SetUserPrefValue(path, new base::StringValue(base::Int64ToString(value))); | 366 SetUserPrefValue(path, new base::StringValue(base::Int64ToString(value))); |
362 } | 367 } |
363 | 368 |
364 int64 PrefService::GetInt64(const char* path) const { | 369 int64 PrefService::GetInt64(const std::string& path) const { |
365 DCHECK(CalledOnValidThread()); | 370 DCHECK(CalledOnValidThread()); |
366 | 371 |
367 const base::Value* value = GetPreferenceValue(path); | 372 const base::Value* value = GetPreferenceValue(path); |
368 if (!value) { | 373 if (!value) { |
369 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 374 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
370 return 0; | 375 return 0; |
371 } | 376 } |
372 std::string result("0"); | 377 std::string result("0"); |
373 bool rv = value->GetAsString(&result); | 378 bool rv = value->GetAsString(&result); |
374 DCHECK(rv); | 379 DCHECK(rv); |
375 | 380 |
376 int64 val; | 381 int64 val; |
377 base::StringToInt64(result, &val); | 382 base::StringToInt64(result, &val); |
378 return val; | 383 return val; |
379 } | 384 } |
380 | 385 |
381 void PrefService::SetUint64(const char* path, uint64 value) { | 386 void PrefService::SetUint64(const std::string& path, uint64 value) { |
382 SetUserPrefValue(path, new base::StringValue(base::Uint64ToString(value))); | 387 SetUserPrefValue(path, new base::StringValue(base::Uint64ToString(value))); |
383 } | 388 } |
384 | 389 |
385 uint64 PrefService::GetUint64(const char* path) const { | 390 uint64 PrefService::GetUint64(const std::string& path) const { |
386 DCHECK(CalledOnValidThread()); | 391 DCHECK(CalledOnValidThread()); |
387 | 392 |
388 const base::Value* value = GetPreferenceValue(path); | 393 const base::Value* value = GetPreferenceValue(path); |
389 if (!value) { | 394 if (!value) { |
390 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 395 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
391 return 0; | 396 return 0; |
392 } | 397 } |
393 std::string result("0"); | 398 std::string result("0"); |
394 bool rv = value->GetAsString(&result); | 399 bool rv = value->GetAsString(&result); |
395 DCHECK(rv); | 400 DCHECK(rv); |
396 | 401 |
397 uint64 val; | 402 uint64 val; |
398 base::StringToUint64(result, &val); | 403 base::StringToUint64(result, &val); |
399 return val; | 404 return val; |
400 } | 405 } |
401 | 406 |
402 base::Value* PrefService::GetMutableUserPref(const char* path, | 407 base::Value* PrefService::GetMutableUserPref(const std::string& path, |
403 base::Value::Type type) { | 408 base::Value::Type type) { |
404 CHECK(type == base::Value::TYPE_DICTIONARY || type == base::Value::TYPE_LIST); | 409 CHECK(type == base::Value::TYPE_DICTIONARY || type == base::Value::TYPE_LIST); |
405 DCHECK(CalledOnValidThread()); | 410 DCHECK(CalledOnValidThread()); |
406 | 411 |
407 const Preference* pref = FindPreference(path); | 412 const Preference* pref = FindPreference(path); |
408 if (!pref) { | 413 if (!pref) { |
409 NOTREACHED() << "Trying to get an unregistered pref: " << path; | 414 NOTREACHED() << "Trying to get an unregistered pref: " << path; |
410 return NULL; | 415 return NULL; |
411 } | 416 } |
412 if (pref->GetType() != type) { | 417 if (pref->GetType() != type) { |
(...skipping 16 matching lines...) Expand all Loading... |
429 user_pref_store_->SetValueSilently(path, value); | 434 user_pref_store_->SetValueSilently(path, value); |
430 } | 435 } |
431 return value; | 436 return value; |
432 } | 437 } |
433 | 438 |
434 void PrefService::ReportUserPrefChanged(const std::string& key) { | 439 void PrefService::ReportUserPrefChanged(const std::string& key) { |
435 DCHECK(CalledOnValidThread()); | 440 DCHECK(CalledOnValidThread()); |
436 user_pref_store_->ReportValueChanged(key); | 441 user_pref_store_->ReportValueChanged(key); |
437 } | 442 } |
438 | 443 |
439 void PrefService::SetUserPrefValue(const char* path, base::Value* new_value) { | 444 void PrefService::SetUserPrefValue(const std::string& path, |
| 445 base::Value* new_value) { |
440 scoped_ptr<base::Value> owned_value(new_value); | 446 scoped_ptr<base::Value> owned_value(new_value); |
441 DCHECK(CalledOnValidThread()); | 447 DCHECK(CalledOnValidThread()); |
442 | 448 |
443 const Preference* pref = FindPreference(path); | 449 const Preference* pref = FindPreference(path); |
444 if (!pref) { | 450 if (!pref) { |
445 NOTREACHED() << "Trying to write an unregistered pref: " << path; | 451 NOTREACHED() << "Trying to write an unregistered pref: " << path; |
446 return; | 452 return; |
447 } | 453 } |
448 if (pref->GetType() != new_value->GetType()) { | 454 if (pref->GetType() != new_value->GetType()) { |
449 NOTREACHED() << "Trying to set pref " << path | 455 NOTREACHED() << "Trying to set pref " << path |
450 << " of type " << pref->GetType() | 456 << " of type " << pref->GetType() |
451 << " to value of type " << new_value->GetType(); | 457 << " to value of type " << new_value->GetType(); |
452 return; | 458 return; |
453 } | 459 } |
454 | 460 |
455 user_pref_store_->SetValue(path, owned_value.release()); | 461 user_pref_store_->SetValue(path, owned_value.release()); |
456 } | 462 } |
457 | 463 |
458 void PrefService::UpdateCommandLinePrefStore(PrefStore* command_line_store) { | 464 void PrefService::UpdateCommandLinePrefStore(PrefStore* command_line_store) { |
459 pref_value_store_->UpdateCommandLinePrefStore(command_line_store); | 465 pref_value_store_->UpdateCommandLinePrefStore(command_line_store); |
460 } | 466 } |
461 | 467 |
462 /////////////////////////////////////////////////////////////////////////////// | 468 /////////////////////////////////////////////////////////////////////////////// |
463 // PrefService::Preference | 469 // PrefService::Preference |
464 | 470 |
465 PrefService::Preference::Preference(const PrefService* service, | 471 PrefService::Preference::Preference(const PrefService* service, |
466 const char* name, | 472 const std::string& name, |
467 base::Value::Type type) | 473 base::Value::Type type) |
468 : name_(name), | 474 : name_(name), type_(type), pref_service_(service) { |
469 type_(type), | |
470 pref_service_(service) { | |
471 DCHECK(name); | |
472 DCHECK(service); | 475 DCHECK(service); |
473 } | 476 } |
474 | 477 |
475 const std::string PrefService::Preference::name() const { | 478 const std::string PrefService::Preference::name() const { |
476 return name_; | 479 return name_; |
477 } | 480 } |
478 | 481 |
479 base::Value::Type PrefService::Preference::GetType() const { | 482 base::Value::Type PrefService::Preference::GetType() const { |
480 return type_; | 483 return type_; |
481 } | 484 } |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 DCHECK(found_value->IsType(default_type)); | 550 DCHECK(found_value->IsType(default_type)); |
548 return found_value; | 551 return found_value; |
549 } else { | 552 } else { |
550 // Every registered preference has at least a default value. | 553 // Every registered preference has at least a default value. |
551 NOTREACHED() << "no valid value found for registered pref " << path; | 554 NOTREACHED() << "no valid value found for registered pref " << path; |
552 } | 555 } |
553 } | 556 } |
554 | 557 |
555 return NULL; | 558 return NULL; |
556 } | 559 } |
OLD | NEW |