| 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/stl_util.h" | 16 #include "base/stl_util.h" |
| 17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/threading/sequenced_worker_pool.h" |
| 19 #include "base/value_conversions.h" | 20 #include "base/value_conversions.h" |
| 20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
| 21 #include "chrome/browser/browser_process.h" | 22 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/extensions/extension_pref_store.h" | 23 #include "chrome/browser/extensions/extension_pref_store.h" |
| 23 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 24 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 24 #include "chrome/browser/prefs/command_line_pref_store.h" | 25 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 25 #include "chrome/browser/prefs/default_pref_store.h" | 26 #include "chrome/browser/prefs/default_pref_store.h" |
| 26 #include "chrome/browser/prefs/overlay_user_pref_store.h" | 27 #include "chrome/browser/prefs/overlay_user_pref_store.h" |
| 27 #include "chrome/browser/prefs/pref_model_associator.h" | 28 #include "chrome/browser/prefs/pref_model_associator.h" |
| 28 #include "chrome/browser/prefs/pref_notifier_impl.h" | 29 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 | 118 |
| 118 PrefServiceBase* PrefServiceBase::FromBrowserContext(BrowserContext* context) { | 119 PrefServiceBase* PrefServiceBase::FromBrowserContext(BrowserContext* context) { |
| 119 return static_cast<Profile*>(context)->GetPrefs(); | 120 return static_cast<Profile*>(context)->GetPrefs(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 // static | 123 // static |
| 123 PrefService* PrefService::CreatePrefService( | 124 PrefService* PrefService::CreatePrefService( |
| 124 const FilePath& pref_filename, | 125 const FilePath& pref_filename, |
| 125 policy::PolicyService* policy_service, | 126 policy::PolicyService* policy_service, |
| 126 PrefStore* extension_prefs, | 127 PrefStore* extension_prefs, |
| 127 bool async) { | 128 bool async, |
| 129 base::SequencedTaskRunner* sequenced_task_runner) { |
| 128 using policy::ConfigurationPolicyPrefStore; | 130 using policy::ConfigurationPolicyPrefStore; |
| 129 | 131 |
| 130 #if defined(OS_LINUX) | 132 #if defined(OS_LINUX) |
| 131 // We'd like to see what fraction of our users have the preferences | 133 // We'd like to see what fraction of our users have the preferences |
| 132 // stored on a network file system, as we've had no end of troubles | 134 // stored on a network file system, as we've had no end of troubles |
| 133 // with NFS/AFS. | 135 // with NFS/AFS. |
| 134 // TODO(evanm): remove this once we've collected state. | 136 // TODO(evanm): remove this once we've collected state. |
| 135 file_util::FileSystemType fstype; | 137 file_util::FileSystemType fstype; |
| 136 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { | 138 if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { |
| 137 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", | 139 UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", |
| 138 static_cast<int>(fstype), | 140 static_cast<int>(fstype), |
| 139 file_util::FILE_SYSTEM_TYPE_COUNT); | 141 file_util::FILE_SYSTEM_TYPE_COUNT); |
| 140 } | 142 } |
| 141 #endif | 143 #endif |
| 142 | 144 |
| 143 #if defined(ENABLE_CONFIGURATION_POLICY) | 145 #if defined(ENABLE_CONFIGURATION_POLICY) |
| 144 ConfigurationPolicyPrefStore* managed = | 146 ConfigurationPolicyPrefStore* managed = |
| 145 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( | 147 ConfigurationPolicyPrefStore::CreateMandatoryPolicyPrefStore( |
| 146 policy_service); | 148 policy_service); |
| 147 ConfigurationPolicyPrefStore* recommended = | 149 ConfigurationPolicyPrefStore* recommended = |
| 148 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( | 150 ConfigurationPolicyPrefStore::CreateRecommendedPolicyPrefStore( |
| 149 policy_service); | 151 policy_service); |
| 150 #else | 152 #else |
| 151 ConfigurationPolicyPrefStore* managed = NULL; | 153 ConfigurationPolicyPrefStore* managed = NULL; |
| 152 ConfigurationPolicyPrefStore* recommended = NULL; | 154 ConfigurationPolicyPrefStore* recommended = NULL; |
| 153 #endif // ENABLE_CONFIGURATION_POLICY | 155 #endif // ENABLE_CONFIGURATION_POLICY |
| 154 | 156 |
| 155 CommandLinePrefStore* command_line = | 157 CommandLinePrefStore* command_line = |
| 156 new CommandLinePrefStore(CommandLine::ForCurrentProcess()); | 158 new CommandLinePrefStore(CommandLine::ForCurrentProcess()); |
| 157 JsonPrefStore* user = new JsonPrefStore( | 159 JsonPrefStore* user = JsonPrefStore::Create( |
| 158 pref_filename, | 160 pref_filename, sequenced_task_runner); |
| 159 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); | |
| 160 DefaultPrefStore* default_pref_store = new DefaultPrefStore(); | 161 DefaultPrefStore* default_pref_store = new DefaultPrefStore(); |
| 161 | 162 |
| 162 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); | 163 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
| 163 PrefModelAssociator* pref_sync_associator = new PrefModelAssociator(); | 164 PrefModelAssociator* pref_sync_associator = new PrefModelAssociator(); |
| 164 | 165 |
| 165 return new PrefService( | 166 return new PrefService( |
| 166 pref_notifier, | 167 pref_notifier, |
| 167 new PrefValueStore( | 168 new PrefValueStore( |
| 168 managed, | 169 managed, |
| 169 extension_prefs, | 170 extension_prefs, |
| (...skipping 877 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1047 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 1048 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 1048 } | 1049 } |
| 1049 | 1050 |
| 1050 bool PrefService::Preference::IsUserModifiable() const { | 1051 bool PrefService::Preference::IsUserModifiable() const { |
| 1051 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 1052 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 1052 } | 1053 } |
| 1053 | 1054 |
| 1054 bool PrefService::Preference::IsExtensionModifiable() const { | 1055 bool PrefService::Preference::IsExtensionModifiable() const { |
| 1055 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 1056 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 1056 } | 1057 } |
| OLD | NEW |