blob: 4206f01e0c447c43860f6f5d5c372b9a830c510e [file] [log] [blame]
[email protected]9a8c4022011-01-25 14:25:331// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]37858e52010-08-26 00:22:025#include "chrome/browser/prefs/pref_service.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]1cb92b82010-03-08 23:12:157#include <algorithm>
8#include <string>
9
[email protected]bebe69432011-09-28 18:36:4510#include "base/bind.h"
[email protected]aa4dc5e22010-06-16 11:32:5411#include "base/command_line.h"
[email protected]c02c853d72010-08-07 06:23:2412#include "base/file_path.h"
[email protected]1d01d412010-08-20 00:36:0113#include "base/file_util.h"
initial.commit09911bf2008-07-26 23:55:2914#include "base/logging.h"
15#include "base/message_loop.h"
[email protected]835d7c82010-10-14 04:38:3816#include "base/metrics/histogram.h"
[email protected]7286e3fc2011-07-19 22:13:2417#include "base/stl_util.h"
[email protected]e83326f2010-07-31 17:29:2518#include "base/string_number_conversions.h"
initial.commit09911bf2008-07-26 23:55:2919#include "base/string_util.h"
[email protected]8703b2b2011-03-15 09:51:5020#include "base/value_conversions.h"
[email protected]66de4f092009-09-04 23:59:4021#include "build/build_config.h"
[email protected]d36f941b2011-05-09 06:19:1622#include "chrome/browser/browser_process.h"
[email protected]9a8c4022011-01-25 14:25:3323#include "chrome/browser/extensions/extension_pref_store.h"
[email protected]acd78969c2010-12-08 09:49:1124#include "chrome/browser/policy/configuration_policy_pref_store.h"
25#include "chrome/browser/prefs/command_line_pref_store.h"
[email protected]f2d1f612010-12-09 15:10:1726#include "chrome/browser/prefs/default_pref_store.h"
[email protected]a78e9482011-07-14 19:22:2927#include "chrome/browser/prefs/incognito_user_pref_store.h"
[email protected]361d37f62011-11-22 10:37:0228#include "chrome/browser/prefs/per_tab_user_pref_store.h"
[email protected]d36f941b2011-05-09 06:19:1629#include "chrome/browser/prefs/pref_model_associator.h"
[email protected]acd78969c2010-12-08 09:49:1130#include "chrome/browser/prefs/pref_notifier_impl.h"
[email protected]39d9f62c2010-12-03 10:48:5031#include "chrome/browser/prefs/pref_value_store.h"
[email protected]c7fb2da32011-04-14 20:47:1032#include "chrome/browser/ui/profile_error_dialog.h"
[email protected]e4f86492011-04-13 12:23:5333#include "chrome/common/json_pref_store.h"
[email protected]c38831a12011-10-28 12:44:4934#include "content/public/browser/browser_thread.h"
[email protected]ba399672010-04-06 15:42:3935#include "grit/chromium_strings.h"
[email protected]34ac8f32009-02-22 23:03:2736#include "grit/generated_resources.h"
[email protected]c051a1b2011-01-21 23:30:1737#include "ui/base/l10n/l10n_util.h"
initial.commit09911bf2008-07-26 23:55:2938
[email protected]631bb742011-11-02 11:29:3939using content::BrowserThread;
40
initial.commit09911bf2008-07-26 23:55:2941namespace {
42
initial.commit09911bf2008-07-26 23:55:2943// 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]bab1c13f2011-08-12 20:59:0246Value* CreateLocaleDefaultValue(base::Value::Type type, int message_id) {
[email protected]16b527162010-08-15 18:37:1047 std::string resource_string = l10n_util::GetStringUTF8(message_id);
initial.commit09911bf2008-07-26 23:55:2948 DCHECK(!resource_string.empty());
49 switch (type) {
50 case Value::TYPE_BOOLEAN: {
[email protected]16b527162010-08-15 18:37:1051 if ("true" == resource_string)
initial.commit09911bf2008-07-26 23:55:2952 return Value::CreateBooleanValue(true);
[email protected]16b527162010-08-15 18:37:1053 if ("false" == resource_string)
initial.commit09911bf2008-07-26 23:55:2954 return Value::CreateBooleanValue(false);
55 break;
56 }
57
58 case Value::TYPE_INTEGER: {
[email protected]e83326f2010-07-31 17:29:2559 int val;
[email protected]16b527162010-08-15 18:37:1060 base::StringToInt(resource_string, &val);
[email protected]e83326f2010-07-31 17:29:2561 return Value::CreateIntegerValue(val);
initial.commit09911bf2008-07-26 23:55:2962 }
63
[email protected]fb534c92011-02-01 01:02:0764 case Value::TYPE_DOUBLE: {
[email protected]e83326f2010-07-31 17:29:2565 double val;
[email protected]16b527162010-08-15 18:37:1066 base::StringToDouble(resource_string, &val);
[email protected]fb534c92011-02-01 01:02:0767 return Value::CreateDoubleValue(val);
initial.commit09911bf2008-07-26 23:55:2968 }
69
70 case Value::TYPE_STRING: {
71 return Value::CreateStringValue(resource_string);
initial.commit09911bf2008-07-26 23:55:2972 }
73
74 default: {
[email protected]b154e6f2009-03-06 01:52:4075 NOTREACHED() <<
[email protected]c3b54f372010-09-14 08:25:0776 "list and dictionary types cannot have default locale values";
initial.commit09911bf2008-07-26 23:55:2977 }
78 }
79 NOTREACHED();
80 return Value::CreateNullValue();
81}
82
[email protected]ba399672010-04-06 15:42:3983// Forwards a notification after a PostMessage so that we can wait for the
84// MessageLoop to run.
[email protected]845b43a82011-05-11 10:14:4385void NotifyReadError(int message_id) {
[email protected]c7fb2da32011-04-14 20:47:1086 ShowProfileErrorDialog(message_id);
[email protected]ba399672010-04-06 15:42:3987}
88
[email protected]845b43a82011-05-11 10:14:4389// Shows notifications which correspond to PersistentPrefStore's reading errors.
90class 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]bebe69432011-09-28 18:36:45106 base::Bind(&NotifyReadError, message_id));
[email protected]845b43a82011-05-11 10:14:43107 }
[email protected]ff3c69a2011-09-15 00:36:48108 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error,
109 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM);
[email protected]845b43a82011-05-11 10:14:43110 }
111 }
112};
113
initial.commit09911bf2008-07-26 23:55:29114} // namespace
115
[email protected]db198b22010-07-12 16:48:49116// static
[email protected]a9c23a52010-08-04 09:13:44117PrefService* PrefService::CreatePrefService(const FilePath& pref_filename,
[email protected]f2d1f612010-12-09 15:10:17118 PrefStore* extension_prefs,
[email protected]845b43a82011-05-11 10:14:43119 bool async) {
[email protected]acd78969c2010-12-08 09:49:11120 using policy::ConfigurationPolicyPrefStore;
121
[email protected]1d01d412010-08-20 00:36:01122#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]f31e2e52011-07-14 16:01:19135#if defined(ENABLE_CONFIGURATION_POLICY)
[email protected]887288f02011-02-04 22:52:46136 ConfigurationPolicyPrefStore* managed_platform =
[email protected]acd78969c2010-12-08 09:49:11137 ConfigurationPolicyPrefStore::CreateManagedPlatformPolicyPrefStore();
[email protected]887288f02011-02-04 22:52:46138 ConfigurationPolicyPrefStore* managed_cloud =
[email protected]fcf53572011-06-29 15:44:37139 ConfigurationPolicyPrefStore::CreateManagedCloudPolicyPrefStore();
[email protected]f31e2e52011-07-14 16:01:19140 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]acd78969c2010-12-08 09:49:11151 CommandLinePrefStore* command_line =
152 new CommandLinePrefStore(CommandLine::ForCurrentProcess());
153 JsonPrefStore* user = new JsonPrefStore(
154 pref_filename,
155 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE));
[email protected]9a8c4022011-01-25 14:25:33156 DefaultPrefStore* default_pref_store = new DefaultPrefStore();
[email protected]acd78969c2010-12-08 09:49:11157
[email protected]361d37f62011-11-22 10:37:02158 PrefNotifierImpl* pref_notifier = new PrefNotifierImpl();
159 PrefModelAssociator* pref_sync_associator = new PrefModelAssociator();
160
[email protected]845b43a82011-05-11 10:14:43161 return new PrefService(
[email protected]361d37f62011-11-22 10:37:02162 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]9a8c4022011-01-25 14:25:33178}
179
180PrefService* PrefService::CreateIncognitoPrefService(
181 PrefStore* incognito_extension_prefs) {
[email protected]361d37f62011-11-22 10:37:02182 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]9a8c4022011-01-25 14:25:33199 default_store_.get(),
[email protected]361d37f62011-11-22 10:37:02200 NULL,
201 false);
202}
203
204PrefService* 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
228PrefService::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]9a8c4022011-01-25 14:25:33243}
244
initial.commit09911bf2008-07-26 23:55:29245PrefService::~PrefService() {
246 DCHECK(CalledOnValidThread());
initial.commit09911bf2008-07-26 23:55:29247 STLDeleteContainerPointers(prefs_.begin(), prefs_.end());
248 prefs_.clear();
[email protected]a98ce1262011-01-28 13:20:23249
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]d36f941b2011-05-09 06:19:16254 pref_sync_associator_.reset();
initial.commit09911bf2008-07-26 23:55:29255}
256
[email protected]845b43a82011-05-11 10:14:43257void PrefService::InitFromStorage(bool async) {
258 if (!async) {
259 ReadErrorHandler error_handler;
260 error_handler.OnError(user_pref_store_->ReadPrefs());
[email protected]844a1002011-04-19 11:37:21261 } else {
[email protected]845b43a82011-05-11 10:14:43262 // Guarantee that initialization happens after this function returned.
263 MessageLoop::current()->PostTask(
264 FROM_HERE,
[email protected]bebe69432011-09-28 18:36:45265 base::Bind(&PersistentPrefStore::ReadPrefsAsync,
266 user_pref_store_.get(),
267 new ReadErrorHandler()));
[email protected]844a1002011-04-19 11:37:21268 }
[email protected]ba399672010-04-06 15:42:39269}
270
271bool PrefService::ReloadPersistentPrefs() {
[email protected]f2d1f612010-12-09 15:10:17272 return user_pref_store_->ReadPrefs() ==
273 PersistentPrefStore::PREF_READ_ERROR_NONE;
initial.commit09911bf2008-07-26 23:55:29274}
275
[email protected]6faa0e0d2009-04-28 06:50:36276bool PrefService::SavePersistentPrefs() {
277 DCHECK(CalledOnValidThread());
[email protected]f2d1f612010-12-09 15:10:17278 return user_pref_store_->WritePrefs();
[email protected]6faa0e0d2009-04-28 06:50:36279}
280
[email protected]6c1164042009-05-08 14:41:08281void PrefService::ScheduleSavePersistentPrefs() {
[email protected]6faa0e0d2009-04-28 06:50:36282 DCHECK(CalledOnValidThread());
[email protected]f2d1f612010-12-09 15:10:17283 user_pref_store_->ScheduleWritePrefs();
initial.commit09911bf2008-07-26 23:55:29284}
285
[email protected]3826fed2011-03-25 10:59:56286void PrefService::CommitPendingWrite() {
287 DCHECK(CalledOnValidThread());
288 user_pref_store_->CommitPendingWrite();
289}
290
[email protected]d36f941b2011-05-09 06:19:16291namespace {
292
293// If there's no g_browser_process or no local state, return true (for testing).
294bool 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).
301bool 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]57ecc4b2010-08-11 03:02:51312void PrefService::RegisterBooleanPref(const char* path,
initial.commit09911bf2008-07-26 23:55:29313 bool default_value) {
[email protected]d36f941b2011-05-09 06:19:16314 // 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.commit09911bf2008-07-26 23:55:29320}
321
[email protected]57ecc4b2010-08-11 03:02:51322void PrefService::RegisterIntegerPref(const char* path, int default_value) {
[email protected]d36f941b2011-05-09 06:19:16323 // 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.commit09911bf2008-07-26 23:55:29329}
330
[email protected]fb534c92011-02-01 01:02:07331void PrefService::RegisterDoublePref(const char* path, double default_value) {
[email protected]d36f941b2011-05-09 06:19:16332 // 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.commit09911bf2008-07-26 23:55:29338}
339
[email protected]57ecc4b2010-08-11 03:02:51340void PrefService::RegisterStringPref(const char* path,
[email protected]20ce516d2010-06-18 02:20:04341 const std::string& default_value) {
[email protected]d36f941b2011-05-09 06:19:16342 // 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.commit09911bf2008-07-26 23:55:29348}
349
[email protected]57ecc4b2010-08-11 03:02:51350void PrefService::RegisterFilePathPref(const char* path,
[email protected]b9636002009-03-04 00:05:25351 const FilePath& default_value) {
[email protected]d36f941b2011-05-09 06:19:16352 // 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]b9636002009-03-04 00:05:25358}
359
[email protected]57ecc4b2010-08-11 03:02:51360void PrefService::RegisterListPref(const char* path) {
[email protected]d36f941b2011-05-09 06:19:16361 // 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.commit09911bf2008-07-26 23:55:29367}
368
[email protected]c2f23d012011-02-09 14:52:17369void PrefService::RegisterListPref(const char* path, ListValue* default_value) {
[email protected]d36f941b2011-05-09 06:19:16370 // 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]c2f23d012011-02-09 14:52:17376}
377
[email protected]57ecc4b2010-08-11 03:02:51378void PrefService::RegisterDictionaryPref(const char* path) {
[email protected]d36f941b2011-05-09 06:19:16379 // 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.commit09911bf2008-07-26 23:55:29385}
386
[email protected]c2f23d012011-02-09 14:52:17387void PrefService::RegisterDictionaryPref(const char* path,
388 DictionaryValue* default_value) {
[email protected]d36f941b2011-05-09 06:19:16389 // 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]c2f23d012011-02-09 14:52:17395}
396
[email protected]57ecc4b2010-08-11 03:02:51397void PrefService::RegisterLocalizedBooleanPref(const char* path,
initial.commit09911bf2008-07-26 23:55:29398 int locale_default_message_id) {
[email protected]d36f941b2011-05-09 06:19:16399 // 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]c3b54f372010-09-14 08:25:07402 RegisterPreference(
403 path,
[email protected]d36f941b2011-05-09 06:19:16404 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id),
405 UNSYNCABLE_PREF);
initial.commit09911bf2008-07-26 23:55:29406}
407
[email protected]57ecc4b2010-08-11 03:02:51408void PrefService::RegisterLocalizedIntegerPref(const char* path,
initial.commit09911bf2008-07-26 23:55:29409 int locale_default_message_id) {
[email protected]d36f941b2011-05-09 06:19:16410 // 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]c3b54f372010-09-14 08:25:07413 RegisterPreference(
414 path,
[email protected]d36f941b2011-05-09 06:19:16415 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id),
416 UNSYNCABLE_PREF);
initial.commit09911bf2008-07-26 23:55:29417}
418
[email protected]fb534c92011-02-01 01:02:07419void PrefService::RegisterLocalizedDoublePref(const char* path,
420 int locale_default_message_id) {
[email protected]d36f941b2011-05-09 06:19:16421 // 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]c3b54f372010-09-14 08:25:07424 RegisterPreference(
425 path,
[email protected]d36f941b2011-05-09 06:19:16426 CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id),
427 UNSYNCABLE_PREF);
initial.commit09911bf2008-07-26 23:55:29428}
429
[email protected]57ecc4b2010-08-11 03:02:51430void PrefService::RegisterLocalizedStringPref(const char* path,
initial.commit09911bf2008-07-26 23:55:29431 int locale_default_message_id) {
[email protected]d36f941b2011-05-09 06:19:16432 // 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]c3b54f372010-09-14 08:25:07435 RegisterPreference(
436 path,
[email protected]d36f941b2011-05-09 06:19:16437 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id),
438 UNSYNCABLE_PREF);
439}
440
441void 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).
452void 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
461void 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
470void 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
479void 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
488void 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
497void PrefService::RegisterListPref(const char* path,
498 PrefSyncStatus sync_status) {
499 DCHECK(IsProfilePrefService(this));
500 RegisterPreference(path, new ListValue(), sync_status);
501}
502
503void 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
510void PrefService::RegisterDictionaryPref(const char* path,
511 PrefSyncStatus sync_status) {
512 DCHECK(IsProfilePrefService(this));
513 RegisterPreference(path, new DictionaryValue(), sync_status);
514}
515
516void 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
523void 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
533void 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
543void 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
553void 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
563void 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.commit09911bf2008-07-26 23:55:29571}
572
[email protected]57ecc4b2010-08-11 03:02:51573bool PrefService::GetBoolean(const char* path) const {
initial.commit09911bf2008-07-26 23:55:29574 DCHECK(CalledOnValidThread());
575
576 bool result = false;
initial.commit09911bf2008-07-26 23:55:29577
578 const Preference* pref = FindPreference(path);
579 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40580 NOTREACHED() << "Trying to read an unregistered pref: " << path;
initial.commit09911bf2008-07-26 23:55:29581 return result;
582 }
583 bool rv = pref->GetValue()->GetAsBoolean(&result);
584 DCHECK(rv);
585 return result;
586}
587
[email protected]57ecc4b2010-08-11 03:02:51588int PrefService::GetInteger(const char* path) const {
initial.commit09911bf2008-07-26 23:55:29589 DCHECK(CalledOnValidThread());
590
591 int result = 0;
initial.commit09911bf2008-07-26 23:55:29592
593 const Preference* pref = FindPreference(path);
594 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40595 NOTREACHED() << "Trying to read an unregistered pref: " << path;
initial.commit09911bf2008-07-26 23:55:29596 return result;
597 }
598 bool rv = pref->GetValue()->GetAsInteger(&result);
599 DCHECK(rv);
600 return result;
601}
602
[email protected]fb534c92011-02-01 01:02:07603double PrefService::GetDouble(const char* path) const {
initial.commit09911bf2008-07-26 23:55:29604 DCHECK(CalledOnValidThread());
605
606 double result = 0.0;
initial.commit09911bf2008-07-26 23:55:29607
608 const Preference* pref = FindPreference(path);
609 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40610 NOTREACHED() << "Trying to read an unregistered pref: " << path;
initial.commit09911bf2008-07-26 23:55:29611 return result;
612 }
[email protected]fb534c92011-02-01 01:02:07613 bool rv = pref->GetValue()->GetAsDouble(&result);
initial.commit09911bf2008-07-26 23:55:29614 DCHECK(rv);
615 return result;
616}
617
[email protected]57ecc4b2010-08-11 03:02:51618std::string PrefService::GetString(const char* path) const {
initial.commit09911bf2008-07-26 23:55:29619 DCHECK(CalledOnValidThread());
620
[email protected]ddd231e2010-06-29 20:35:19621 std::string result;
[email protected]8e50b602009-03-03 22:59:43622
initial.commit09911bf2008-07-26 23:55:29623 const Preference* pref = FindPreference(path);
624 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40625 NOTREACHED() << "Trying to read an unregistered pref: " << path;
initial.commit09911bf2008-07-26 23:55:29626 return result;
627 }
628 bool rv = pref->GetValue()->GetAsString(&result);
629 DCHECK(rv);
630 return result;
631}
632
[email protected]57ecc4b2010-08-11 03:02:51633FilePath PrefService::GetFilePath(const char* path) const {
[email protected]b9636002009-03-04 00:05:25634 DCHECK(CalledOnValidThread());
635
[email protected]68d9d352011-02-21 16:35:04636 FilePath result;
[email protected]b9636002009-03-04 00:05:25637
638 const Preference* pref = FindPreference(path);
639 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40640 NOTREACHED() << "Trying to read an unregistered pref: " << path;
[email protected]b9636002009-03-04 00:05:25641 return FilePath(result);
642 }
[email protected]8703b2b2011-03-15 09:51:50643 bool rv = base::GetValueAsFilePath(*pref->GetValue(), &result);
[email protected]b9636002009-03-04 00:05:25644 DCHECK(rv);
[email protected]68d9d352011-02-21 16:35:04645 return result;
[email protected]b9636002009-03-04 00:05:25646}
647
[email protected]57ecc4b2010-08-11 03:02:51648bool PrefService::HasPrefPath(const char* path) const {
[email protected]9a8c4022011-01-25 14:25:33649 const Preference* pref = FindPreference(path);
650 return pref && !pref->IsDefaultValue();
initial.commit09911bf2008-07-26 23:55:29651}
652
[email protected]ebd0b022011-01-27 13:24:14653DictionaryValue* 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]8874e02172011-03-11 19:44:08658 const Preference* pref = FindPreference(i->first.c_str());
659 DCHECK(pref);
660 const Value* value = pref->GetValue();
661 DCHECK(value);
[email protected]ebd0b022011-01-27 13:24:14662 out->Set(i->first, value->DeepCopy());
663 }
664 return out;
665}
666
initial.commit09911bf2008-07-26 23:55:29667const PrefService::Preference* PrefService::FindPreference(
[email protected]57ecc4b2010-08-11 03:02:51668 const char* pref_name) const {
initial.commit09911bf2008-07-26 23:55:29669 DCHECK(CalledOnValidThread());
[email protected]9a8c4022011-01-25 14:25:33670 Preference p(this, pref_name, Value::TYPE_NULL);
initial.commit09911bf2008-07-26 23:55:29671 PreferenceSet::const_iterator it = prefs_.find(&p);
[email protected]9a8c4022011-01-25 14:25:33672 if (it != prefs_.end())
673 return *it;
[email protected]bab1c13f2011-08-12 20:59:02674 const base::Value::Type type = default_store_->GetType(pref_name);
[email protected]9a8c4022011-01-25 14:25:33675 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.commit09911bf2008-07-26 23:55:29680}
681
[email protected]acd78969c2010-12-08 09:49:11682bool PrefService::ReadOnly() const {
[email protected]f2d1f612010-12-09 15:10:17683 return user_pref_store_->ReadOnly();
[email protected]acd78969c2010-12-08 09:49:11684}
685
[email protected]57ecc4b2010-08-11 03:02:51686bool PrefService::IsManagedPreference(const char* pref_name) const {
[email protected]d90de1c02010-07-19 19:50:48687 const Preference* pref = FindPreference(pref_name);
[email protected]9a8c4022011-01-25 14:25:33688 return pref && pref->IsManaged();
[email protected]d90de1c02010-07-19 19:50:48689}
690
[email protected]57ecc4b2010-08-11 03:02:51691const DictionaryValue* PrefService::GetDictionary(const char* path) const {
initial.commit09911bf2008-07-26 23:55:29692 DCHECK(CalledOnValidThread());
693
initial.commit09911bf2008-07-26 23:55:29694 const Preference* pref = FindPreference(path);
695 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40696 NOTREACHED() << "Trying to read an unregistered pref: " << path;
initial.commit09911bf2008-07-26 23:55:29697 return NULL;
698 }
699 const Value* value = pref->GetValue();
[email protected]11b040b2011-02-02 12:42:25700 if (value->GetType() != Value::TYPE_DICTIONARY) {
701 NOTREACHED();
initial.commit09911bf2008-07-26 23:55:29702 return NULL;
[email protected]11b040b2011-02-02 12:42:25703 }
initial.commit09911bf2008-07-26 23:55:29704 return static_cast<const DictionaryValue*>(value);
705}
706
[email protected]57ecc4b2010-08-11 03:02:51707const ListValue* PrefService::GetList(const char* path) const {
initial.commit09911bf2008-07-26 23:55:29708 DCHECK(CalledOnValidThread());
709
initial.commit09911bf2008-07-26 23:55:29710 const Preference* pref = FindPreference(path);
711 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40712 NOTREACHED() << "Trying to read an unregistered pref: " << path;
initial.commit09911bf2008-07-26 23:55:29713 return NULL;
714 }
715 const Value* value = pref->GetValue();
[email protected]11b040b2011-02-02 12:42:25716 if (value->GetType() != Value::TYPE_LIST) {
717 NOTREACHED();
initial.commit09911bf2008-07-26 23:55:29718 return NULL;
[email protected]11b040b2011-02-02 12:42:25719 }
initial.commit09911bf2008-07-26 23:55:29720 return static_cast<const ListValue*>(value);
721}
722
[email protected]57ecc4b2010-08-11 03:02:51723void PrefService::AddPrefObserver(const char* path,
[email protected]6c2381d2011-10-19 02:52:53724 content::NotificationObserver* obs) {
[email protected]d81288a02010-08-18 07:25:50725 pref_notifier_->AddPrefObserver(path, obs);
initial.commit09911bf2008-07-26 23:55:29726}
727
[email protected]57ecc4b2010-08-11 03:02:51728void PrefService::RemovePrefObserver(const char* path,
[email protected]6c2381d2011-10-19 02:52:53729 content::NotificationObserver* obs) {
[email protected]d81288a02010-08-18 07:25:50730 pref_notifier_->RemovePrefObserver(path, obs);
initial.commit09911bf2008-07-26 23:55:29731}
732
[email protected]d36f941b2011-05-09 06:19:16733void PrefService::RegisterPreference(const char* path,
734 Value* default_value,
735 PrefSyncStatus sync_status) {
initial.commit09911bf2008-07-26 23:55:29736 DCHECK(CalledOnValidThread());
737
[email protected]c3b54f372010-09-14 08:25:07738 // 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.commit09911bf2008-07-26 23:55:29743 return;
744 }
[email protected]c3b54f372010-09-14 08:25:07745
[email protected]bab1c13f2011-08-12 20:59:02746 base::Value::Type orig_type = default_value->GetType();
[email protected]99cc9a02010-09-17 07:53:28747 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) <<
748 "invalid preference type: " << orig_type;
749
[email protected]9a8c4022011-01-25 14:25:33750 // Hand off ownership.
751 default_store_->SetDefaultValue(path, scoped_value.release());
[email protected]d36f941b2011-05-09 06:19:16752
753 // Register with sync if necessary.
754 if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get())
755 pref_sync_associator_->RegisterPref(path);
initial.commit09911bf2008-07-26 23:55:29756}
757
[email protected]57ecc4b2010-08-11 03:02:51758void PrefService::ClearPref(const char* path) {
initial.commit09911bf2008-07-26 23:55:29759 DCHECK(CalledOnValidThread());
760
761 const Preference* pref = FindPreference(path);
762 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40763 NOTREACHED() << "Trying to clear an unregistered pref: " << path;
initial.commit09911bf2008-07-26 23:55:29764 return;
765 }
[email protected]f2d1f612010-12-09 15:10:17766 user_pref_store_->RemoveValue(path);
initial.commit09911bf2008-07-26 23:55:29767}
768
[email protected]57ecc4b2010-08-11 03:02:51769void PrefService::Set(const char* path, const Value& value) {
[email protected]b99c41c2011-04-27 15:18:48770 SetUserPrefValue(path, value.DeepCopy());
[email protected]a048d7e42009-12-01 01:02:39771}
772
[email protected]57ecc4b2010-08-11 03:02:51773void PrefService::SetBoolean(const char* path, bool value) {
[email protected]c3b54f372010-09-14 08:25:07774 SetUserPrefValue(path, Value::CreateBooleanValue(value));
initial.commit09911bf2008-07-26 23:55:29775}
776
[email protected]57ecc4b2010-08-11 03:02:51777void PrefService::SetInteger(const char* path, int value) {
[email protected]c3b54f372010-09-14 08:25:07778 SetUserPrefValue(path, Value::CreateIntegerValue(value));
initial.commit09911bf2008-07-26 23:55:29779}
780
[email protected]fb534c92011-02-01 01:02:07781void PrefService::SetDouble(const char* path, double value) {
782 SetUserPrefValue(path, Value::CreateDoubleValue(value));
initial.commit09911bf2008-07-26 23:55:29783}
784
[email protected]57ecc4b2010-08-11 03:02:51785void PrefService::SetString(const char* path, const std::string& value) {
[email protected]c3b54f372010-09-14 08:25:07786 SetUserPrefValue(path, Value::CreateStringValue(value));
initial.commit09911bf2008-07-26 23:55:29787}
788
[email protected]57ecc4b2010-08-11 03:02:51789void PrefService::SetFilePath(const char* path, const FilePath& value) {
[email protected]8703b2b2011-03-15 09:51:50790 SetUserPrefValue(path, base::CreateFilePathValue(value));
[email protected]b9636002009-03-04 00:05:25791}
792
[email protected]57ecc4b2010-08-11 03:02:51793void PrefService::SetInt64(const char* path, int64 value) {
[email protected]c3b54f372010-09-14 08:25:07794 SetUserPrefValue(path, Value::CreateStringValue(base::Int64ToString(value)));
[email protected]0bb1a622009-03-04 03:22:32795}
796
[email protected]57ecc4b2010-08-11 03:02:51797int64 PrefService::GetInt64(const char* path) const {
[email protected]0bb1a622009-03-04 03:22:32798 DCHECK(CalledOnValidThread());
799
[email protected]0bb1a622009-03-04 03:22:32800 const Preference* pref = FindPreference(path);
801 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40802 NOTREACHED() << "Trying to read an unregistered pref: " << path;
[email protected]c3453302009-12-01 01:33:08803 return 0;
[email protected]0bb1a622009-03-04 03:22:32804 }
[email protected]dc9a6762010-08-16 07:13:53805 std::string result("0");
[email protected]0bb1a622009-03-04 03:22:32806 bool rv = pref->GetValue()->GetAsString(&result);
807 DCHECK(rv);
[email protected]e83326f2010-07-31 17:29:25808
809 int64 val;
[email protected]dc9a6762010-08-16 07:13:53810 base::StringToInt64(result, &val);
[email protected]e83326f2010-07-31 17:29:25811 return val;
[email protected]0bb1a622009-03-04 03:22:32812}
813
[email protected]26418b72011-03-30 14:07:39814Value* PrefService::GetMutableUserPref(const char* path,
[email protected]bab1c13f2011-08-12 20:59:02815 base::Value::Type type) {
[email protected]26418b72011-03-30 14:07:39816 CHECK(type == Value::TYPE_DICTIONARY || type == Value::TYPE_LIST);
initial.commit09911bf2008-07-26 23:55:29817 DCHECK(CalledOnValidThread());
818
819 const Preference* pref = FindPreference(path);
820 if (!pref) {
[email protected]b154e6f2009-03-06 01:52:40821 NOTREACHED() << "Trying to get an unregistered pref: " << path;
initial.commit09911bf2008-07-26 23:55:29822 return NULL;
823 }
[email protected]26418b72011-03-30 14:07:39824 if (pref->GetType() != type) {
825 NOTREACHED() << "Wrong type for GetMutableValue: " << path;
initial.commit09911bf2008-07-26 23:55:29826 return NULL;
827 }
828
[email protected]e0250892010-10-01 18:57:53829 // 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]26418b72011-03-30 14:07:39831 Value* value = NULL;
832 if (user_pref_store_->GetMutableValue(path, &value)
[email protected]f2d1f612010-12-09 15:10:17833 != PersistentPrefStore::READ_OK ||
[email protected]26418b72011-03-30 14:07:39834 !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.commit09911bf2008-07-26 23:55:29843 }
[email protected]26418b72011-03-30 14:07:39844 return value;
845}
846
[email protected]68bf41a2011-03-25 16:38:31847void PrefService::ReportUserPrefChanged(const std::string& key) {
[email protected]f89ee342011-03-07 09:28:27848 user_pref_store_->ReportValueChanged(key);
849}
850
[email protected]c3b54f372010-09-14 08:25:07851void PrefService::SetUserPrefValue(const char* path, Value* new_value) {
[email protected]b99c41c2011-04-27 15:18:48852 scoped_ptr<Value> owned_value(new_value);
[email protected]c3b54f372010-09-14 08:25:07853 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]99cc9a02010-09-17 07:53:28860 if (pref->GetType() != new_value->GetType()) {
861 NOTREACHED() << "Trying to set pref " << path
862 << " of type " << pref->GetType()
[email protected]c3b54f372010-09-14 08:25:07863 << " to value of type " << new_value->GetType();
864 return;
865 }
866
[email protected]b99c41c2011-04-27 15:18:48867 user_pref_store_->SetValue(path, owned_value.release());
[email protected]73c47932010-12-06 18:13:43868}
869
[email protected]d36f941b2011-05-09 06:19:16870SyncableService* PrefService::GetSyncableService() {
871 return pref_sync_associator_.get();
872}
873
initial.commit09911bf2008-07-26 23:55:29874///////////////////////////////////////////////////////////////////////////////
875// PrefService::Preference
876
[email protected]c3b54f372010-09-14 08:25:07877PrefService::Preference::Preference(const PrefService* service,
[email protected]9a8c4022011-01-25 14:25:33878 const char* name,
[email protected]bab1c13f2011-08-12 20:59:02879 base::Value::Type type)
[email protected]99cc9a02010-09-17 07:53:28880 : name_(name),
[email protected]9a8c4022011-01-25 14:25:33881 type_(type),
[email protected]c3b54f372010-09-14 08:25:07882 pref_service_(service) {
initial.commit09911bf2008-07-26 23:55:29883 DCHECK(name);
[email protected]c3b54f372010-09-14 08:25:07884 DCHECK(service);
[email protected]99cc9a02010-09-17 07:53:28885}
886
[email protected]bab1c13f2011-08-12 20:59:02887base::Value::Type PrefService::Preference::GetType() const {
[email protected]9a8c4022011-01-25 14:25:33888 return type_;
initial.commit09911bf2008-07-26 23:55:29889}
890
891const Value* PrefService::Preference::GetValue() const {
[email protected]c3b54f372010-09-14 08:25:07892 DCHECK(pref_service_->FindPreference(name_.c_str())) <<
initial.commit09911bf2008-07-26 23:55:29893 "Must register pref before getting its value";
894
[email protected]68bf41a2011-03-25 16:38:31895 const Value* found_value = NULL;
[email protected]887288f02011-02-04 22:52:46896 if (pref_value_store()->GetValue(name_, type_, &found_value)) {
[email protected]9a8c4022011-01-25 14:25:33897 DCHECK(found_value->IsType(type_));
[email protected]99cc9a02010-09-17 07:53:28898 return found_value;
[email protected]9a8c4022011-01-25 14:25:33899 }
initial.commit09911bf2008-07-26 23:55:29900
[email protected]c3b54f372010-09-14 08:25:07901 // Every registered preference has at least a default value.
[email protected]99cc9a02010-09-17 07:53:28902 NOTREACHED() << "no valid value found for registered pref " << name_;
[email protected]c3b54f372010-09-14 08:25:07903 return NULL;
[email protected]40a47c162010-09-09 11:14:01904}
905
906bool PrefService::Preference::IsManaged() const {
[email protected]887288f02011-02-04 22:52:46907 return pref_value_store()->PrefValueInManagedStore(name_.c_str());
[email protected]40a47c162010-09-09 11:14:01908}
909
910bool PrefService::Preference::HasExtensionSetting() const {
[email protected]887288f02011-02-04 22:52:46911 return pref_value_store()->PrefValueInExtensionStore(name_.c_str());
[email protected]40a47c162010-09-09 11:14:01912}
913
914bool PrefService::Preference::HasUserSetting() const {
[email protected]887288f02011-02-04 22:52:46915 return pref_value_store()->PrefValueInUserStore(name_.c_str());
[email protected]40a47c162010-09-09 11:14:01916}
917
918bool PrefService::Preference::IsExtensionControlled() const {
[email protected]887288f02011-02-04 22:52:46919 return pref_value_store()->PrefValueFromExtensionStore(name_.c_str());
[email protected]40a47c162010-09-09 11:14:01920}
921
922bool PrefService::Preference::IsUserControlled() const {
[email protected]887288f02011-02-04 22:52:46923 return pref_value_store()->PrefValueFromUserStore(name_.c_str());
[email protected]c3b54f372010-09-14 08:25:07924}
925
926bool PrefService::Preference::IsDefaultValue() const {
[email protected]887288f02011-02-04 22:52:46927 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str());
[email protected]d7449e82010-07-14 11:42:35928}
[email protected]74379bc52010-07-21 13:54:08929
930bool PrefService::Preference::IsUserModifiable() const {
[email protected]887288f02011-02-04 22:52:46931 return pref_value_store()->PrefValueUserModifiable(name_.c_str());
[email protected]74379bc52010-07-21 13:54:08932}
[email protected]9a28f132011-02-24 21:15:16933
934bool PrefService::Preference::IsExtensionModifiable() const {
935 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str());
936}