| 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 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/prefs/default_pref_store.h" | 16 #include "base/prefs/default_pref_store.h" |
| 17 #include "base/prefs/json_pref_store.h" | 17 #include "base/prefs/json_pref_store.h" |
| 18 #include "base/prefs/overlay_user_pref_store.h" | 18 #include "base/prefs/overlay_user_pref_store.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/string_number_conversions.h" | 20 #include "base/string_number_conversions.h" |
| 21 #include "base/string_util.h" | 21 #include "base/string_util.h" |
| 22 #include "base/value_conversions.h" | 22 #include "base/value_conversions.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "chrome/browser/browser_process.h" | 24 #include "chrome/browser/browser_process.h" |
| 25 #include "chrome/browser/extensions/extension_pref_store.h" | 25 #include "chrome/browser/extensions/extension_pref_store.h" |
| 26 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 26 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 27 #include "chrome/browser/prefs/command_line_pref_store.h" | 27 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 28 #include "chrome/browser/prefs/pref_model_associator.h" | 28 #include "chrome/browser/prefs/pref_model_associator.h" |
| 29 #include "chrome/browser/prefs/pref_notifier_impl.h" | 29 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| 30 #include "chrome/browser/prefs/pref_service_observer.h" |
| 30 #include "chrome/browser/prefs/pref_value_store.h" | 31 #include "chrome/browser/prefs/pref_value_store.h" |
| 31 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 32 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" | 33 #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
| 33 #include "chrome/browser/ui/profile_error_dialog.h" | 34 #include "chrome/browser/ui/profile_error_dialog.h" |
| 34 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 35 #include "content/public/browser/browser_thread.h" | 36 #include "content/public/browser/browser_thread.h" |
| 36 #include "grit/chromium_strings.h" | 37 #include "grit/chromium_strings.h" |
| 37 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
| 38 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 39 | 40 |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 bool PrefService::ReloadPersistentPrefs() { | 250 bool PrefService::ReloadPersistentPrefs() { |
| 250 return user_pref_store_->ReadPrefs() == | 251 return user_pref_store_->ReadPrefs() == |
| 251 PersistentPrefStore::PREF_READ_ERROR_NONE; | 252 PersistentPrefStore::PREF_READ_ERROR_NONE; |
| 252 } | 253 } |
| 253 | 254 |
| 254 void PrefService::CommitPendingWrite() { | 255 void PrefService::CommitPendingWrite() { |
| 255 DCHECK(CalledOnValidThread()); | 256 DCHECK(CalledOnValidThread()); |
| 256 user_pref_store_->CommitPendingWrite(); | 257 user_pref_store_->CommitPendingWrite(); |
| 257 } | 258 } |
| 258 | 259 |
| 260 void PrefService::AddObserver(PrefServiceObserver* observer) { |
| 261 observer_list_.AddObserver(observer); |
| 262 } |
| 263 |
| 264 void PrefService::RemoveObserver(PrefServiceObserver* observer) { |
| 265 observer_list_.RemoveObserver(observer); |
| 266 } |
| 267 |
| 268 bool PrefService::HasSynced() { |
| 269 return pref_sync_associator_.get() && |
| 270 pref_sync_associator_->models_associated(); |
| 271 } |
| 272 |
| 273 void PrefService::HasSyncedChanged() { |
| 274 FOR_EACH_OBSERVER(PrefServiceObserver, observer_list_, OnHasSyncedChanged()); |
| 275 } |
| 276 |
| 259 namespace { | 277 namespace { |
| 260 | 278 |
| 261 // If there's no g_browser_process or no local state, return true (for testing). | 279 // If there's no g_browser_process or no local state, return true (for testing). |
| 262 bool IsLocalStatePrefService(PrefService* prefs) { | 280 bool IsLocalStatePrefService(PrefService* prefs) { |
| 263 return (!g_browser_process || | 281 return (!g_browser_process || |
| 264 !g_browser_process->local_state() || | 282 !g_browser_process->local_state() || |
| 265 g_browser_process->local_state() == prefs); | 283 g_browser_process->local_state() == prefs); |
| 266 } | 284 } |
| 267 | 285 |
| 268 // If there's no g_browser_process, return true (for testing). | 286 // If there's no g_browser_process, return true (for testing). |
| (...skipping 773 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1042 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 1060 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 1043 } | 1061 } |
| 1044 | 1062 |
| 1045 bool PrefService::Preference::IsUserModifiable() const { | 1063 bool PrefService::Preference::IsUserModifiable() const { |
| 1046 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 1064 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 1047 } | 1065 } |
| 1048 | 1066 |
| 1049 bool PrefService::Preference::IsExtensionModifiable() const { | 1067 bool PrefService::Preference::IsExtensionModifiable() const { |
| 1050 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 1068 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 1051 } | 1069 } |
| OLD | NEW |