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 89d7e782b19d7b258f4fbfd761b4b6207d40d8c9..6f98fa4e47caa9f084092b716c87b9c416e56859 100644 |
| --- a/chrome/browser/prefs/pref_service.cc |
| +++ b/chrome/browser/prefs/pref_service.cc |
| @@ -21,9 +21,14 @@ |
| #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/pref_notifier.h" |
| #include "chrome/browser/prefs/pref_value_store.h" |
| #include "chrome/browser/profile.h" |
| +#include "chrome/common/json_pref_store.h" |
| #include "chrome/common/notification_service.h" |
| #include "grit/chromium_strings.h" |
| #include "grit/generated_resources.h" |
| @@ -83,6 +88,8 @@ void NotifyReadError(PrefService* pref, int message_id) { |
| // static |
| PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, |
| Profile* profile) { |
| + using policy::ConfigurationPolicyPrefStore; |
| + |
| #if defined(OS_LINUX) |
| // We'd like to see what fraction of our users have the preferences |
| // stored on a network file system, as we've had no end of troubles |
| @@ -96,19 +103,52 @@ PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, |
| } |
| #endif |
| - return new PrefService( |
| - PrefValueStore::CreatePrefValueStore(pref_filename, profile, false)); |
| + ConfigurationPolicyPrefStore* managed = |
| + ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore(); |
| + ConfigurationPolicyPrefStore* device_management = |
| + ConfigurationPolicyPrefStore::CreateDeviceManagementPolicyPrefStore( |
| + profile); |
| + ExtensionPrefStore* extension = new ExtensionPrefStore(profile); |
| + CommandLinePrefStore* command_line = |
| + new CommandLinePrefStore(CommandLine::ForCurrentProcess()); |
| + JsonPrefStore* user = new JsonPrefStore( |
| + pref_filename, |
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| + ConfigurationPolicyPrefStore* recommended = |
| + ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore(); |
| + |
| + return new PrefService(managed, device_management, extension, command_line, |
| + user, recommended, profile); |
| } |
| // static |
| PrefService* PrefService::CreateUserPrefService(const FilePath& pref_filename) { |
| - return new PrefService( |
| - PrefValueStore::CreatePrefValueStore(pref_filename, NULL, true)); |
| -} |
| - |
| -PrefService::PrefService(PrefValueStore* pref_value_store) |
| - : pref_value_store_(pref_value_store) { |
| - pref_notifier_.reset(new PrefNotifier(this, pref_value_store)); |
| + JsonPrefStore* user = new JsonPrefStore( |
| + pref_filename, |
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
| + |
| + return new PrefService(NULL, NULL, NULL, NULL, user, NULL, NULL); |
| +} |
| + |
| +PrefService::PrefService(PrefStore* managed_platform_prefs, |
| + PrefStore* device_management_prefs, |
| + PrefStore* extension_prefs, |
| + PrefStore* command_line_prefs, |
| + PrefStore* user_prefs, |
| + PrefStore* recommended_prefs, |
| + Profile* profile) { |
| + pref_notifier_.reset(new PrefNotifier(this)); |
| + default_store_ = new DefaultPrefStore(); |
| + pref_value_store_ = |
| + new PrefValueStore(managed_platform_prefs, |
| + device_management_prefs, |
| + extension_prefs, |
| + command_line_prefs, |
| + user_prefs, |
| + recommended_prefs, |
| + default_store_, |
| + pref_notifier_.get(), |
| + profile); |
| InitFromStorage(); |
| } |
| @@ -319,6 +359,14 @@ const PrefService::Preference* PrefService::FindPreference( |
| return it == prefs_.end() ? NULL : *it; |
| } |
| +bool PrefService::ReadOnly() const { |
| + return pref_value_store_->ReadOnly(); |
| +} |
| + |
| +PrefNotifier* PrefService::pref_notifier() const { |
| + return pref_notifier_.get(); |
| +} |
| + |
| bool PrefService::IsManagedPreference(const char* pref_name) const { |
| const Preference* pref = FindPreference(pref_name); |
| if (pref && pref->IsManaged()) { |
| @@ -355,10 +403,6 @@ const ListValue* PrefService::GetList(const char* path) const { |
| return static_cast<const ListValue*>(value); |
| } |
| -bool PrefService::ReadOnly() const { |
| - return pref_value_store_->ReadOnly(); |
| -} |
| - |
| void PrefService::AddPrefObserver(const char* path, |
| NotificationObserver* obs) { |
| pref_notifier_->AddPrefObserver(path, obs); |
| @@ -388,11 +432,11 @@ void PrefService::RegisterPreference(const char* path, Value* default_value) { |
| // 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) { |
| - pref_value_store_->SetDefaultPrefValue(path, Value::CreateNullValue()); |
| + default_store_->prefs()->Set(path, Value::CreateNullValue()); |
| } else { |
| // Hand off ownership. |
| DCHECK(!PrefStore::IsUseDefaultSentinelValue(default_value)); |
| - pref_value_store_->SetDefaultPrefValue(path, scoped_value.release()); |
| + default_store_->prefs()->Set(path, scoped_value.release()); |
| } |
| pref_value_store_->RegisterPreferenceType(path, orig_type); |
| @@ -407,8 +451,7 @@ void PrefService::ClearPref(const char* path) { |
| NOTREACHED() << "Trying to clear an unregistered pref: " << path; |
| return; |
| } |
| - if (pref_value_store_->RemoveUserPrefValue(path)) |
| - pref_notifier_->OnUserPreferenceSet(path); |
| + pref_value_store_->RemoveUserPrefValue(path); |
| } |
| void PrefService::Set(const char* path, const Value& value) { |
| @@ -422,21 +465,17 @@ void PrefService::Set(const char* path, const Value& value) { |
| // Allow dictionary and list types to be set to null, which removes their |
| // user values. |
| - bool value_changed = false; |
| if (value.GetType() == Value::TYPE_NULL && |
| (pref->GetType() == Value::TYPE_DICTIONARY || |
| pref->GetType() == Value::TYPE_LIST)) { |
| - value_changed = pref_value_store_->RemoveUserPrefValue(path); |
| + pref_value_store_->RemoveUserPrefValue(path); |
| } else if (pref->GetType() != value.GetType()) { |
| NOTREACHED() << "Trying to set pref " << path |
| << " of type " << pref->GetType() |
| << " to value of type " << value.GetType(); |
| } else { |
| - value_changed = pref_value_store_->SetUserPrefValue(path, value.DeepCopy()); |
| + pref_value_store_->SetUserPrefValue(path, value.DeepCopy()); |
| } |
| - |
| - if (value_changed) |
| - pref_notifier_->OnUserPreferenceSet(path); |
| } |
| void PrefService::SetBoolean(const char* path, bool value) { |
| @@ -514,7 +553,7 @@ DictionaryValue* PrefService::GetMutableDictionary(const char* path) { |
| if (!pref_value_store_->GetUserValue(path, &tmp_value) || |
| !tmp_value->IsType(Value::TYPE_DICTIONARY)) { |
| dict = new DictionaryValue; |
| - pref_value_store_->SetUserPrefValue(path, dict); |
| + pref_value_store_->PutUserPrefValue(path, dict); |
|
danno
2010/12/02 10:31:52
Call this SetUserPrefValueWithoutNotification/Sile
Mattias Nissler (ping if slow)
2010/12/02 16:38:24
Done.
|
| } else { |
| dict = static_cast<DictionaryValue*>(tmp_value); |
| } |
| @@ -541,7 +580,7 @@ ListValue* PrefService::GetMutableList(const char* path) { |
| if (!pref_value_store_->GetUserValue(path, &tmp_value) || |
| !tmp_value->IsType(Value::TYPE_LIST)) { |
| list = new ListValue; |
| - pref_value_store_->SetUserPrefValue(path, list); |
| + pref_value_store_->PutUserPrefValue(path, list); |
| } else { |
| list = static_cast<ListValue*>(tmp_value); |
| } |
| @@ -575,8 +614,7 @@ void PrefService::SetUserPrefValue(const char* path, Value* new_value) { |
| return; |
| } |
| - if (pref_value_store_->SetUserPrefValue(path, new_value)) |
| - pref_notifier_->OnUserPreferenceSet(path); |
| + pref_value_store_->SetUserPrefValue(path, new_value); |
| } |
| /////////////////////////////////////////////////////////////////////////////// |