Index: chrome/browser/prefs/pref_value_store.cc |
diff --git a/chrome/browser/prefs/pref_value_store.cc b/chrome/browser/prefs/pref_value_store.cc |
index 3ad6c44f009bc614e641d271d666f9f7e0237c9f..54bf81ba02c0f2f4f7aaaf6ecdbda7aee6b5637a 100644 |
--- a/chrome/browser/prefs/pref_value_store.cc |
+++ b/chrome/browser/prefs/pref_value_store.cc |
@@ -27,7 +27,7 @@ void PrefValueStore::PrefStoreKeeper::Initialize( |
pref_store_->RemoveObserver(this); |
type_ = type; |
pref_value_store_ = store; |
- pref_store_.reset(pref_store); |
+ pref_store_ = pref_store; |
if (pref_store_.get()) |
pref_store_->AddObserver(this); |
} |
@@ -71,48 +71,31 @@ PrefValueStore::PrefValueStore(PrefStore* managed_platform_prefs, |
PrefValueStore::~PrefValueStore() {} |
bool PrefValueStore::GetValue(const std::string& name, |
+ Value::ValueType type, |
Value** out_value) const { |
+ *out_value = NULL; |
// Check the |PrefStore|s in order of their priority from highest to lowest |
// to find the value of the preference described by the given preference name. |
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { |
if (GetValueFromStore(name.c_str(), static_cast<PrefStoreType>(i), |
- out_value)) |
+ out_value)) { |
+ if (!(*out_value)->IsType(type)) { |
+ LOG(WARNING) << "Expected type for " << name << " is " << type |
+ << " but got " << (*out_value)->GetType() |
+ << " in store " << i; |
+ continue; |
+ } |
return true; |
+ } |
} |
return false; |
} |
-void PrefValueStore::RegisterPreferenceType(const std::string& name, |
- Value::ValueType type) { |
- pref_types_[name] = type; |
-} |
- |
-Value::ValueType PrefValueStore::GetRegisteredType( |
- const std::string& name) const { |
- PrefTypeMap::const_iterator found = pref_types_.find(name); |
- if (found == pref_types_.end()) |
- return Value::TYPE_NULL; |
- return found->second; |
-} |
- |
-bool PrefValueStore::HasPrefPath(const char* path) const { |
- Value* tmp_value = NULL; |
- const std::string name(path); |
- bool rv = GetValue(name, &tmp_value); |
- // Merely registering a pref doesn't count as "having" it: we require a |
- // non-default value set. |
- return rv && !PrefValueFromDefaultStore(path); |
-} |
- |
void PrefValueStore::NotifyPrefChanged( |
const char* path, |
PrefValueStore::PrefStoreType new_store) { |
DCHECK(new_store != INVALID_STORE); |
- // If this pref is not registered, just discard the notification. |
- if (!pref_types_.count(path)) |
- return; |
- |
bool changed = true; |
// Replying that the pref has changed in case the new store is invalid may |
// cause problems, but it's the safer choice. |
@@ -165,24 +148,6 @@ bool PrefValueStore::PrefValueUserModifiable(const char* name) const { |
effective_store == INVALID_STORE; |
} |
-// Returns true if the actual value is a valid type for the expected type when |
-// found in the given store. |
-bool PrefValueStore::IsValidType(Value::ValueType expected, |
- Value::ValueType actual, |
- PrefValueStore::PrefStoreType store) { |
- if (expected == actual) |
- return true; |
- |
- // Dictionaries and lists are allowed to hold TYPE_NULL values too, but only |
- // in the default pref store. |
- if (store == DEFAULT_STORE && |
- actual == Value::TYPE_NULL && |
- (expected == Value::TYPE_DICTIONARY || expected == Value::TYPE_LIST)) { |
- return true; |
- } |
- return false; |
-} |
- |
bool PrefValueStore::PrefValueInStore( |
const char* name, |
PrefValueStore::PrefStoreType store) const { |
@@ -234,12 +199,7 @@ bool PrefValueStore::GetValueFromStore(const char* name, |
} |
// Fall through... |
case PrefStore::READ_OK: |
- if (IsValidType(GetRegisteredType(name), |
- (*out_value)->GetType(), |
- store_type)) { |
- return true; |
- } |
- break; |
+ return true; |
case PrefStore::READ_NO_VALUE: |
break; |
} |
@@ -252,24 +212,21 @@ bool PrefValueStore::GetValueFromStore(const char* name, |
void PrefValueStore::RefreshPolicyPrefsOnFileThread( |
BrowserThread::ID calling_thread_id, |
- policy::ConfigurationPolicyPrefStore* new_managed_platform_pref_store, |
- policy::ConfigurationPolicyPrefStore* new_device_management_pref_store, |
- policy::ConfigurationPolicyPrefStore* new_recommended_pref_store) { |
+ scoped_refptr<policy::ConfigurationPolicyPrefStore> |
+ managed_platform_pref_store, |
+ scoped_refptr<policy::ConfigurationPolicyPrefStore> |
+ device_management_pref_store, |
+ scoped_refptr<policy::ConfigurationPolicyPrefStore> |
+ recommended_pref_store) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
- scoped_ptr<policy::ConfigurationPolicyPrefStore> managed_platform_pref_store( |
- new_managed_platform_pref_store); |
- scoped_ptr<policy::ConfigurationPolicyPrefStore> device_management_pref_store( |
- new_device_management_pref_store); |
- scoped_ptr<policy::ConfigurationPolicyPrefStore> recommended_pref_store( |
- new_recommended_pref_store); |
BrowserThread::PostTask( |
calling_thread_id, FROM_HERE, |
NewRunnableMethod(this, |
&PrefValueStore::RefreshPolicyPrefsCompletion, |
- managed_platform_pref_store.release(), |
- device_management_pref_store.release(), |
- recommended_pref_store.release())); |
+ managed_platform_pref_store, |
+ device_management_pref_store, |
+ recommended_pref_store)); |
} |
void PrefValueStore::RefreshPolicyPrefs() { |
@@ -295,9 +252,9 @@ void PrefValueStore::RefreshPolicyPrefs() { |
NewRunnableMethod(this, |
&PrefValueStore::RefreshPolicyPrefsOnFileThread, |
current_thread_id, |
- new_managed_platform_pref_store, |
- new_device_management_pref_store, |
- new_recommended_pref_store)); |
+ make_scoped_refptr(new_managed_platform_pref_store), |
+ make_scoped_refptr(new_device_management_pref_store), |
+ make_scoped_refptr(new_recommended_pref_store))); |
} |
void PrefValueStore::RefreshPolicyPrefsCompletion( |
@@ -403,7 +360,8 @@ void PrefValueStore::InitPrefStore(PrefValueStore::PrefStoreType type, |
void PrefValueStore::CheckInitializationCompleted() { |
for (size_t i = 0; i <= PREF_STORE_TYPE_MAX; ++i) { |
- PrefStore* store = GetPrefStore(static_cast<PrefStoreType>(i)); |
+ scoped_refptr<PrefStore> store = |
+ GetPrefStore(static_cast<PrefStoreType>(i)); |
if (store && !store->IsInitializationComplete()) |
return; |
} |