| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 | 180 |
| 181 PrefService* PrefService::CreateIncognitoPrefService( | 181 PrefService* PrefService::CreateIncognitoPrefService( |
| 182 PrefStore* incognito_extension_prefs) { | 182 PrefStore* incognito_extension_prefs) { |
| 183 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); | 183 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
| 184 OverlayUserPrefStore* incognito_pref_store = | 184 OverlayUserPrefStore* incognito_pref_store = |
| 185 new OverlayUserPrefStore(user_pref_store_.get()); | 185 new OverlayUserPrefStore(user_pref_store_.get()); |
| 186 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store); | 186 PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store); |
| 187 return new PrefService( | 187 return new PrefService( |
| 188 pref_notifier, | 188 pref_notifier, |
| 189 pref_value_store_->CloneAndSpecialize( | 189 pref_value_store_->CloneAndSpecialize( |
| 190 NULL, // managed_platform_prefs | 190 NULL, // managed_platform_prefs |
| 191 NULL, // managed_cloud_prefs | 191 NULL, // managed_cloud_prefs |
| 192 incognito_extension_prefs, | 192 incognito_extension_prefs, |
| 193 NULL, // command_line_prefs | 193 NULL, // command_line_prefs |
| 194 incognito_pref_store, | 194 incognito_pref_store, |
| 195 NULL, // recommended_platform_prefs | 195 NULL, // recommended_platform_prefs |
| 196 NULL, // recommended_cloud_prefs | 196 NULL, // recommended_cloud_prefs |
| 197 default_store_.get(), | 197 default_store_.get(), |
| 198 NULL, // pref_sync_associator | 198 NULL, // pref_sync_associator |
| 199 pref_notifier), | 199 pref_notifier), |
| 200 incognito_pref_store, | 200 incognito_pref_store, |
| 201 default_store_.get(), | 201 default_store_.get(), |
| 202 NULL, | 202 NULL, |
| 203 false); | 203 false); |
| 204 } | 204 } |
| 205 | 205 |
| 206 PrefService* PrefService::CreatePrefServiceWithPerTabPrefStore() { | 206 PrefService* PrefService::CreatePrefServiceWithPerTabPrefStore() { |
| 207 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); | 207 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
| 208 OverlayUserPrefStore* per_tab_pref_store = | 208 OverlayUserPrefStore* per_tab_pref_store = |
| 209 new OverlayUserPrefStore(user_pref_store_.get()); | 209 new OverlayUserPrefStore(user_pref_store_.get()); |
| 210 PrefsTabHelper::InitPerTabUserPrefStore(per_tab_pref_store); | 210 PrefsTabHelper::InitPerTabUserPrefStore(per_tab_pref_store); |
| 211 DefaultPrefStore* default_store = new DefaultPrefStore(); | 211 DefaultPrefStore* default_store = new DefaultPrefStore(); |
| 212 return new PrefService( | 212 return new PrefService( |
| 213 pref_notifier, | 213 pref_notifier, |
| 214 pref_value_store_->CloneAndSpecialize( | 214 pref_value_store_->CloneAndSpecialize( |
| 215 NULL, // managed_platform_prefs | 215 NULL, // managed_platform_prefs |
| 216 NULL, // managed_cloud_prefs | 216 NULL, // managed_cloud_prefs |
| 217 NULL, // extension_prefs | 217 NULL, // extension_prefs |
| 218 NULL, // command_line_prefs | 218 NULL, // command_line_prefs |
| 219 per_tab_pref_store, | 219 per_tab_pref_store, |
| 220 NULL, // recommended_platform_prefs | 220 NULL, // recommended_platform_prefs |
| 221 NULL, // recommended_cloud_prefs | 221 NULL, // recommended_cloud_prefs |
| 222 default_store, | 222 default_store, |
| 223 NULL, | 223 NULL, |
| 224 pref_notifier), | 224 pref_notifier), |
| 225 per_tab_pref_store, | 225 per_tab_pref_store, |
| 226 default_store, | 226 default_store, |
| 227 NULL, | 227 NULL, |
| 228 false); | 228 false); |
| 229 } | 229 } |
| 230 | 230 |
| 231 PrefService::PrefService(PrefNotifierImpl* pref_notifier, | 231 PrefService::PrefService(PrefNotifierImpl* pref_notifier, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 } | 277 } |
| 278 | 278 |
| 279 void PrefService::CommitPendingWrite() { | 279 void PrefService::CommitPendingWrite() { |
| 280 DCHECK(CalledOnValidThread()); | 280 DCHECK(CalledOnValidThread()); |
| 281 user_pref_store_->CommitPendingWrite(); | 281 user_pref_store_->CommitPendingWrite(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 namespace { | 284 namespace { |
| 285 | 285 |
| 286 // If there's no g_browser_process or no local state, return true (for testing). | 286 // If there's no g_browser_process or no local state, return true (for testing). |
| 287 bool IsLocalStatePrefService(PrefService* prefs){ | 287 bool IsLocalStatePrefService(PrefService* prefs) { |
| 288 return (!g_browser_process || | 288 return (!g_browser_process || |
| 289 !g_browser_process->local_state() || | 289 !g_browser_process->local_state() || |
| 290 g_browser_process->local_state() == prefs); | 290 g_browser_process->local_state() == prefs); |
| 291 } | 291 } |
| 292 | 292 |
| 293 // If there's no g_browser_process, return true (for testing). | 293 // If there's no g_browser_process, return true (for testing). |
| 294 bool IsProfilePrefService(PrefService* prefs){ | 294 bool IsProfilePrefService(PrefService* prefs) { |
| 295 // TODO(zea): uncomment this once all preferences are only ever registered | 295 // 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. | 296 // 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); | 297 // return (!g_browser_process || g_browser_process->local_state() != prefs); |
| 298 return true; | 298 return true; |
| 299 } | 299 } |
| 300 | 300 |
| 301 } // namespace | 301 } // namespace |
| 302 | 302 |
| 303 | 303 |
| 304 // Local State prefs. | 304 // Local State prefs. |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 DCHECK(IsProfilePrefService(this)); | 512 DCHECK(IsProfilePrefService(this)); |
| 513 RegisterPreference(path, default_value, sync_status); | 513 RegisterPreference(path, default_value, sync_status); |
| 514 } | 514 } |
| 515 | 515 |
| 516 void PrefService::RegisterLocalizedBooleanPref(const char* path, | 516 void PrefService::RegisterLocalizedBooleanPref(const char* path, |
| 517 int locale_default_message_id, | 517 int locale_default_message_id, |
| 518 PrefSyncStatus sync_status) { | 518 PrefSyncStatus sync_status) { |
| 519 DCHECK(IsProfilePrefService(this)); | 519 DCHECK(IsProfilePrefService(this)); |
| 520 RegisterPreference( | 520 RegisterPreference( |
| 521 path, | 521 path, |
| 522 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN,locale_default_message_id), | 522 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id), |
| 523 sync_status); | 523 sync_status); |
| 524 } | 524 } |
| 525 | 525 |
| 526 void PrefService::RegisterLocalizedIntegerPref(const char* path, | 526 void PrefService::RegisterLocalizedIntegerPref(const char* path, |
| 527 int locale_default_message_id, | 527 int locale_default_message_id, |
| 528 PrefSyncStatus sync_status) { | 528 PrefSyncStatus sync_status) { |
| 529 DCHECK(IsProfilePrefService(this)); | 529 DCHECK(IsProfilePrefService(this)); |
| 530 RegisterPreference( | 530 RegisterPreference( |
| 531 path, | 531 path, |
| 532 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id), | 532 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id), |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 return; | 876 return; |
| 877 } | 877 } |
| 878 | 878 |
| 879 user_pref_store_->SetValue(path, owned_value.release()); | 879 user_pref_store_->SetValue(path, owned_value.release()); |
| 880 } | 880 } |
| 881 | 881 |
| 882 SyncableService* PrefService::GetSyncableService() { | 882 SyncableService* PrefService::GetSyncableService() { |
| 883 return pref_sync_associator_.get(); | 883 return pref_sync_associator_.get(); |
| 884 } | 884 } |
| 885 | 885 |
| 886 void PrefService::UpdateCommandLinePrefStore(CommandLine* command_line) { |
| 887 pref_value_store_->UpdateCommandLinePrefStore( |
| 888 new CommandLinePrefStore(command_line)); |
| 889 } |
| 890 |
| 886 /////////////////////////////////////////////////////////////////////////////// | 891 /////////////////////////////////////////////////////////////////////////////// |
| 887 // PrefService::Preference | 892 // PrefService::Preference |
| 888 | 893 |
| 889 PrefService::Preference::Preference(const PrefService* service, | 894 PrefService::Preference::Preference(const PrefService* service, |
| 890 const char* name, | 895 const char* name, |
| 891 base::Value::Type type) | 896 base::Value::Type type) |
| 892 : name_(name), | 897 : name_(name), |
| 893 type_(type), | 898 type_(type), |
| 894 pref_service_(service) { | 899 pref_service_(service) { |
| 895 DCHECK(name); | 900 DCHECK(name); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 943 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 948 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 944 } | 949 } |
| 945 | 950 |
| 946 bool PrefService::Preference::IsUserModifiable() const { | 951 bool PrefService::Preference::IsUserModifiable() const { |
| 947 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 952 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 948 } | 953 } |
| 949 | 954 |
| 950 bool PrefService::Preference::IsExtensionModifiable() const { | 955 bool PrefService::Preference::IsExtensionModifiable() const { |
| 951 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 956 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 952 } | 957 } |
| OLD | NEW |