| 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..be4e37897c4d2f639a875738ce080aaed7636b7f 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"
|
| @@ -115,9 +117,26 @@ PrefService* PrefService::CreatePrefService(const FilePath& pref_filename,
|
| BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
|
| ConfigurationPolicyPrefStore* recommended =
|
| ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore();
|
| + DefaultPrefStore* default_pref_store = new DefaultPrefStore();
|
|
|
| return new PrefService(managed, device_management, extension_prefs,
|
| - command_line, user, recommended, profile);
|
| + command_line, user, recommended, default_pref_store,
|
| + profile, true);
|
| +}
|
| +
|
| +PrefService* PrefService::CreateIncognitoPrefService(
|
| + PrefStore* incognito_extension_prefs) {
|
| + return new PrefService(
|
| + managed_platform_prefs_,
|
| + device_management_prefs_,
|
| + incognito_extension_prefs,
|
| + command_line_prefs_,
|
| + new OverlayPersistentPrefStore(user_pref_store_.get()),
|
| + recommended_prefs_,
|
| + default_store_,
|
| + profile_,
|
| + false
|
| + );
|
| }
|
|
|
| PrefService::PrefService(PrefStore* managed_platform_prefs,
|
| @@ -126,21 +145,30 @@ PrefService::PrefService(PrefStore* managed_platform_prefs,
|
| PrefStore* command_line_prefs,
|
| PersistentPrefStore* user_prefs,
|
| PrefStore* recommended_prefs,
|
| - Profile* profile)
|
| - : user_pref_store_(user_prefs) {
|
| + DefaultPrefStore* default_store,
|
| + Profile* profile,
|
| + bool init_from_storage)
|
| + : managed_platform_prefs_(managed_platform_prefs),
|
| + device_management_prefs_(device_management_prefs),
|
| + extension_prefs_(extension_prefs),
|
| + command_line_prefs_(command_line_prefs),
|
| + recommended_prefs_(recommended_prefs),
|
| + user_pref_store_(user_prefs),
|
| + default_store_(default_store),
|
| + profile_(profile){
|
| pref_notifier_.reset(new PrefNotifierImpl(this));
|
| - default_store_ = new DefaultPrefStore();
|
| pref_value_store_ =
|
| - new PrefValueStore(managed_platform_prefs,
|
| - device_management_prefs,
|
| - extension_prefs,
|
| - command_line_prefs,
|
| + new PrefValueStore(managed_platform_prefs_,
|
| + device_management_prefs_,
|
| + extension_prefs_,
|
| + command_line_prefs_,
|
| user_pref_store_,
|
| - recommended_prefs,
|
| + recommended_prefs_,
|
| default_store_,
|
| pref_notifier_.get(),
|
| - profile);
|
| - InitFromStorage();
|
| + profile_);
|
| + if (init_from_storage)
|
| + InitFromStorage();
|
| }
|
|
|
| PrefService::~PrefService() {
|
| @@ -328,15 +356,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 +385,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 +441,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 +467,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 +609,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 +627,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_;
|
|
|