| 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 "chrome/browser/prefs/pref_service.h" | 5 #include "chrome/browser/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/file_path.h" | 10 #include "base/file_path.h" |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 | 306 |
| 307 // The main code path takes ownership, but most don't. We'll be safe. | 307 // The main code path takes ownership, but most don't. We'll be safe. |
| 308 scoped_ptr<Value> scoped_value(default_value); | 308 scoped_ptr<Value> scoped_value(default_value); |
| 309 | 309 |
| 310 CHECK(!FindPreference(path)) << "Tried to register duplicate pref " << path; | 310 CHECK(!FindPreference(path)) << "Tried to register duplicate pref " << path; |
| 311 | 311 |
| 312 base::Value::Type orig_type = default_value->GetType(); | 312 base::Value::Type orig_type = default_value->GetType(); |
| 313 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << | 313 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << |
| 314 "invalid preference type: " << orig_type; | 314 "invalid preference type: " << orig_type; |
| 315 | 315 |
| 316 // For ListValue and DictionaryValue with non empty default, empty value | |
| 317 // for |path| needs to be persisted in |user_pref_store_|. So that | |
| 318 // non empty default is not used when user sets an empty ListValue or | |
| 319 // DictionaryValue. | |
| 320 bool needs_empty_value = false; | |
| 321 if (orig_type == base::Value::TYPE_LIST) { | |
| 322 const base::ListValue* list = NULL; | |
| 323 if (default_value->GetAsList(&list) && !list->empty()) | |
| 324 needs_empty_value = true; | |
| 325 } else if (orig_type == base::Value::TYPE_DICTIONARY) { | |
| 326 const base::DictionaryValue* dict = NULL; | |
| 327 if (default_value->GetAsDictionary(&dict) && !dict->empty()) | |
| 328 needs_empty_value = true; | |
| 329 } | |
| 330 if (needs_empty_value) | |
| 331 user_pref_store_->MarkNeedsEmptyValue(path); | |
| 332 | |
| 333 // Hand off ownership. | 316 // Hand off ownership. |
| 334 default_store_->SetDefaultValue(path, scoped_value.release()); | 317 default_store_->SetDefaultValue(path, scoped_value.release()); |
| 335 } | 318 } |
| 336 | 319 |
| 337 void PrefService::UnregisterPreference(const char* path) { | 320 void PrefService::UnregisterPreference(const char* path) { |
| 338 DCHECK(CalledOnValidThread()); | 321 DCHECK(CalledOnValidThread()); |
| 339 | 322 |
| 340 PreferenceMap::iterator it = prefs_map_.find(path); | 323 PreferenceMap::iterator it = prefs_map_.find(path); |
| 341 CHECK(it != prefs_map_.end()) << "Trying to unregister an unregistered pref: " | 324 CHECK(it != prefs_map_.end()) << "Trying to unregister an unregistered pref: " |
| 342 << path; | 325 << path; |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 const Value* found_value = NULL; | 550 const Value* found_value = NULL; |
| 568 if (pref_value_store_->GetValue(path, type, &found_value)) { | 551 if (pref_value_store_->GetValue(path, type, &found_value)) { |
| 569 DCHECK(found_value->IsType(type)); | 552 DCHECK(found_value->IsType(type)); |
| 570 return found_value; | 553 return found_value; |
| 571 } | 554 } |
| 572 | 555 |
| 573 // Every registered preference has at least a default value. | 556 // Every registered preference has at least a default value. |
| 574 NOTREACHED() << "no valid value found for registered pref " << path; | 557 NOTREACHED() << "no valid value found for registered pref " << path; |
| 575 return NULL; | 558 return NULL; |
| 576 } | 559 } |
| OLD | NEW |