| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 base::Callback<void(PersistentPrefStore::PrefReadError)> | 46 base::Callback<void(PersistentPrefStore::PrefReadError)> |
| 47 read_error_callback, | 47 read_error_callback, |
| 48 bool async) | 48 bool async) |
| 49 : pref_notifier_(pref_notifier), | 49 : pref_notifier_(pref_notifier), |
| 50 pref_value_store_(pref_value_store), | 50 pref_value_store_(pref_value_store), |
| 51 pref_registry_(pref_registry), | 51 pref_registry_(pref_registry), |
| 52 user_pref_store_(user_prefs), | 52 user_pref_store_(user_prefs), |
| 53 read_error_callback_(read_error_callback) { | 53 read_error_callback_(read_error_callback) { |
| 54 pref_notifier_->SetPrefService(this); | 54 pref_notifier_->SetPrefService(this); |
| 55 | 55 |
| 56 // TODO(battre): This is a check for crbug.com/435208 to make sure that |
| 57 // access violations are caused by a use-after-free bug and not by an |
| 58 // initialization bug. |
| 59 CHECK(pref_registry_); |
| 60 CHECK(pref_value_store_); |
| 61 |
| 56 InitFromStorage(async); | 62 InitFromStorage(async); |
| 57 } | 63 } |
| 58 | 64 |
| 59 PrefService::~PrefService() { | 65 PrefService::~PrefService() { |
| 60 DCHECK(CalledOnValidThread()); | 66 DCHECK(CalledOnValidThread()); |
| 61 | 67 |
| 62 // Reset pointers so accesses after destruction reliably crash. | 68 // Reset pointers so accesses after destruction reliably crash. |
| 63 pref_value_store_.reset(); | 69 pref_value_store_.reset(); |
| 64 pref_registry_ = NULL; | 70 pref_registry_ = NULL; |
| 65 user_pref_store_ = NULL; | 71 user_pref_store_ = NULL; |
| (...skipping 489 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 return pref_value_store()->PrefValueUserModifiable(name_); | 561 return pref_value_store()->PrefValueUserModifiable(name_); |
| 556 } | 562 } |
| 557 | 563 |
| 558 bool PrefService::Preference::IsExtensionModifiable() const { | 564 bool PrefService::Preference::IsExtensionModifiable() const { |
| 559 return pref_value_store()->PrefValueExtensionModifiable(name_); | 565 return pref_value_store()->PrefValueExtensionModifiable(name_); |
| 560 } | 566 } |
| 561 | 567 |
| 562 const base::Value* PrefService::GetPreferenceValue( | 568 const base::Value* PrefService::GetPreferenceValue( |
| 563 const std::string& path) const { | 569 const std::string& path) const { |
| 564 DCHECK(CalledOnValidThread()); | 570 DCHECK(CalledOnValidThread()); |
| 571 |
| 572 // TODO(battre): This is a check for crbug.com/435208. After analyzing some |
| 573 // crash dumps it looks like the PrefService is accessed even though it has |
| 574 // been cleared already. |
| 575 CHECK(pref_registry_); |
| 576 CHECK(pref_registry_->defaults()); |
| 577 CHECK(pref_value_store_); |
| 578 |
| 565 const base::Value* default_value = NULL; | 579 const base::Value* default_value = NULL; |
| 566 if (pref_registry_->defaults()->GetValue(path, &default_value)) { | 580 if (pref_registry_->defaults()->GetValue(path, &default_value)) { |
| 567 const base::Value* found_value = NULL; | 581 const base::Value* found_value = NULL; |
| 568 base::Value::Type default_type = default_value->GetType(); | 582 base::Value::Type default_type = default_value->GetType(); |
| 569 if (pref_value_store_->GetValue(path, default_type, &found_value)) { | 583 if (pref_value_store_->GetValue(path, default_type, &found_value)) { |
| 570 DCHECK(found_value->IsType(default_type)); | 584 DCHECK(found_value->IsType(default_type)); |
| 571 return found_value; | 585 return found_value; |
| 572 } else { | 586 } else { |
| 573 // Every registered preference has at least a default value. | 587 // Every registered preference has at least a default value. |
| 574 NOTREACHED() << "no valid value found for registered pref " << path; | 588 NOTREACHED() << "no valid value found for registered pref " << path; |
| 575 } | 589 } |
| 576 } | 590 } |
| 577 | 591 |
| 578 return NULL; | 592 return NULL; |
| 579 } | 593 } |
| OLD | NEW |