Chromium Code Reviews| Index: chrome/browser/prefs/pref_service.cc |
| diff --git a/chrome/browser/prefs/pref_service.cc b/chrome/browser/prefs/pref_service.cc |
| index 4a3110c5c801990e3b5a76d547a588a2cfa62885..6f87b8983872e3da37984eb465d04cc15aa82acd 100644 |
| --- a/chrome/browser/prefs/pref_service.cc |
| +++ b/chrome/browser/prefs/pref_service.cc |
| @@ -21,9 +21,11 @@ |
| #include "base/utf_string_conversions.h" |
| #include "build/build_config.h" |
| #include "chrome/browser/browser_thread.h" |
| +#include "chrome/browser/extensions/extension_pref_store.h" |
| #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| #include "chrome/browser/prefs/command_line_pref_store.h" |
| #include "chrome/browser/prefs/default_pref_store.h" |
| +#include "chrome/browser/prefs/overlay_persistent_pref_store.h" |
| #include "chrome/browser/prefs/pref_notifier_impl.h" |
| #include "chrome/browser/prefs/pref_value_store.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -85,9 +87,10 @@ void NotifyReadError(PrefService* pref, int message_id) { |
| } // namespace |
| // static |
| -PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, |
| - PrefStore* extension_prefs, |
| - Profile* profile) { |
| +PrefService* PrefService::CreatePrefService( |
| + const FilePath& pref_filename, |
| + scoped_refptr<PrefStore> extension_prefs, |
| + Profile* profile) { |
| using policy::ConfigurationPolicyPrefStore; |
| #if defined(OS_LINUX) |
| @@ -103,29 +106,52 @@ PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, |
| } |
| #endif |
| - ConfigurationPolicyPrefStore* managed = |
| + scoped_refptr<ConfigurationPolicyPrefStore> managed = |
|
Mattias Nissler (ping if slow)
2010/12/20 14:50:02
scoped_refptr construction not needed here either.
battre
2010/12/21 18:51:59
Done.
|
| ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore(); |
| - ConfigurationPolicyPrefStore* device_management = |
| + scoped_refptr<ConfigurationPolicyPrefStore> device_management = |
| ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( |
| profile); |
| - CommandLinePrefStore* command_line = |
| + scoped_refptr<CommandLinePrefStore> command_line = |
| new CommandLinePrefStore(CommandLine::ForCurrentProcess()); |
| - JsonPrefStore* user = new JsonPrefStore( |
| + scoped_refptr<JsonPrefStore> user = new JsonPrefStore( |
| pref_filename, |
| BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| - ConfigurationPolicyPrefStore* recommended = |
| + scoped_refptr<ConfigurationPolicyPrefStore> recommended = |
| ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); |
| return new PrefService(managed, device_management, extension_prefs, |
| command_line, user, recommended, profile); |
| } |
| -PrefService::PrefService(PrefStore* managed_platform_prefs, |
| - PrefStore* device_management_prefs, |
| - PrefStore* extension_prefs, |
| - PrefStore* command_line_prefs, |
| - PersistentPrefStore* user_prefs, |
| - PrefStore* recommended_prefs, |
| +PrefService* PrefService::CreateIncognitoPrefService( |
| + scoped_refptr<PrefStore> incognito_extension_prefs) { |
| + return new PrefService(pref_value_store_, |
| + user_pref_store_, |
| + incognito_extension_prefs, |
| + default_store_); |
| +} |
| + |
| +PrefService::PrefService(PrefValueStore* old_pref_value_store, |
| + scoped_refptr<PersistentPrefStore> old_user_pref_store, |
| + scoped_refptr<PrefStore> incognito_extension_prefs, |
| + scoped_refptr<DefaultPrefStore> default_store) |
| + : user_pref_store_(new OverlayPersistentPrefStore(old_user_pref_store)), |
| + default_store_(default_store) { |
| + pref_notifier_.reset(new PrefNotifierImpl(this)); |
| + pref_value_store_ = |
| + old_pref_value_store->Derive(incognito_extension_prefs, |
| + user_pref_store_, |
| + pref_notifier_.get()); |
| + // We do not call InitFromStorage() here intentionally, as we do not read |
| + // the user prefs from disk. |
| +} |
| + |
| +PrefService::PrefService(scoped_refptr<PrefStore> managed_platform_prefs, |
| + scoped_refptr<PrefStore> device_management_prefs, |
| + scoped_refptr<PrefStore> extension_prefs, |
| + scoped_refptr<PrefStore> command_line_prefs, |
| + scoped_refptr<PersistentPrefStore> user_prefs, |
| + scoped_refptr<PrefStore> recommended_prefs, |
| Profile* profile) |
| : user_pref_store_(user_prefs) { |
| pref_notifier_.reset(new PrefNotifierImpl(this)); |
| @@ -328,15 +354,23 @@ FilePath PrefService::GetFilePath(const char* path) const { |
| } |
| bool PrefService::HasPrefPath(const char* path) const { |
| - return pref_value_store_->HasPrefPath(path); |
| + const Preference* pref = FindPreference(path); |
| + return pref && !pref->IsDefaultValue(); |
| } |
| const PrefService::Preference* PrefService::FindPreference( |
| const char* pref_name) const { |
| DCHECK(CalledOnValidThread()); |
| - Preference p(this, pref_name); |
| + Preference p(this, pref_name, Value::TYPE_NULL); |
| PreferenceSet::const_iterator it = prefs_.find(&p); |
| - return it == prefs_.end() ? NULL : *it; |
| + if (it != prefs_.end()) |
| + return *it; |
| + const Value::ValueType type = default_store_->GetType(pref_name); |
| + if (type == Value::TYPE_NULL) |
| + return NULL; |
| + Preference* new_pref = new Preference(this, pref_name, type); |
| + prefs_.insert(new_pref); |
| + return new_pref; |
| } |
| bool PrefService::ReadOnly() const { |
| @@ -349,10 +383,7 @@ PrefNotifier* PrefService::pref_notifier() const { |
| bool PrefService::IsManagedPreference(const char* pref_name) const { |
| const Preference* pref = FindPreference(pref_name); |
| - if (pref && pref->IsManaged()) { |
| - return true; |
| - } |
| - return false; |
| + return pref && pref->IsManaged(); |
| } |
| const DictionaryValue* PrefService::GetDictionary(const char* path) const { |
| @@ -408,18 +439,10 @@ void PrefService::RegisterPreference(const char* path, Value* default_value) { |
| DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << |
| "invalid preference type: " << orig_type; |
| - // We set the default value of dictionaries and lists to be null so it's |
| - // easier for callers to check for empty dict/list prefs. The PrefValueStore |
| - // accepts ownership of the value (null or default_value). |
| - if (Value::TYPE_LIST == orig_type || Value::TYPE_DICTIONARY == orig_type) { |
| - default_store_->SetDefaultValue(path, Value::CreateNullValue()); |
| - } else { |
| - // Hand off ownership. |
| - default_store_->SetDefaultValue(path, scoped_value.release()); |
| - } |
| + // Hand off ownership. |
| + default_store_->SetDefaultValue(path, scoped_value.release()); |
| - pref_value_store_->RegisterPreferenceType(path, orig_type); |
| - prefs_.insert(new Preference(this, path)); |
| + prefs_.insert(new Preference(this, path, orig_type)); |
| } |
| void PrefService::ClearPref(const char* path) { |
| @@ -442,13 +465,7 @@ void PrefService::Set(const char* path, const Value& value) { |
| return; |
| } |
| - // Allow dictionary and list types to be set to null, which removes their |
| - // user values. |
| - if (value.GetType() == Value::TYPE_NULL && |
| - (pref->GetType() == Value::TYPE_DICTIONARY || |
| - pref->GetType() == Value::TYPE_LIST)) { |
| - user_pref_store_->RemoveValue(path); |
| - } else if (pref->GetType() != value.GetType()) { |
| + if (pref->GetType() != value.GetType()) { |
| NOTREACHED() << "Trying to set pref " << path |
| << " of type " << pref->GetType() |
| << " to value of type " << value.GetType(); |
| @@ -590,15 +607,17 @@ void PrefService::SetUserPrefValue(const char* path, Value* new_value) { |
| // PrefService::Preference |
| PrefService::Preference::Preference(const PrefService* service, |
| - const char* name) |
| + const char* name, |
| + Value::ValueType type) |
| : name_(name), |
| + type_(type), |
| pref_service_(service) { |
| DCHECK(name); |
| DCHECK(service); |
| } |
| Value::ValueType PrefService::Preference::GetType() const { |
| - return pref_service_->pref_value_store_->GetRegisteredType(name_); |
| + return type_; |
| } |
| const Value* PrefService::Preference::GetValue() const { |
| @@ -606,8 +625,10 @@ const Value* PrefService::Preference::GetValue() const { |
| "Must register pref before getting its value"; |
| Value* found_value = NULL; |
| - if (pref_service_->pref_value_store_->GetValue(name_, &found_value)) |
| + if (pref_service_->pref_value_store_->GetValue(name_, type_, &found_value)) { |
| + DCHECK(found_value->IsType(type_)); |
| return found_value; |
| + } |
| // Every registered preference has at least a default value. |
| NOTREACHED() << "no valid value found for registered pref " << name_; |