[email protected] | 32c3c75 | 2012-01-05 17:33:47 | [diff] [blame^] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 37858e5 | 2010-08-26 00:22:02 | [diff] [blame] | 5 | #include "chrome/browser/prefs/pref_service.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 1cb92b8 | 2010-03-08 23:12:15 | [diff] [blame] | 7 | #include <algorithm> |
| 8 | #include <string> |
| 9 | |
[email protected] | bebe6943 | 2011-09-28 18:36:45 | [diff] [blame] | 10 | #include "base/bind.h" |
[email protected] | aa4dc5e2 | 2010-06-16 11:32:54 | [diff] [blame] | 11 | #include "base/command_line.h" |
[email protected] | c02c853d7 | 2010-08-07 06:23:24 | [diff] [blame] | 12 | #include "base/file_path.h" |
[email protected] | 1d01d41 | 2010-08-20 00:36:01 | [diff] [blame] | 13 | #include "base/file_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 14 | #include "base/logging.h" |
| 15 | #include "base/message_loop.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 16 | #include "base/metrics/histogram.h" |
[email protected] | 7286e3fc | 2011-07-19 22:13:24 | [diff] [blame] | 17 | #include "base/stl_util.h" |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 18 | #include "base/string_number_conversions.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | #include "base/string_util.h" |
[email protected] | 8703b2b | 2011-03-15 09:51:50 | [diff] [blame] | 20 | #include "base/value_conversions.h" |
[email protected] | 66de4f09 | 2009-09-04 23:59:40 | [diff] [blame] | 21 | #include "build/build_config.h" |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 22 | #include "chrome/browser/browser_process.h" |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 23 | #include "chrome/browser/extensions/extension_pref_store.h" |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 24 | #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 25 | #include "chrome/browser/prefs/command_line_pref_store.h" |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 26 | #include "chrome/browser/prefs/default_pref_store.h" |
[email protected] | 32c3c75 | 2012-01-05 17:33:47 | [diff] [blame^] | 27 | #include "chrome/browser/prefs/overlay_user_pref_store.h" |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 28 | #include "chrome/browser/prefs/pref_model_associator.h" |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 29 | #include "chrome/browser/prefs/pref_notifier_impl.h" |
[email protected] | 39d9f62c | 2010-12-03 10:48:50 | [diff] [blame] | 30 | #include "chrome/browser/prefs/pref_value_store.h" |
[email protected] | 32c3c75 | 2012-01-05 17:33:47 | [diff] [blame^] | 31 | #include "chrome/browser/ui/prefs/prefs_tab_helper.h" |
[email protected] | c7fb2da3 | 2011-04-14 20:47:10 | [diff] [blame] | 32 | #include "chrome/browser/ui/profile_error_dialog.h" |
[email protected] | e4f8649 | 2011-04-13 12:23:53 | [diff] [blame] | 33 | #include "chrome/common/json_pref_store.h" |
[email protected] | 32c3c75 | 2012-01-05 17:33:47 | [diff] [blame^] | 34 | #include "chrome/common/pref_names.h" |
[email protected] | c38831a1 | 2011-10-28 12:44:49 | [diff] [blame] | 35 | #include "content/public/browser/browser_thread.h" |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 36 | #include "grit/chromium_strings.h" |
[email protected] | 34ac8f3 | 2009-02-22 23:03:27 | [diff] [blame] | 37 | #include "grit/generated_resources.h" |
[email protected] | c051a1b | 2011-01-21 23:30:17 | [diff] [blame] | 38 | #include "ui/base/l10n/l10n_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 39 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 40 | using content::BrowserThread; |
| 41 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 42 | namespace { |
| 43 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 44 | // A helper function for RegisterLocalized*Pref that creates a Value* based on |
| 45 | // the string value in the locale dll. Because we control the values in a |
| 46 | // locale dll, this should always return a Value of the appropriate type. |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 47 | Value* CreateLocaleDefaultValue(base::Value::Type type, int message_id) { |
[email protected] | 16b52716 | 2010-08-15 18:37:10 | [diff] [blame] | 48 | std::string resource_string = l10n_util::GetStringUTF8(message_id); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 49 | DCHECK(!resource_string.empty()); |
| 50 | switch (type) { |
| 51 | case Value::TYPE_BOOLEAN: { |
[email protected] | 16b52716 | 2010-08-15 18:37:10 | [diff] [blame] | 52 | if ("true" == resource_string) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 53 | return Value::CreateBooleanValue(true); |
[email protected] | 16b52716 | 2010-08-15 18:37:10 | [diff] [blame] | 54 | if ("false" == resource_string) |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 55 | return Value::CreateBooleanValue(false); |
| 56 | break; |
| 57 | } |
| 58 | |
| 59 | case Value::TYPE_INTEGER: { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 60 | int val; |
[email protected] | 16b52716 | 2010-08-15 18:37:10 | [diff] [blame] | 61 | base::StringToInt(resource_string, &val); |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 62 | return Value::CreateIntegerValue(val); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | } |
| 64 | |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 65 | case Value::TYPE_DOUBLE: { |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 66 | double val; |
[email protected] | 16b52716 | 2010-08-15 18:37:10 | [diff] [blame] | 67 | base::StringToDouble(resource_string, &val); |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 68 | return Value::CreateDoubleValue(val); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | case Value::TYPE_STRING: { |
| 72 | return Value::CreateStringValue(resource_string); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | default: { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 76 | NOTREACHED() << |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 77 | "list and dictionary types cannot have default locale values"; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | } |
| 79 | } |
| 80 | NOTREACHED(); |
| 81 | return Value::CreateNullValue(); |
| 82 | } |
| 83 | |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 84 | // Forwards a notification after a PostMessage so that we can wait for the |
| 85 | // MessageLoop to run. |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 86 | void NotifyReadError(int message_id) { |
[email protected] | c7fb2da3 | 2011-04-14 20:47:10 | [diff] [blame] | 87 | ShowProfileErrorDialog(message_id); |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 88 | } |
| 89 | |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 90 | // Shows notifications which correspond to PersistentPrefStore's reading errors. |
| 91 | class ReadErrorHandler : public PersistentPrefStore::ReadErrorDelegate { |
| 92 | public: |
| 93 | virtual void OnError(PersistentPrefStore::PrefReadError error) { |
| 94 | if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { |
| 95 | // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for |
| 96 | // an example problem that this can cause. |
| 97 | // Do some diagnosis and try to avoid losing data. |
| 98 | int message_id = 0; |
| 99 | if (error <= PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE) { |
| 100 | message_id = IDS_PREFERENCES_CORRUPT_ERROR; |
| 101 | } else if (error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) { |
| 102 | message_id = IDS_PREFERENCES_UNREADABLE_ERROR; |
| 103 | } |
| 104 | |
| 105 | if (message_id) { |
| 106 | BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
[email protected] | bebe6943 | 2011-09-28 18:36:45 | [diff] [blame] | 107 | base::Bind(&NotifyReadError, message_id)); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 108 | } |
[email protected] | ff3c69a | 2011-09-15 00:36:48 | [diff] [blame] | 109 | UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, |
| 110 | PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | }; |
| 114 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 115 | } // namespace |
| 116 | |
[email protected] | db198b2 | 2010-07-12 16:48:49 | [diff] [blame] | 117 | // static |
[email protected] | a9c23a5 | 2010-08-04 09:13:44 | [diff] [blame] | 118 | PrefService* PrefService::CreatePrefService(const FilePath& pref_filename, |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 119 | PrefStore* extension_prefs, |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 120 | bool async) { |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 121 | using policy::ConfigurationPolicyPrefStore; |
| 122 | |
[email protected] | 1d01d41 | 2010-08-20 00:36:01 | [diff] [blame] | 123 | #if defined(OS_LINUX) |
| 124 | // We'd like to see what fraction of our users have the preferences |
| 125 | // stored on a network file system, as we've had no end of troubles |
| 126 | // with NFS/AFS. |
| 127 | // TODO(evanm): remove this once we've collected state. |
| 128 | file_util::FileSystemType fstype; |
| 129 | if (file_util::GetFileSystemType(pref_filename.DirName(), &fstype)) { |
| 130 | UMA_HISTOGRAM_ENUMERATION("PrefService.FileSystemType", |
| 131 | static_cast<int>(fstype), |
| 132 | file_util::FILE_SYSTEM_TYPE_COUNT); |
| 133 | } |
| 134 | #endif |
| 135 | |
[email protected] | f31e2e5 | 2011-07-14 16:01:19 | [diff] [blame] | 136 | #if defined(ENABLE_CONFIGURATION_POLICY) |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 137 | ConfigurationPolicyPrefStore* managed_platform = |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 138 | ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore(); |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 139 | ConfigurationPolicyPrefStore* managed_cloud = |
[email protected] | fcf5357 | 2011-06-29 15:44:37 | [diff] [blame] | 140 | ConfigurationPolicyPrefStore::CreateManagedCloudPolicyPrefStore(); |
[email protected] | f31e2e5 | 2011-07-14 16:01:19 | [diff] [blame] | 141 | ConfigurationPolicyPrefStore* recommended_platform = |
| 142 | ConfigurationPolicyPrefStore::CreateRecommendedPlatformPolicyPrefStore(); |
| 143 | ConfigurationPolicyPrefStore* recommended_cloud = |
| 144 | ConfigurationPolicyPrefStore::CreateRecommendedCloudPolicyPrefStore(); |
| 145 | #else |
| 146 | ConfigurationPolicyPrefStore* managed_platform = NULL; |
| 147 | ConfigurationPolicyPrefStore* managed_cloud = NULL; |
| 148 | ConfigurationPolicyPrefStore* recommended_platform = NULL; |
| 149 | ConfigurationPolicyPrefStore* recommended_cloud = NULL; |
| 150 | #endif // ENABLE_CONFIGURATION_POLICY |
| 151 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 152 | CommandLinePrefStore* command_line = |
| 153 | new CommandLinePrefStore(CommandLine::ForCurrentProcess()); |
| 154 | JsonPrefStore* user = new JsonPrefStore( |
| 155 | pref_filename, |
| 156 | BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE)); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 157 | DefaultPrefStore* default_pref_store = new DefaultPrefStore(); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 158 | |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 159 | PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
| 160 | PrefModelAssociator* pref_sync_associator = new PrefModelAssociator(); |
| 161 | |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 162 | return new PrefService( |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 163 | pref_notifier, |
| 164 | new PrefValueStore( |
| 165 | managed_platform, |
| 166 | managed_cloud, |
| 167 | extension_prefs, |
| 168 | command_line, |
| 169 | user, |
| 170 | recommended_platform, |
| 171 | recommended_cloud, |
| 172 | default_pref_store, |
| 173 | pref_sync_associator, |
| 174 | pref_notifier), |
| 175 | user, |
| 176 | default_pref_store, |
| 177 | pref_sync_associator, |
| 178 | async); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | PrefService* PrefService::CreateIncognitoPrefService( |
| 182 | PrefStore* incognito_extension_prefs) { |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 183 | PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
[email protected] | 32c3c75 | 2012-01-05 17:33:47 | [diff] [blame^] | 184 | OverlayUserPrefStore* incognito_pref_store = |
| 185 | new OverlayUserPrefStore(user_pref_store_.get()); |
| 186 | PrefsTabHelper::InitIncognitoUserPrefStore(incognito_pref_store); |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 187 | return new PrefService( |
| 188 | pref_notifier, |
| 189 | pref_value_store_->CloneAndSpecialize( |
| 190 | NULL, // managed_platform_prefs |
| 191 | NULL, // managed_cloud_prefs |
| 192 | incognito_extension_prefs, |
| 193 | NULL, // command_line_prefs |
| 194 | incognito_pref_store, |
| 195 | NULL, // recommended_platform_prefs |
| 196 | NULL, // recommended_cloud_prefs |
| 197 | default_store_.get(), |
| 198 | NULL, // pref_sync_associator |
| 199 | pref_notifier), |
| 200 | incognito_pref_store, |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 201 | default_store_.get(), |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 202 | NULL, |
| 203 | false); |
| 204 | } |
| 205 | |
| 206 | PrefService* PrefService::CreatePrefServiceWithPerTabPrefStore() { |
| 207 | PrefNotifierImpl* pref_notifier = new PrefNotifierImpl(); |
[email protected] | 32c3c75 | 2012-01-05 17:33:47 | [diff] [blame^] | 208 | OverlayUserPrefStore* per_tab_pref_store = |
| 209 | new OverlayUserPrefStore(user_pref_store_.get()); |
| 210 | PrefsTabHelper::InitPerTabUserPrefStore(per_tab_pref_store); |
[email protected] | 361d37f6 | 2011-11-22 10:37:02 | [diff] [blame] | 211 | DefaultPrefStore* default_store = new DefaultPrefStore(); |
| 212 | return new PrefService( |
| 213 | pref_notifier, |
| 214 | pref_value_store_->CloneAndSpecialize( |
| 215 | NULL, // managed_platform_prefs |
| 216 | NULL, // managed_cloud_prefs |
| 217 | NULL, // extension_prefs |
| 218 | NULL, // command_line_prefs |
| 219 | per_tab_pref_store, |
| 220 | NULL, // recommended_platform_prefs |
| 221 | NULL, // recommended_cloud_prefs |
| 222 | default_store, |
| 223 | NULL, |
| 224 | pref_notifier), |
| 225 | per_tab_pref_store, |
| 226 | default_store, |
| 227 | NULL, |
| 228 | false); |
| 229 | } |
| 230 | |
| 231 | PrefService::PrefService(PrefNotifierImpl* pref_notifier, |
| 232 | PrefValueStore* pref_value_store, |
| 233 | PersistentPrefStore* user_prefs, |
| 234 | DefaultPrefStore* default_store, |
| 235 | PrefModelAssociator* pref_sync_associator, |
| 236 | bool async) |
| 237 | : pref_notifier_(pref_notifier), |
| 238 | pref_value_store_(pref_value_store), |
| 239 | user_pref_store_(user_prefs), |
| 240 | default_store_(default_store), |
| 241 | pref_sync_associator_(pref_sync_associator) { |
| 242 | pref_notifier_->SetPrefService(this); |
| 243 | if (pref_sync_associator_.get()) |
| 244 | pref_sync_associator_->SetPrefService(this); |
| 245 | InitFromStorage(async); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 246 | } |
| 247 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 248 | PrefService::~PrefService() { |
| 249 | DCHECK(CalledOnValidThread()); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 250 | STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); |
| 251 | prefs_.clear(); |
[email protected] | a98ce126 | 2011-01-28 13:20:23 | [diff] [blame] | 252 | |
| 253 | // Reset pointers so accesses after destruction reliably crash. |
| 254 | pref_value_store_.reset(); |
| 255 | user_pref_store_ = NULL; |
| 256 | default_store_ = NULL; |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 257 | pref_sync_associator_.reset(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 258 | } |
| 259 | |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 260 | void PrefService::InitFromStorage(bool async) { |
| 261 | if (!async) { |
| 262 | ReadErrorHandler error_handler; |
| 263 | error_handler.OnError(user_pref_store_->ReadPrefs()); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 264 | } else { |
[email protected] | 845b43a8 | 2011-05-11 10:14:43 | [diff] [blame] | 265 | // Guarantee that initialization happens after this function returned. |
| 266 | MessageLoop::current()->PostTask( |
| 267 | FROM_HERE, |
[email protected] | bebe6943 | 2011-09-28 18:36:45 | [diff] [blame] | 268 | base::Bind(&PersistentPrefStore::ReadPrefsAsync, |
| 269 | user_pref_store_.get(), |
| 270 | new ReadErrorHandler())); |
[email protected] | 844a100 | 2011-04-19 11:37:21 | [diff] [blame] | 271 | } |
[email protected] | ba39967 | 2010-04-06 15:42:39 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | bool PrefService::ReloadPersistentPrefs() { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 275 | return user_pref_store_->ReadPrefs() == |
| 276 | PersistentPrefStore::PREF_READ_ERROR_NONE; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 277 | } |
| 278 | |
[email protected] | 3826fed | 2011-03-25 10:59:56 | [diff] [blame] | 279 | void PrefService::CommitPendingWrite() { |
| 280 | DCHECK(CalledOnValidThread()); |
| 281 | user_pref_store_->CommitPendingWrite(); |
| 282 | } |
| 283 | |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 284 | namespace { |
| 285 | |
| 286 | // If there's no g_browser_process or no local state, return true (for testing). |
| 287 | bool IsLocalStatePrefService(PrefService* prefs){ |
| 288 | return (!g_browser_process || |
| 289 | !g_browser_process->local_state() || |
| 290 | g_browser_process->local_state() == prefs); |
| 291 | } |
| 292 | |
| 293 | // If there's no g_browser_process, return true (for testing). |
| 294 | bool IsProfilePrefService(PrefService* prefs){ |
| 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. |
| 297 | // return (!g_browser_process || g_browser_process->local_state() != prefs); |
| 298 | return true; |
| 299 | } |
| 300 | |
| 301 | } // namespace |
| 302 | |
| 303 | |
| 304 | // Local State prefs. |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 305 | void PrefService::RegisterBooleanPref(const char* path, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 306 | bool default_value) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 307 | // If this fails, the pref service in use is a profile pref service, so the |
| 308 | // sync status must be provided (see profile pref registration calls below). |
| 309 | DCHECK(IsLocalStatePrefService(this)); |
| 310 | RegisterPreference(path, |
| 311 | Value::CreateBooleanValue(default_value), |
| 312 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 313 | } |
| 314 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 315 | void PrefService::RegisterIntegerPref(const char* path, int default_value) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 316 | // If this fails, the pref service in use is a profile pref service, so the |
| 317 | // sync status must be provided (see profile pref registration calls below). |
| 318 | DCHECK(IsLocalStatePrefService(this)); |
| 319 | RegisterPreference(path, |
| 320 | Value::CreateIntegerValue(default_value), |
| 321 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 322 | } |
| 323 | |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 324 | void PrefService::RegisterDoublePref(const char* path, double default_value) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 325 | // If this fails, the pref service in use is a profile pref service, so the |
| 326 | // sync status must be provided (see profile pref registration calls below). |
| 327 | DCHECK(IsLocalStatePrefService(this)); |
| 328 | RegisterPreference(path, |
| 329 | Value::CreateDoubleValue(default_value), |
| 330 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 331 | } |
| 332 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 333 | void PrefService::RegisterStringPref(const char* path, |
[email protected] | 20ce516d | 2010-06-18 02:20:04 | [diff] [blame] | 334 | const std::string& default_value) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 335 | // If this fails, the pref service in use is a profile pref service, so the |
| 336 | // sync status must be provided (see profile pref registration calls below). |
| 337 | DCHECK(IsLocalStatePrefService(this)); |
| 338 | RegisterPreference(path, |
| 339 | Value::CreateStringValue(default_value), |
| 340 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 341 | } |
| 342 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 343 | void PrefService::RegisterFilePathPref(const char* path, |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 344 | const FilePath& default_value) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 345 | // If this fails, the pref service in use is a profile pref service, so the |
| 346 | // sync status must be provided (see profile pref registration calls below). |
| 347 | DCHECK(IsLocalStatePrefService(this)); |
| 348 | RegisterPreference(path, |
| 349 | Value::CreateStringValue(default_value.value()), |
| 350 | UNSYNCABLE_PREF); |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 351 | } |
| 352 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 353 | void PrefService::RegisterListPref(const char* path) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 354 | // If this fails, the pref service in use is a profile pref service, so the |
| 355 | // sync status must be provided (see profile pref registration calls below). |
| 356 | DCHECK(IsLocalStatePrefService(this)); |
| 357 | RegisterPreference(path, |
| 358 | new ListValue(), |
| 359 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 360 | } |
| 361 | |
[email protected] | c2f23d01 | 2011-02-09 14:52:17 | [diff] [blame] | 362 | void PrefService::RegisterListPref(const char* path, ListValue* default_value) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 363 | // If this fails, the pref service in use is a profile pref service, so the |
| 364 | // sync status must be provided (see profile pref registration calls below). |
| 365 | DCHECK(IsLocalStatePrefService(this)); |
| 366 | RegisterPreference(path, |
| 367 | default_value, |
| 368 | UNSYNCABLE_PREF); |
[email protected] | c2f23d01 | 2011-02-09 14:52:17 | [diff] [blame] | 369 | } |
| 370 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 371 | void PrefService::RegisterDictionaryPref(const char* path) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 372 | // If this fails, the pref service in use is a profile pref service, so the |
| 373 | // sync status must be provided (see profile pref registration calls below). |
| 374 | DCHECK(IsLocalStatePrefService(this)); |
| 375 | RegisterPreference(path, |
| 376 | new DictionaryValue(), |
| 377 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 378 | } |
| 379 | |
[email protected] | c2f23d01 | 2011-02-09 14:52:17 | [diff] [blame] | 380 | void PrefService::RegisterDictionaryPref(const char* path, |
| 381 | DictionaryValue* default_value) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 382 | // If this fails, the pref service in use is a profile pref service, so the |
| 383 | // sync status must be provided (see profile pref registration calls below). |
| 384 | DCHECK(IsLocalStatePrefService(this)); |
| 385 | RegisterPreference(path, |
| 386 | default_value, |
| 387 | UNSYNCABLE_PREF); |
[email protected] | c2f23d01 | 2011-02-09 14:52:17 | [diff] [blame] | 388 | } |
| 389 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 390 | void PrefService::RegisterLocalizedBooleanPref(const char* path, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 391 | int locale_default_message_id) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 392 | // If this fails, the pref service in use is a profile pref service, so the |
| 393 | // sync status must be provided (see profile pref registration calls below). |
| 394 | DCHECK(IsLocalStatePrefService(this)); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 395 | RegisterPreference( |
| 396 | path, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 397 | CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id), |
| 398 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 399 | } |
| 400 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 401 | void PrefService::RegisterLocalizedIntegerPref(const char* path, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 402 | int locale_default_message_id) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 403 | // If this fails, the pref service in use is a profile pref service, so the |
| 404 | // sync status must be provided (see profile pref registration calls below). |
| 405 | DCHECK(IsLocalStatePrefService(this)); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 406 | RegisterPreference( |
| 407 | path, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 408 | CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id), |
| 409 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 410 | } |
| 411 | |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 412 | void PrefService::RegisterLocalizedDoublePref(const char* path, |
| 413 | int locale_default_message_id) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 414 | // If this fails, the pref service in use is a profile pref service, so the |
| 415 | // sync status must be provided (see profile pref registration calls below). |
| 416 | DCHECK(IsLocalStatePrefService(this)); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 417 | RegisterPreference( |
| 418 | path, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 419 | CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id), |
| 420 | UNSYNCABLE_PREF); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 421 | } |
| 422 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 423 | void PrefService::RegisterLocalizedStringPref(const char* path, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 424 | int locale_default_message_id) { |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 425 | // If this fails, the pref service in use is a profile pref service, so the |
| 426 | // sync status must be provided (see profile pref registration calls below). |
| 427 | DCHECK(IsLocalStatePrefService(this)); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 428 | RegisterPreference( |
| 429 | path, |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 430 | CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id), |
| 431 | UNSYNCABLE_PREF); |
| 432 | } |
| 433 | |
| 434 | void PrefService::RegisterInt64Pref(const char* path, int64 default_value) { |
| 435 | // If this fails, the pref service in use is a profile pref service, so the |
| 436 | // sync status must be provided (see profile pref registration calls below). |
| 437 | DCHECK(IsLocalStatePrefService(this)); |
| 438 | RegisterPreference( |
| 439 | path, |
| 440 | Value::CreateStringValue(base::Int64ToString(default_value)), |
| 441 | UNSYNCABLE_PREF); |
| 442 | } |
| 443 | |
| 444 | // Profile prefs (must use the sync_status variable). |
| 445 | void PrefService::RegisterBooleanPref(const char* path, |
| 446 | bool default_value, |
| 447 | PrefSyncStatus sync_status) { |
| 448 | DCHECK(IsProfilePrefService(this)); |
| 449 | RegisterPreference(path, |
| 450 | Value::CreateBooleanValue(default_value), |
| 451 | sync_status); |
| 452 | } |
| 453 | |
| 454 | void PrefService::RegisterIntegerPref(const char* path, |
| 455 | int default_value, |
| 456 | PrefSyncStatus sync_status) { |
| 457 | DCHECK(IsProfilePrefService(this)); |
| 458 | RegisterPreference(path, |
| 459 | Value::CreateIntegerValue(default_value), |
| 460 | sync_status); |
| 461 | } |
| 462 | |
| 463 | void PrefService::RegisterDoublePref(const char* path, |
| 464 | double default_value, |
| 465 | PrefSyncStatus sync_status) { |
| 466 | DCHECK(IsProfilePrefService(this)); |
| 467 | RegisterPreference(path, |
| 468 | Value::CreateDoubleValue(default_value), |
| 469 | sync_status); |
| 470 | } |
| 471 | |
| 472 | void PrefService::RegisterStringPref(const char* path, |
| 473 | const std::string& default_value, |
| 474 | PrefSyncStatus sync_status) { |
| 475 | DCHECK(IsProfilePrefService(this)); |
| 476 | RegisterPreference(path, |
| 477 | Value::CreateStringValue(default_value), |
| 478 | sync_status); |
| 479 | } |
| 480 | |
| 481 | void PrefService::RegisterFilePathPref(const char* path, |
| 482 | const FilePath& default_value, |
| 483 | PrefSyncStatus sync_status) { |
| 484 | DCHECK(IsProfilePrefService(this)); |
| 485 | RegisterPreference(path, |
| 486 | Value::CreateStringValue(default_value.value()), |
| 487 | sync_status); |
| 488 | } |
| 489 | |
| 490 | void PrefService::RegisterListPref(const char* path, |
| 491 | PrefSyncStatus sync_status) { |
| 492 | DCHECK(IsProfilePrefService(this)); |
| 493 | RegisterPreference(path, new ListValue(), sync_status); |
| 494 | } |
| 495 | |
| 496 | void PrefService::RegisterListPref(const char* path, |
| 497 | ListValue* default_value, |
| 498 | PrefSyncStatus sync_status) { |
| 499 | DCHECK(IsProfilePrefService(this)); |
| 500 | RegisterPreference(path, default_value, sync_status); |
| 501 | } |
| 502 | |
| 503 | void PrefService::RegisterDictionaryPref(const char* path, |
| 504 | PrefSyncStatus sync_status) { |
| 505 | DCHECK(IsProfilePrefService(this)); |
| 506 | RegisterPreference(path, new DictionaryValue(), sync_status); |
| 507 | } |
| 508 | |
| 509 | void PrefService::RegisterDictionaryPref(const char* path, |
| 510 | DictionaryValue* default_value, |
| 511 | PrefSyncStatus sync_status) { |
| 512 | DCHECK(IsProfilePrefService(this)); |
| 513 | RegisterPreference(path, default_value, sync_status); |
| 514 | } |
| 515 | |
| 516 | void PrefService::RegisterLocalizedBooleanPref(const char* path, |
| 517 | int locale_default_message_id, |
| 518 | PrefSyncStatus sync_status) { |
| 519 | DCHECK(IsProfilePrefService(this)); |
| 520 | RegisterPreference( |
| 521 | path, |
| 522 | CreateLocaleDefaultValue(Value::TYPE_BOOLEAN,locale_default_message_id), |
| 523 | sync_status); |
| 524 | } |
| 525 | |
| 526 | void PrefService::RegisterLocalizedIntegerPref(const char* path, |
| 527 | int locale_default_message_id, |
| 528 | PrefSyncStatus sync_status) { |
| 529 | DCHECK(IsProfilePrefService(this)); |
| 530 | RegisterPreference( |
| 531 | path, |
| 532 | CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id), |
| 533 | sync_status); |
| 534 | } |
| 535 | |
| 536 | void PrefService::RegisterLocalizedDoublePref(const char* path, |
| 537 | int locale_default_message_id, |
| 538 | PrefSyncStatus sync_status) { |
| 539 | DCHECK(IsProfilePrefService(this)); |
| 540 | RegisterPreference( |
| 541 | path, |
| 542 | CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id), |
| 543 | sync_status); |
| 544 | } |
| 545 | |
| 546 | void PrefService::RegisterLocalizedStringPref(const char* path, |
| 547 | int locale_default_message_id, |
| 548 | PrefSyncStatus sync_status) { |
| 549 | DCHECK(IsProfilePrefService(this)); |
| 550 | RegisterPreference( |
| 551 | path, |
| 552 | CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id), |
| 553 | sync_status); |
| 554 | } |
| 555 | |
| 556 | void PrefService::RegisterInt64Pref(const char* path, |
| 557 | int64 default_value, |
| 558 | PrefSyncStatus sync_status) { |
| 559 | DCHECK(IsProfilePrefService(this)); |
| 560 | RegisterPreference( |
| 561 | path, |
| 562 | Value::CreateStringValue(base::Int64ToString(default_value)), |
| 563 | sync_status); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 564 | } |
| 565 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 566 | bool PrefService::GetBoolean(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 567 | DCHECK(CalledOnValidThread()); |
| 568 | |
| 569 | bool result = false; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 570 | |
| 571 | const Preference* pref = FindPreference(path); |
| 572 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 573 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 574 | return result; |
| 575 | } |
| 576 | bool rv = pref->GetValue()->GetAsBoolean(&result); |
| 577 | DCHECK(rv); |
| 578 | return result; |
| 579 | } |
| 580 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 581 | int PrefService::GetInteger(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 582 | DCHECK(CalledOnValidThread()); |
| 583 | |
| 584 | int result = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 585 | |
| 586 | const Preference* pref = FindPreference(path); |
| 587 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 588 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 589 | return result; |
| 590 | } |
| 591 | bool rv = pref->GetValue()->GetAsInteger(&result); |
| 592 | DCHECK(rv); |
| 593 | return result; |
| 594 | } |
| 595 | |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 596 | double PrefService::GetDouble(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 597 | DCHECK(CalledOnValidThread()); |
| 598 | |
| 599 | double result = 0.0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 600 | |
| 601 | const Preference* pref = FindPreference(path); |
| 602 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 603 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 604 | return result; |
| 605 | } |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 606 | bool rv = pref->GetValue()->GetAsDouble(&result); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 607 | DCHECK(rv); |
| 608 | return result; |
| 609 | } |
| 610 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 611 | std::string PrefService::GetString(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 612 | DCHECK(CalledOnValidThread()); |
| 613 | |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 614 | std::string result; |
[email protected] | 8e50b60 | 2009-03-03 22:59:43 | [diff] [blame] | 615 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 616 | const Preference* pref = FindPreference(path); |
| 617 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 618 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 619 | return result; |
| 620 | } |
| 621 | bool rv = pref->GetValue()->GetAsString(&result); |
| 622 | DCHECK(rv); |
| 623 | return result; |
| 624 | } |
| 625 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 626 | FilePath PrefService::GetFilePath(const char* path) const { |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 627 | DCHECK(CalledOnValidThread()); |
| 628 | |
[email protected] | 68d9d35 | 2011-02-21 16:35:04 | [diff] [blame] | 629 | FilePath result; |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 630 | |
| 631 | const Preference* pref = FindPreference(path); |
| 632 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 633 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 634 | return FilePath(result); |
| 635 | } |
[email protected] | 8703b2b | 2011-03-15 09:51:50 | [diff] [blame] | 636 | bool rv = base::GetValueAsFilePath(*pref->GetValue(), &result); |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 637 | DCHECK(rv); |
[email protected] | 68d9d35 | 2011-02-21 16:35:04 | [diff] [blame] | 638 | return result; |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 641 | bool PrefService::HasPrefPath(const char* path) const { |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 642 | const Preference* pref = FindPreference(path); |
| 643 | return pref && !pref->IsDefaultValue(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 644 | } |
| 645 | |
[email protected] | ebd0b02 | 2011-01-27 13:24:14 | [diff] [blame] | 646 | DictionaryValue* PrefService::GetPreferenceValues() const { |
| 647 | DCHECK(CalledOnValidThread()); |
| 648 | DictionaryValue* out = new DictionaryValue; |
| 649 | DefaultPrefStore::const_iterator i = default_store_->begin(); |
| 650 | for (; i != default_store_->end(); ++i) { |
[email protected] | 8874e0217 | 2011-03-11 19:44:08 | [diff] [blame] | 651 | const Preference* pref = FindPreference(i->first.c_str()); |
| 652 | DCHECK(pref); |
| 653 | const Value* value = pref->GetValue(); |
| 654 | DCHECK(value); |
[email protected] | ebd0b02 | 2011-01-27 13:24:14 | [diff] [blame] | 655 | out->Set(i->first, value->DeepCopy()); |
| 656 | } |
| 657 | return out; |
| 658 | } |
| 659 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 660 | const PrefService::Preference* PrefService::FindPreference( |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 661 | const char* pref_name) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 662 | DCHECK(CalledOnValidThread()); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 663 | Preference p(this, pref_name, Value::TYPE_NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 664 | PreferenceSet::const_iterator it = prefs_.find(&p); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 665 | if (it != prefs_.end()) |
| 666 | return *it; |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 667 | const base::Value::Type type = default_store_->GetType(pref_name); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 668 | if (type == Value::TYPE_NULL) |
| 669 | return NULL; |
| 670 | Preference* new_pref = new Preference(this, pref_name, type); |
| 671 | prefs_.insert(new_pref); |
| 672 | return new_pref; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 673 | } |
| 674 | |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 675 | bool PrefService::ReadOnly() const { |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 676 | return user_pref_store_->ReadOnly(); |
[email protected] | acd78969c | 2010-12-08 09:49:11 | [diff] [blame] | 677 | } |
| 678 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 679 | bool PrefService::IsManagedPreference(const char* pref_name) const { |
[email protected] | d90de1c0 | 2010-07-19 19:50:48 | [diff] [blame] | 680 | const Preference* pref = FindPreference(pref_name); |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 681 | return pref && pref->IsManaged(); |
[email protected] | d90de1c0 | 2010-07-19 19:50:48 | [diff] [blame] | 682 | } |
| 683 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 684 | const DictionaryValue* PrefService::GetDictionary(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 685 | DCHECK(CalledOnValidThread()); |
| 686 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 687 | const Preference* pref = FindPreference(path); |
| 688 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 689 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 690 | return NULL; |
| 691 | } |
| 692 | const Value* value = pref->GetValue(); |
[email protected] | 11b040b | 2011-02-02 12:42:25 | [diff] [blame] | 693 | if (value->GetType() != Value::TYPE_DICTIONARY) { |
| 694 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 695 | return NULL; |
[email protected] | 11b040b | 2011-02-02 12:42:25 | [diff] [blame] | 696 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 697 | return static_cast<const DictionaryValue*>(value); |
| 698 | } |
| 699 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 700 | const ListValue* PrefService::GetList(const char* path) const { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 701 | DCHECK(CalledOnValidThread()); |
| 702 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 703 | const Preference* pref = FindPreference(path); |
| 704 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 705 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 706 | return NULL; |
| 707 | } |
| 708 | const Value* value = pref->GetValue(); |
[email protected] | 11b040b | 2011-02-02 12:42:25 | [diff] [blame] | 709 | if (value->GetType() != Value::TYPE_LIST) { |
| 710 | NOTREACHED(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 711 | return NULL; |
[email protected] | 11b040b | 2011-02-02 12:42:25 | [diff] [blame] | 712 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 713 | return static_cast<const ListValue*>(value); |
| 714 | } |
| 715 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 716 | void PrefService::AddPrefObserver(const char* path, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 717 | content::NotificationObserver* obs) { |
[email protected] | d81288a0 | 2010-08-18 07:25:50 | [diff] [blame] | 718 | pref_notifier_->AddPrefObserver(path, obs); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 719 | } |
| 720 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 721 | void PrefService::RemovePrefObserver(const char* path, |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 722 | content::NotificationObserver* obs) { |
[email protected] | d81288a0 | 2010-08-18 07:25:50 | [diff] [blame] | 723 | pref_notifier_->RemovePrefObserver(path, obs); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 724 | } |
| 725 | |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 726 | void PrefService::RegisterPreference(const char* path, |
| 727 | Value* default_value, |
| 728 | PrefSyncStatus sync_status) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 729 | DCHECK(CalledOnValidThread()); |
| 730 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 731 | // The main code path takes ownership, but most don't. We'll be safe. |
| 732 | scoped_ptr<Value> scoped_value(default_value); |
| 733 | |
| 734 | if (FindPreference(path)) { |
| 735 | NOTREACHED() << "Tried to register duplicate pref " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 736 | return; |
| 737 | } |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 738 | |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 739 | base::Value::Type orig_type = default_value->GetType(); |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 740 | DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << |
| 741 | "invalid preference type: " << orig_type; |
| 742 | |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 743 | // Hand off ownership. |
| 744 | default_store_->SetDefaultValue(path, scoped_value.release()); |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 745 | |
| 746 | // Register with sync if necessary. |
| 747 | if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get()) |
| 748 | pref_sync_associator_->RegisterPref(path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 749 | } |
| 750 | |
[email protected] | 7a5f593 | 2011-12-29 10:35:49 | [diff] [blame] | 751 | void PrefService::UnregisterPreference(const char* path) { |
| 752 | DCHECK(CalledOnValidThread()); |
| 753 | |
| 754 | Preference p(this, path, Value::TYPE_NULL); |
| 755 | PreferenceSet::const_iterator it = prefs_.find(&p); |
| 756 | if (it == prefs_.end()) { |
| 757 | NOTREACHED() << "Trying to unregister an unregistered pref: " << path; |
| 758 | return; |
| 759 | } |
| 760 | |
[email protected] | 5a56d37 | 2011-12-29 11:34:40 | [diff] [blame] | 761 | delete *it; |
[email protected] | 7a5f593 | 2011-12-29 10:35:49 | [diff] [blame] | 762 | prefs_.erase(it); |
| 763 | default_store_->RemoveDefaultValue(path); |
| 764 | if (pref_sync_associator_.get() && |
| 765 | pref_sync_associator_->IsPrefRegistered(path)) { |
| 766 | pref_sync_associator_->UnregisterPref(path); |
| 767 | } |
| 768 | } |
| 769 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 770 | void PrefService::ClearPref(const char* path) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 771 | DCHECK(CalledOnValidThread()); |
| 772 | |
| 773 | const Preference* pref = FindPreference(path); |
| 774 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 775 | NOTREACHED() << "Trying to clear an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 776 | return; |
| 777 | } |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 778 | user_pref_store_->RemoveValue(path); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 779 | } |
| 780 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 781 | void PrefService::Set(const char* path, const Value& value) { |
[email protected] | b99c41c | 2011-04-27 15:18:48 | [diff] [blame] | 782 | SetUserPrefValue(path, value.DeepCopy()); |
[email protected] | a048d7e4 | 2009-12-01 01:02:39 | [diff] [blame] | 783 | } |
| 784 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 785 | void PrefService::SetBoolean(const char* path, bool value) { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 786 | SetUserPrefValue(path, Value::CreateBooleanValue(value)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 787 | } |
| 788 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 789 | void PrefService::SetInteger(const char* path, int value) { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 790 | SetUserPrefValue(path, Value::CreateIntegerValue(value)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 791 | } |
| 792 | |
[email protected] | fb534c9 | 2011-02-01 01:02:07 | [diff] [blame] | 793 | void PrefService::SetDouble(const char* path, double value) { |
| 794 | SetUserPrefValue(path, Value::CreateDoubleValue(value)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 795 | } |
| 796 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 797 | void PrefService::SetString(const char* path, const std::string& value) { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 798 | SetUserPrefValue(path, Value::CreateStringValue(value)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 799 | } |
| 800 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 801 | void PrefService::SetFilePath(const char* path, const FilePath& value) { |
[email protected] | 8703b2b | 2011-03-15 09:51:50 | [diff] [blame] | 802 | SetUserPrefValue(path, base::CreateFilePathValue(value)); |
[email protected] | b963600 | 2009-03-04 00:05:25 | [diff] [blame] | 803 | } |
| 804 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 805 | void PrefService::SetInt64(const char* path, int64 value) { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 806 | SetUserPrefValue(path, Value::CreateStringValue(base::Int64ToString(value))); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 807 | } |
| 808 | |
[email protected] | 57ecc4b | 2010-08-11 03:02:51 | [diff] [blame] | 809 | int64 PrefService::GetInt64(const char* path) const { |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 810 | DCHECK(CalledOnValidThread()); |
| 811 | |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 812 | const Preference* pref = FindPreference(path); |
| 813 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 814 | NOTREACHED() << "Trying to read an unregistered pref: " << path; |
[email protected] | c345330 | 2009-12-01 01:33:08 | [diff] [blame] | 815 | return 0; |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 816 | } |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 817 | std::string result("0"); |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 818 | bool rv = pref->GetValue()->GetAsString(&result); |
| 819 | DCHECK(rv); |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 820 | |
| 821 | int64 val; |
[email protected] | dc9a676 | 2010-08-16 07:13:53 | [diff] [blame] | 822 | base::StringToInt64(result, &val); |
[email protected] | e83326f | 2010-07-31 17:29:25 | [diff] [blame] | 823 | return val; |
[email protected] | 0bb1a62 | 2009-03-04 03:22:32 | [diff] [blame] | 824 | } |
| 825 | |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 826 | Value* PrefService::GetMutableUserPref(const char* path, |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 827 | base::Value::Type type) { |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 828 | CHECK(type == Value::TYPE_DICTIONARY || type == Value::TYPE_LIST); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 829 | DCHECK(CalledOnValidThread()); |
| 830 | |
| 831 | const Preference* pref = FindPreference(path); |
| 832 | if (!pref) { |
[email protected] | b154e6f | 2009-03-06 01:52:40 | [diff] [blame] | 833 | NOTREACHED() << "Trying to get an unregistered pref: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 834 | return NULL; |
| 835 | } |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 836 | if (pref->GetType() != type) { |
| 837 | NOTREACHED() << "Wrong type for GetMutableValue: " << path; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 838 | return NULL; |
| 839 | } |
| 840 | |
[email protected] | e025089 | 2010-10-01 18:57:53 | [diff] [blame] | 841 | // Look for an existing preference in the user store. If it doesn't |
| 842 | // exist or isn't the correct type, create a new user preference. |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 843 | Value* value = NULL; |
| 844 | if (user_pref_store_->GetMutableValue(path, &value) |
[email protected] | f2d1f61 | 2010-12-09 15:10:17 | [diff] [blame] | 845 | != PersistentPrefStore::READ_OK || |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 846 | !value->IsType(type)) { |
| 847 | if (type == Value::TYPE_DICTIONARY) { |
| 848 | value = new DictionaryValue; |
| 849 | } else if (type == Value::TYPE_LIST) { |
| 850 | value = new ListValue; |
| 851 | } else { |
| 852 | NOTREACHED(); |
| 853 | } |
| 854 | user_pref_store_->SetValueSilently(path, value); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 855 | } |
[email protected] | 26418b7 | 2011-03-30 14:07:39 | [diff] [blame] | 856 | return value; |
| 857 | } |
| 858 | |
[email protected] | 68bf41a | 2011-03-25 16:38:31 | [diff] [blame] | 859 | void PrefService::ReportUserPrefChanged(const std::string& key) { |
[email protected] | f89ee34 | 2011-03-07 09:28:27 | [diff] [blame] | 860 | user_pref_store_->ReportValueChanged(key); |
| 861 | } |
| 862 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 863 | void PrefService::SetUserPrefValue(const char* path, Value* new_value) { |
[email protected] | b99c41c | 2011-04-27 15:18:48 | [diff] [blame] | 864 | scoped_ptr<Value> owned_value(new_value); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 865 | DCHECK(CalledOnValidThread()); |
| 866 | |
| 867 | const Preference* pref = FindPreference(path); |
| 868 | if (!pref) { |
| 869 | NOTREACHED() << "Trying to write an unregistered pref: " << path; |
| 870 | return; |
| 871 | } |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 872 | if (pref->GetType() != new_value->GetType()) { |
| 873 | NOTREACHED() << "Trying to set pref " << path |
| 874 | << " of type " << pref->GetType() |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 875 | << " to value of type " << new_value->GetType(); |
| 876 | return; |
| 877 | } |
| 878 | |
[email protected] | b99c41c | 2011-04-27 15:18:48 | [diff] [blame] | 879 | user_pref_store_->SetValue(path, owned_value.release()); |
[email protected] | 73c4793 | 2010-12-06 18:13:43 | [diff] [blame] | 880 | } |
| 881 | |
[email protected] | d36f941b | 2011-05-09 06:19:16 | [diff] [blame] | 882 | SyncableService* PrefService::GetSyncableService() { |
| 883 | return pref_sync_associator_.get(); |
| 884 | } |
| 885 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 886 | /////////////////////////////////////////////////////////////////////////////// |
| 887 | // PrefService::Preference |
| 888 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 889 | PrefService::Preference::Preference(const PrefService* service, |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 890 | const char* name, |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 891 | base::Value::Type type) |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 892 | : name_(name), |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 893 | type_(type), |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 894 | pref_service_(service) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 895 | DCHECK(name); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 896 | DCHECK(service); |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 897 | } |
| 898 | |
[email protected] | bab1c13f | 2011-08-12 20:59:02 | [diff] [blame] | 899 | base::Value::Type PrefService::Preference::GetType() const { |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 900 | return type_; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 901 | } |
| 902 | |
| 903 | const Value* PrefService::Preference::GetValue() const { |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 904 | DCHECK(pref_service_->FindPreference(name_.c_str())) << |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 905 | "Must register pref before getting its value"; |
| 906 | |
[email protected] | 68bf41a | 2011-03-25 16:38:31 | [diff] [blame] | 907 | const Value* found_value = NULL; |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 908 | if (pref_value_store()->GetValue(name_, type_, &found_value)) { |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 909 | DCHECK(found_value->IsType(type_)); |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 910 | return found_value; |
[email protected] | 9a8c402 | 2011-01-25 14:25:33 | [diff] [blame] | 911 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 912 | |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 913 | // Every registered preference has at least a default value. |
[email protected] | 99cc9a0 | 2010-09-17 07:53:28 | [diff] [blame] | 914 | NOTREACHED() << "no valid value found for registered pref " << name_; |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 915 | return NULL; |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 916 | } |
| 917 | |
| 918 | bool PrefService::Preference::IsManaged() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 919 | return pref_value_store()->PrefValueInManagedStore(name_.c_str()); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 920 | } |
| 921 | |
[email protected] | a543728 | 2011-12-12 12:33:21 | [diff] [blame] | 922 | bool PrefService::Preference::IsRecommended() const { |
| 923 | return pref_value_store()->PrefValueFromRecommendedStore(name_.c_str()); |
| 924 | } |
| 925 | |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 926 | bool PrefService::Preference::HasExtensionSetting() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 927 | return pref_value_store()->PrefValueInExtensionStore(name_.c_str()); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | bool PrefService::Preference::HasUserSetting() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 931 | return pref_value_store()->PrefValueInUserStore(name_.c_str()); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 932 | } |
| 933 | |
| 934 | bool PrefService::Preference::IsExtensionControlled() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 935 | return pref_value_store()->PrefValueFromExtensionStore(name_.c_str()); |
[email protected] | 40a47c16 | 2010-09-09 11:14:01 | [diff] [blame] | 936 | } |
| 937 | |
| 938 | bool PrefService::Preference::IsUserControlled() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 939 | return pref_value_store()->PrefValueFromUserStore(name_.c_str()); |
[email protected] | c3b54f37 | 2010-09-14 08:25:07 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | bool PrefService::Preference::IsDefaultValue() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 943 | return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
[email protected] | d7449e8 | 2010-07-14 11:42:35 | [diff] [blame] | 944 | } |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 945 | |
| 946 | bool PrefService::Preference::IsUserModifiable() const { |
[email protected] | 887288f0 | 2011-02-04 22:52:46 | [diff] [blame] | 947 | return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
[email protected] | 74379bc5 | 2010-07-21 13:54:08 | [diff] [blame] | 948 | } |
[email protected] | 9a28f13 | 2011-02-24 21:15:16 | [diff] [blame] | 949 | |
| 950 | bool PrefService::Preference::IsExtensionModifiable() const { |
| 951 | return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 952 | } |