| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/prefs/pref_service.h" | 5 #include "chrome/browser/prefs/pref_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/extensions/extension_pref_store.h" | 21 #include "chrome/browser/extensions/extension_pref_store.h" |
| 22 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 22 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 23 #include "chrome/browser/prefs/command_line_pref_store.h" | 23 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 24 #include "chrome/browser/prefs/default_pref_store.h" | 24 #include "chrome/browser/prefs/default_pref_store.h" |
| 25 #include "chrome/browser/prefs/overlay_persistent_pref_store.h" | 25 #include "chrome/browser/prefs/overlay_persistent_pref_store.h" |
| 26 #include "chrome/browser/prefs/pref_notifier_impl.h" | 26 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| 27 #include "chrome/browser/prefs/pref_value_store.h" | 27 #include "chrome/browser/prefs/pref_value_store.h" |
| 28 #include "chrome/common/json_pref_store.h" | 28 #include "chrome/common/json_pref_store.h" |
| 29 #include "content/browser/browser_thread.h" | 29 #include "content/browser/browser_thread.h" |
| 30 #include "content/common/notification_service.h" | 30 #include "content/common/notification_service.h" |
| 31 #include "content/common/notification_source.h" |
| 31 #include "grit/chromium_strings.h" | 32 #include "grit/chromium_strings.h" |
| 32 #include "grit/generated_resources.h" | 33 #include "grit/generated_resources.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 | 35 |
| 35 namespace { | 36 namespace { |
| 36 | 37 |
| 37 // A helper function for RegisterLocalized*Pref that creates a Value* based on | 38 // A helper function for RegisterLocalized*Pref that creates a Value* based on |
| 38 // the string value in the locale dll. Because we control the values in a | 39 // the string value in the locale dll. Because we control the values in a |
| 39 // locale dll, this should always return a Value of the appropriate type. | 40 // locale dll, this should always return a Value of the appropriate type. |
| 40 Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) { | 41 Value* CreateLocaleDefaultValue(Value::ValueType type, int message_id) { |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 PrefService::PrefService(PrefStore* managed_platform_prefs, | 133 PrefService::PrefService(PrefStore* managed_platform_prefs, |
| 133 PrefStore* managed_cloud_prefs, | 134 PrefStore* managed_cloud_prefs, |
| 134 PrefStore* extension_prefs, | 135 PrefStore* extension_prefs, |
| 135 PrefStore* command_line_prefs, | 136 PrefStore* command_line_prefs, |
| 136 PersistentPrefStore* user_prefs, | 137 PersistentPrefStore* user_prefs, |
| 137 PrefStore* recommended_platform_prefs, | 138 PrefStore* recommended_platform_prefs, |
| 138 PrefStore* recommended_cloud_prefs, | 139 PrefStore* recommended_cloud_prefs, |
| 139 DefaultPrefStore* default_store) | 140 DefaultPrefStore* default_store) |
| 140 : user_pref_store_(user_prefs), | 141 : user_pref_store_(user_prefs), |
| 141 default_store_(default_store) { | 142 default_store_(default_store) { |
| 143 user_pref_store_->SetNotificationSource(Source<PrefService>(this)); |
| 142 pref_notifier_.reset(new PrefNotifierImpl(this)); | 144 pref_notifier_.reset(new PrefNotifierImpl(this)); |
| 143 pref_value_store_.reset( | 145 pref_value_store_.reset( |
| 144 new PrefValueStore(managed_platform_prefs, | 146 new PrefValueStore(managed_platform_prefs, |
| 145 managed_cloud_prefs, | 147 managed_cloud_prefs, |
| 146 extension_prefs, | 148 extension_prefs, |
| 147 command_line_prefs, | 149 command_line_prefs, |
| 148 user_pref_store_, | 150 user_pref_store_, |
| 149 recommended_platform_prefs, | 151 recommended_platform_prefs, |
| 150 recommended_cloud_prefs, | 152 recommended_cloud_prefs, |
| 151 default_store, | 153 default_store, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, 20); | 208 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, 20); |
| 207 } | 209 } |
| 208 | 210 |
| 209 bool PrefService::ReloadPersistentPrefs() { | 211 bool PrefService::ReloadPersistentPrefs() { |
| 210 return user_pref_store_->ReadPrefs() == | 212 return user_pref_store_->ReadPrefs() == |
| 211 PersistentPrefStore::PREF_READ_ERROR_NONE; | 213 PersistentPrefStore::PREF_READ_ERROR_NONE; |
| 212 } | 214 } |
| 213 | 215 |
| 214 bool PrefService::SavePersistentPrefs() { | 216 bool PrefService::SavePersistentPrefs() { |
| 215 DCHECK(CalledOnValidThread()); | 217 DCHECK(CalledOnValidThread()); |
| 216 | |
| 217 return user_pref_store_->WritePrefs(); | 218 return user_pref_store_->WritePrefs(); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void PrefService::ScheduleSavePersistentPrefs() { | 221 void PrefService::ScheduleSavePersistentPrefs() { |
| 221 DCHECK(CalledOnValidThread()); | 222 DCHECK(CalledOnValidThread()); |
| 223 user_pref_store_->ScheduleWritePrefs(); |
| 224 } |
| 222 | 225 |
| 223 user_pref_store_->ScheduleWritePrefs(); | 226 void PrefService::CommitPendingWrite() { |
| 227 DCHECK(CalledOnValidThread()); |
| 228 user_pref_store_->CommitPendingWrite(); |
| 224 } | 229 } |
| 225 | 230 |
| 226 void PrefService::RegisterBooleanPref(const char* path, | 231 void PrefService::RegisterBooleanPref(const char* path, |
| 227 bool default_value) { | 232 bool default_value) { |
| 228 RegisterPreference(path, Value::CreateBooleanValue(default_value)); | 233 RegisterPreference(path, Value::CreateBooleanValue(default_value)); |
| 229 } | 234 } |
| 230 | 235 |
| 231 void PrefService::RegisterIntegerPref(const char* path, int default_value) { | 236 void PrefService::RegisterIntegerPref(const char* path, int default_value) { |
| 232 RegisterPreference(path, Value::CreateIntegerValue(default_value)); | 237 RegisterPreference(path, Value::CreateIntegerValue(default_value)); |
| 233 } | 238 } |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 689 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 694 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 690 } | 695 } |
| 691 | 696 |
| 692 bool PrefService::Preference::IsUserModifiable() const { | 697 bool PrefService::Preference::IsUserModifiable() const { |
| 693 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 698 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 694 } | 699 } |
| 695 | 700 |
| 696 bool PrefService::Preference::IsExtensionModifiable() const { | 701 bool PrefService::Preference::IsExtensionModifiable() const { |
| 697 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 702 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 698 } | 703 } |
| OLD | NEW |