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