| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 10 #include "base/bind.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 pref_sync_associator, | 173 pref_sync_associator, |
| 174 pref_notifier), | 174 pref_notifier), |
| 175 user, | 175 user, |
| 176 default_pref_store, | 176 default_pref_store, |
| 177 pref_sync_associator, | 177 pref_sync_associator, |
| 178 async); | 178 async); |
| 179 } | 179 } |
| 180 | 180 |
| 181 PrefService* PrefService::CreateIncognitoPrefService( | 181 PrefService* PrefService::CreateIncognitoPrefService( |
| 182 PrefStore* incognito_extension_prefs) { | 182 PrefStore* incognito_extension_prefs) { |
| 183 pref_service_forked_ = true; |
| 183 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); | 184 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
| 184 OverlayUserPrefStore* incognito_pref_store = | 185 OverlayUserPrefStore* incognito_pref_store = |
| 185 new OverlayUserPrefStore(user_pref_store_.get()); | 186 new OverlayUserPrefStore(user_pref_store_.get()); |
| 186 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store); | 187 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store); |
| 187 return new PrefService( | 188 return new PrefService( |
| 188 pref_notifier, | 189 pref_notifier, |
| 189 pref_value_store_->CloneAndSpecialize( | 190 pref_value_store_->CloneAndSpecialize( |
| 190 NULL, // managed_platform_prefs | 191 NULL, // managed_platform_prefs |
| 191 NULL, // managed_cloud_prefs | 192 NULL, // managed_cloud_prefs |
| 192 incognito_extension_prefs, | 193 incognito_extension_prefs, |
| 193 NULL, // command_line_prefs | 194 NULL, // command_line_prefs |
| 194 incognito_pref_store, | 195 incognito_pref_store, |
| 195 NULL, // recommended_platform_prefs | 196 NULL, // recommended_platform_prefs |
| 196 NULL, // recommended_cloud_prefs | 197 NULL, // recommended_cloud_prefs |
| 197 default_store_.get(), | 198 default_store_.get(), |
| 198 NULL, // pref_sync_associator | 199 NULL, // pref_sync_associator |
| 199 pref_notifier), | 200 pref_notifier), |
| 200 incognito_pref_store, | 201 incognito_pref_store, |
| 201 default_store_.get(), | 202 default_store_.get(), |
| 202 NULL, | 203 NULL, |
| 203 false); | 204 false); |
| 204 } | 205 } |
| 205 | 206 |
| 206 PrefService* PrefService::CreatePrefServiceWithPerTabPrefStore() { | 207 PrefService* PrefService::CreatePrefServiceWithPerTabPrefStore() { |
| 208 pref_service_forked_ = true; |
| 207 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); | 209 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
| 208 OverlayUserPrefStore* per_tab_pref_store = | 210 OverlayUserPrefStore* per_tab_pref_store = |
| 209 new OverlayUserPrefStore(user_pref_store_.get()); | 211 new OverlayUserPrefStore(user_pref_store_.get()); |
| 210 PrefsTabHelper::InitPerTabUserPrefStore(per_tab_pref_store); | 212 PrefsTabHelper::InitPerTabUserPrefStore(per_tab_pref_store); |
| 211 DefaultPrefStore* default_store = new DefaultPrefStore(); | 213 DefaultPrefStore* default_store = new DefaultPrefStore(); |
| 212 return new PrefService( | 214 return new PrefService( |
| 213 pref_notifier, | 215 pref_notifier, |
| 214 pref_value_store_->CloneAndSpecialize( | 216 pref_value_store_->CloneAndSpecialize( |
| 215 NULL, // managed_platform_prefs | 217 NULL, // managed_platform_prefs |
| 216 NULL, // managed_cloud_prefs | 218 NULL, // managed_cloud_prefs |
| 217 NULL, // extension_prefs | 219 NULL, // extension_prefs |
| 218 NULL, // command_line_prefs | 220 NULL, // command_line_prefs |
| 219 per_tab_pref_store, | 221 per_tab_pref_store, |
| 220 NULL, // recommended_platform_prefs | 222 NULL, // recommended_platform_prefs |
| 221 NULL, // recommended_cloud_prefs | 223 NULL, // recommended_cloud_prefs |
| 222 default_store, | 224 default_store, |
| 223 NULL, | 225 NULL, |
| 224 pref_notifier), | 226 pref_notifier), |
| 225 per_tab_pref_store, | 227 per_tab_pref_store, |
| 226 default_store, | 228 default_store, |
| 227 NULL, | 229 NULL, |
| 228 false); | 230 false); |
| 229 } | 231 } |
| 230 | 232 |
| 231 PrefService::PrefService(PrefNotifierImpl* pref_notifier, | 233 PrefService::PrefService(PrefNotifierImpl* pref_notifier, |
| 232 PrefValueStore* pref_value_store, | 234 PrefValueStore* pref_value_store, |
| 233 PersistentPrefStore* user_prefs, | 235 PersistentPrefStore* user_prefs, |
| 234 DefaultPrefStore* default_store, | 236 DefaultPrefStore* default_store, |
| 235 PrefModelAssociator* pref_sync_associator, | 237 PrefModelAssociator* pref_sync_associator, |
| 236 bool async) | 238 bool async) |
| 237 : pref_notifier_(pref_notifier), | 239 : pref_notifier_(pref_notifier), |
| 238 pref_value_store_(pref_value_store), | 240 pref_value_store_(pref_value_store), |
| 239 user_pref_store_(user_prefs), | 241 user_pref_store_(user_prefs), |
| 240 default_store_(default_store), | 242 default_store_(default_store), |
| 241 pref_sync_associator_(pref_sync_associator) { | 243 pref_sync_associator_(pref_sync_associator), |
| 244 pref_service_forked_(false) { |
| 242 pref_notifier_->SetPrefService(this); | 245 pref_notifier_->SetPrefService(this); |
| 243 if (pref_sync_associator_.get()) | 246 if (pref_sync_associator_.get()) |
| 244 pref_sync_associator_->SetPrefService(this); | 247 pref_sync_associator_->SetPrefService(this); |
| 245 InitFromStorage(async); | 248 InitFromStorage(async); |
| 246 } | 249 } |
| 247 | 250 |
| 248 PrefService::~PrefService() { | 251 PrefService::~PrefService() { |
| 249 DCHECK(CalledOnValidThread()); | 252 DCHECK(CalledOnValidThread()); |
| 250 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); | 253 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); |
| 251 prefs_.clear(); | 254 prefs_.clear(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 277 } | 280 } |
| 278 | 281 |
| 279 void PrefService::CommitPendingWrite() { | 282 void PrefService::CommitPendingWrite() { |
| 280 DCHECK(CalledOnValidThread()); | 283 DCHECK(CalledOnValidThread()); |
| 281 user_pref_store_->CommitPendingWrite(); | 284 user_pref_store_->CommitPendingWrite(); |
| 282 } | 285 } |
| 283 | 286 |
| 284 namespace { | 287 namespace { |
| 285 | 288 |
| 286 // If there's no g_browser_process or no local state, return true (for testing). | 289 // If there's no g_browser_process or no local state, return true (for testing). |
| 287 bool IsLocalStatePrefService(PrefService* prefs){ | 290 bool IsLocalStatePrefService(PrefService* prefs) { |
| 288 return (!g_browser_process || | 291 return (!g_browser_process || |
| 289 !g_browser_process->local_state() || | 292 !g_browser_process->local_state() || |
| 290 g_browser_process->local_state() == prefs); | 293 g_browser_process->local_state() == prefs); |
| 291 } | 294 } |
| 292 | 295 |
| 293 // If there's no g_browser_process, return true (for testing). | 296 // If there's no g_browser_process, return true (for testing). |
| 294 bool IsProfilePrefService(PrefService* prefs){ | 297 bool IsProfilePrefService(PrefService* prefs) { |
| 295 // TODO(zea): uncomment this once all preferences are only ever registered | 298 // TODO(zea): uncomment this once all preferences are only ever registered |
| 296 // with either the local_state's pref service or the profile's pref service. | 299 // with either the local_state's pref service or the profile's pref service. |
| 297 // return (!g_browser_process || g_browser_process->local_state() != prefs); | 300 // return (!g_browser_process || g_browser_process->local_state() != prefs); |
| 298 return true; | 301 return true; |
| 299 } | 302 } |
| 300 | 303 |
| 301 } // namespace | 304 } // namespace |
| 302 | 305 |
| 303 | 306 |
| 304 // Local State prefs. | 307 // Local State prefs. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 DCHECK(IsProfilePrefService(this)); | 515 DCHECK(IsProfilePrefService(this)); |
| 513 RegisterPreference(path, default_value, sync_status); | 516 RegisterPreference(path, default_value, sync_status); |
| 514 } | 517 } |
| 515 | 518 |
| 516 void PrefService::RegisterLocalizedBooleanPref(const char* path, | 519 void PrefService::RegisterLocalizedBooleanPref(const char* path, |
| 517 int locale_default_message_id, | 520 int locale_default_message_id, |
| 518 PrefSyncStatus sync_status) { | 521 PrefSyncStatus sync_status) { |
| 519 DCHECK(IsProfilePrefService(this)); | 522 DCHECK(IsProfilePrefService(this)); |
| 520 RegisterPreference( | 523 RegisterPreference( |
| 521 path, | 524 path, |
| 522 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN,locale_default_message_id), | 525 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id), |
| 523 sync_status); | 526 sync_status); |
| 524 } | 527 } |
| 525 | 528 |
| 526 void PrefService::RegisterLocalizedIntegerPref(const char* path, | 529 void PrefService::RegisterLocalizedIntegerPref(const char* path, |
| 527 int locale_default_message_id, | 530 int locale_default_message_id, |
| 528 PrefSyncStatus sync_status) { | 531 PrefSyncStatus sync_status) { |
| 529 DCHECK(IsProfilePrefService(this)); | 532 DCHECK(IsProfilePrefService(this)); |
| 530 RegisterPreference( | 533 RegisterPreference( |
| 531 path, | 534 path, |
| 532 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id), | 535 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id), |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 return; | 879 return; |
| 877 } | 880 } |
| 878 | 881 |
| 879 user_pref_store_->SetValue(path, owned_value.release()); | 882 user_pref_store_->SetValue(path, owned_value.release()); |
| 880 } | 883 } |
| 881 | 884 |
| 882 SyncableService* PrefService::GetSyncableService() { | 885 SyncableService* PrefService::GetSyncableService() { |
| 883 return pref_sync_associator_.get(); | 886 return pref_sync_associator_.get(); |
| 884 } | 887 } |
| 885 | 888 |
| 889 void PrefService::UpdateCommandLinePrefStore(CommandLine* command_line) { |
| 890 // If |pref_service_forked_| is true, then this PrefService and the forked |
| 891 // copies will be out of sync. |
| 892 DCHECK(!pref_service_forked_); |
| 893 pref_value_store_->UpdateCommandLinePrefStore( |
| 894 new CommandLinePrefStore(command_line)); |
| 895 } |
| 896 |
| 886 /////////////////////////////////////////////////////////////////////////////// | 897 /////////////////////////////////////////////////////////////////////////////// |
| 887 // PrefService::Preference | 898 // PrefService::Preference |
| 888 | 899 |
| 889 PrefService::Preference::Preference(const PrefService* service, | 900 PrefService::Preference::Preference(const PrefService* service, |
| 890 const char* name, | 901 const char* name, |
| 891 base::Value::Type type) | 902 base::Value::Type type) |
| 892 : name_(name), | 903 : name_(name), |
| 893 type_(type), | 904 type_(type), |
| 894 pref_service_(service) { | 905 pref_service_(service) { |
| 895 DCHECK(name); | 906 DCHECK(name); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 954 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 944 } | 955 } |
| 945 | 956 |
| 946 bool PrefService::Preference::IsUserModifiable() const { | 957 bool PrefService::Preference::IsUserModifiable() const { |
| 947 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 958 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 948 } | 959 } |
| 949 | 960 |
| 950 bool PrefService::Preference::IsExtensionModifiable() const { | 961 bool PrefService::Preference::IsExtensionModifiable() const { |
| 951 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 962 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 952 } | 963 } |
| OLD | NEW |