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