| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/prefs/pref_service.h" | 5 #include "chrome/browser/prefs/pref_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/stl_util-inl.h" | 16 #include "base/stl_util-inl.h" |
| 17 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/value_conversions.h" | 19 #include "base/value_conversions.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "chrome/browser/browser_process.h" |
| 21 #include "chrome/browser/extensions/extension_pref_store.h" | 22 #include "chrome/browser/extensions/extension_pref_store.h" |
| 22 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 23 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
| 23 #include "chrome/browser/prefs/command_line_pref_store.h" | 24 #include "chrome/browser/prefs/command_line_pref_store.h" |
| 24 #include "chrome/browser/prefs/default_pref_store.h" | 25 #include "chrome/browser/prefs/default_pref_store.h" |
| 25 #include "chrome/browser/prefs/overlay_persistent_pref_store.h" | 26 #include "chrome/browser/prefs/overlay_persistent_pref_store.h" |
| 27 #include "chrome/browser/prefs/pref_model_associator.h" |
| 26 #include "chrome/browser/prefs/pref_notifier_impl.h" | 28 #include "chrome/browser/prefs/pref_notifier_impl.h" |
| 27 #include "chrome/browser/prefs/pref_value_store.h" | 29 #include "chrome/browser/prefs/pref_value_store.h" |
| 28 #include "chrome/browser/ui/profile_error_dialog.h" | 30 #include "chrome/browser/ui/profile_error_dialog.h" |
| 29 #include "chrome/common/json_pref_store.h" | 31 #include "chrome/common/json_pref_store.h" |
| 30 #include "content/browser/browser_thread.h" | 32 #include "content/browser/browser_thread.h" |
| 31 #include "content/common/notification_service.h" | 33 #include "content/common/notification_service.h" |
| 32 #include "grit/chromium_strings.h" | 34 #include "grit/chromium_strings.h" |
| 33 #include "grit/generated_resources.h" | 35 #include "grit/generated_resources.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 35 | 37 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 PrefStore* extension_prefs, | 144 PrefStore* extension_prefs, |
| 143 PrefStore* command_line_prefs, | 145 PrefStore* command_line_prefs, |
| 144 PersistentPrefStore* user_prefs, | 146 PersistentPrefStore* user_prefs, |
| 145 PrefStore* recommended_platform_prefs, | 147 PrefStore* recommended_platform_prefs, |
| 146 PrefStore* recommended_cloud_prefs, | 148 PrefStore* recommended_cloud_prefs, |
| 147 DefaultPrefStore* default_store, | 149 DefaultPrefStore* default_store, |
| 148 PrefServiceDelegate* delegate) | 150 PrefServiceDelegate* delegate) |
| 149 : user_pref_store_(user_prefs), | 151 : user_pref_store_(user_prefs), |
| 150 default_store_(default_store), | 152 default_store_(default_store), |
| 151 delegate_(delegate) { | 153 delegate_(delegate) { |
| 154 pref_sync_associator_.reset(new PrefModelAssociator(this)); |
| 152 pref_notifier_.reset(new PrefNotifierImpl(this)); | 155 pref_notifier_.reset(new PrefNotifierImpl(this)); |
| 153 pref_value_store_.reset( | 156 pref_value_store_.reset( |
| 154 new PrefValueStore(managed_platform_prefs, | 157 new PrefValueStore(managed_platform_prefs, |
| 155 managed_cloud_prefs, | 158 managed_cloud_prefs, |
| 156 extension_prefs, | 159 extension_prefs, |
| 157 command_line_prefs, | 160 command_line_prefs, |
| 158 user_pref_store_, | 161 user_pref_store_, |
| 159 recommended_platform_prefs, | 162 recommended_platform_prefs, |
| 160 recommended_cloud_prefs, | 163 recommended_cloud_prefs, |
| 161 default_store, | 164 default_store, |
| 165 pref_sync_associator_.get(), |
| 162 pref_notifier_.get())); | 166 pref_notifier_.get())); |
| 163 InitFromStorage(); | 167 InitFromStorage(); |
| 164 } | 168 } |
| 165 | 169 |
| 166 PrefService::PrefService(const PrefService& original, | 170 PrefService::PrefService(const PrefService& original, |
| 167 PrefStore* incognito_extension_prefs) | 171 PrefStore* incognito_extension_prefs) |
| 168 : user_pref_store_( | 172 : user_pref_store_( |
| 169 new OverlayPersistentPrefStore(original.user_pref_store_.get())), | 173 new OverlayPersistentPrefStore(original.user_pref_store_.get())), |
| 170 default_store_(original.default_store_.get()), | 174 default_store_(original.default_store_.get()), |
| 171 delegate_(NULL) { | 175 delegate_(NULL) { |
| 176 // Incognito mode doesn't sync, so no need to create PrefModelAssociator. |
| 172 pref_notifier_.reset(new PrefNotifierImpl(this)); | 177 pref_notifier_.reset(new PrefNotifierImpl(this)); |
| 173 pref_value_store_.reset(original.pref_value_store_->CloneAndSpecialize( | 178 pref_value_store_.reset(original.pref_value_store_->CloneAndSpecialize( |
| 174 NULL, // managed_platform_prefs | 179 NULL, // managed_platform_prefs |
| 175 NULL, // managed_cloud_prefs | 180 NULL, // managed_cloud_prefs |
| 176 incognito_extension_prefs, | 181 incognito_extension_prefs, |
| 177 NULL, // command_line_prefs | 182 NULL, // command_line_prefs |
| 178 user_pref_store_.get(), | 183 user_pref_store_.get(), |
| 179 NULL, // recommended_platform_prefs | 184 NULL, // recommended_platform_prefs |
| 180 NULL, // recommended_cloud_prefs | 185 NULL, // recommended_cloud_prefs |
| 181 default_store_.get(), | 186 default_store_.get(), |
| 187 NULL, // pref_sync_associator_ |
| 182 pref_notifier_.get())); | 188 pref_notifier_.get())); |
| 183 InitFromStorage(); | 189 InitFromStorage(); |
| 184 } | 190 } |
| 185 | 191 |
| 186 PrefService::~PrefService() { | 192 PrefService::~PrefService() { |
| 187 DCHECK(CalledOnValidThread()); | 193 DCHECK(CalledOnValidThread()); |
| 188 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); | 194 STLDeleteContainerPointers(prefs_.begin(), prefs_.end()); |
| 189 prefs_.clear(); | 195 prefs_.clear(); |
| 190 | 196 |
| 191 // Reset pointers so accesses after destruction reliably crash. | 197 // Reset pointers so accesses after destruction reliably crash. |
| 192 pref_value_store_.reset(); | 198 pref_value_store_.reset(); |
| 193 user_pref_store_ = NULL; | 199 user_pref_store_ = NULL; |
| 194 default_store_ = NULL; | 200 default_store_ = NULL; |
| 201 if (pref_sync_associator_.get()) |
| 202 pref_sync_associator_->DisassociateModels(); |
| 203 pref_sync_associator_.reset(); |
| 195 } | 204 } |
| 196 | 205 |
| 197 void PrefService::OnPrefsRead(PersistentPrefStore::PrefReadError error, | 206 void PrefService::OnPrefsRead(PersistentPrefStore::PrefReadError error, |
| 198 bool no_dir) { | 207 bool no_dir) { |
| 199 if (no_dir) { | 208 if (no_dir) { |
| 200 // Bad news. When profile is created, the process that creates the directory | 209 // Bad news. When profile is created, the process that creates the directory |
| 201 // is explicitly started. So if directory is missing it probably means that | 210 // is explicitly started. So if directory is missing it probably means that |
| 202 // Chromium hasn't sufficient privileges. | 211 // Chromium hasn't sufficient privileges. |
| 203 CHECK(delegate_); | 212 CHECK(delegate_); |
| 204 delegate_->OnPrefsLoaded(this, false); | 213 delegate_->OnPrefsLoaded(this, false); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 void PrefService::ScheduleSavePersistentPrefs() { | 260 void PrefService::ScheduleSavePersistentPrefs() { |
| 252 DCHECK(CalledOnValidThread()); | 261 DCHECK(CalledOnValidThread()); |
| 253 user_pref_store_->ScheduleWritePrefs(); | 262 user_pref_store_->ScheduleWritePrefs(); |
| 254 } | 263 } |
| 255 | 264 |
| 256 void PrefService::CommitPendingWrite() { | 265 void PrefService::CommitPendingWrite() { |
| 257 DCHECK(CalledOnValidThread()); | 266 DCHECK(CalledOnValidThread()); |
| 258 user_pref_store_->CommitPendingWrite(); | 267 user_pref_store_->CommitPendingWrite(); |
| 259 } | 268 } |
| 260 | 269 |
| 270 namespace { |
| 271 |
| 272 // If there's no g_browser_process or no local state, return true (for testing). |
| 273 bool IsLocalStatePrefService(PrefService* prefs){ |
| 274 return (!g_browser_process || |
| 275 !g_browser_process->local_state() || |
| 276 g_browser_process->local_state() == prefs); |
| 277 } |
| 278 |
| 279 // If there's no g_browser_process, return true (for testing). |
| 280 bool IsProfilePrefService(PrefService* prefs){ |
| 281 // TODO(zea): uncomment this once all preferences are only ever registered |
| 282 // with either the local_state's pref service or the profile's pref service. |
| 283 // return (!g_browser_process || g_browser_process->local_state() != prefs); |
| 284 return true; |
| 285 } |
| 286 |
| 287 } // namespace |
| 288 |
| 289 |
| 290 // Local State prefs. |
| 261 void PrefService::RegisterBooleanPref(const char* path, | 291 void PrefService::RegisterBooleanPref(const char* path, |
| 262 bool default_value) { | 292 bool default_value) { |
| 263 RegisterPreference(path, Value::CreateBooleanValue(default_value)); | 293 // If this fails, the pref service in use is a profile pref service, so the |
| 294 // sync status must be provided (see profile pref registration calls below). |
| 295 DCHECK(IsLocalStatePrefService(this)); |
| 296 RegisterPreference(path, |
| 297 Value::CreateBooleanValue(default_value), |
| 298 UNSYNCABLE_PREF); |
| 264 } | 299 } |
| 265 | 300 |
| 266 void PrefService::RegisterIntegerPref(const char* path, int default_value) { | 301 void PrefService::RegisterIntegerPref(const char* path, int default_value) { |
| 267 RegisterPreference(path, Value::CreateIntegerValue(default_value)); | 302 // If this fails, the pref service in use is a profile pref service, so the |
| 303 // sync status must be provided (see profile pref registration calls below). |
| 304 DCHECK(IsLocalStatePrefService(this)); |
| 305 RegisterPreference(path, |
| 306 Value::CreateIntegerValue(default_value), |
| 307 UNSYNCABLE_PREF); |
| 268 } | 308 } |
| 269 | 309 |
| 270 void PrefService::RegisterDoublePref(const char* path, double default_value) { | 310 void PrefService::RegisterDoublePref(const char* path, double default_value) { |
| 271 RegisterPreference(path, Value::CreateDoubleValue(default_value)); | 311 // If this fails, the pref service in use is a profile pref service, so the |
| 312 // sync status must be provided (see profile pref registration calls below). |
| 313 DCHECK(IsLocalStatePrefService(this)); |
| 314 RegisterPreference(path, |
| 315 Value::CreateDoubleValue(default_value), |
| 316 UNSYNCABLE_PREF); |
| 272 } | 317 } |
| 273 | 318 |
| 274 void PrefService::RegisterStringPref(const char* path, | 319 void PrefService::RegisterStringPref(const char* path, |
| 275 const std::string& default_value) { | 320 const std::string& default_value) { |
| 276 RegisterPreference(path, Value::CreateStringValue(default_value)); | 321 // If this fails, the pref service in use is a profile pref service, so the |
| 322 // sync status must be provided (see profile pref registration calls below). |
| 323 DCHECK(IsLocalStatePrefService(this)); |
| 324 RegisterPreference(path, |
| 325 Value::CreateStringValue(default_value), |
| 326 UNSYNCABLE_PREF); |
| 277 } | 327 } |
| 278 | 328 |
| 279 void PrefService::RegisterFilePathPref(const char* path, | 329 void PrefService::RegisterFilePathPref(const char* path, |
| 280 const FilePath& default_value) { | 330 const FilePath& default_value) { |
| 281 RegisterPreference(path, Value::CreateStringValue(default_value.value())); | 331 // If this fails, the pref service in use is a profile pref service, so the |
| 332 // sync status must be provided (see profile pref registration calls below). |
| 333 DCHECK(IsLocalStatePrefService(this)); |
| 334 RegisterPreference(path, |
| 335 Value::CreateStringValue(default_value.value()), |
| 336 UNSYNCABLE_PREF); |
| 282 } | 337 } |
| 283 | 338 |
| 284 void PrefService::RegisterListPref(const char* path) { | 339 void PrefService::RegisterListPref(const char* path) { |
| 285 RegisterPreference(path, new ListValue()); | 340 // If this fails, the pref service in use is a profile pref service, so the |
| 341 // sync status must be provided (see profile pref registration calls below). |
| 342 DCHECK(IsLocalStatePrefService(this)); |
| 343 RegisterPreference(path, |
| 344 new ListValue(), |
| 345 UNSYNCABLE_PREF); |
| 286 } | 346 } |
| 287 | 347 |
| 288 void PrefService::RegisterListPref(const char* path, ListValue* default_value) { | 348 void PrefService::RegisterListPref(const char* path, ListValue* default_value) { |
| 289 RegisterPreference(path, default_value); | 349 // If this fails, the pref service in use is a profile pref service, so the |
| 350 // sync status must be provided (see profile pref registration calls below). |
| 351 DCHECK(IsLocalStatePrefService(this)); |
| 352 RegisterPreference(path, |
| 353 default_value, |
| 354 UNSYNCABLE_PREF); |
| 290 } | 355 } |
| 291 | 356 |
| 292 void PrefService::RegisterDictionaryPref(const char* path) { | 357 void PrefService::RegisterDictionaryPref(const char* path) { |
| 293 RegisterPreference(path, new DictionaryValue()); | 358 // If this fails, the pref service in use is a profile pref service, so the |
| 359 // sync status must be provided (see profile pref registration calls below). |
| 360 DCHECK(IsLocalStatePrefService(this)); |
| 361 RegisterPreference(path, |
| 362 new DictionaryValue(), |
| 363 UNSYNCABLE_PREF); |
| 294 } | 364 } |
| 295 | 365 |
| 296 void PrefService::RegisterDictionaryPref(const char* path, | 366 void PrefService::RegisterDictionaryPref(const char* path, |
| 297 DictionaryValue* default_value) { | 367 DictionaryValue* default_value) { |
| 298 RegisterPreference(path, default_value); | 368 // If this fails, the pref service in use is a profile pref service, so the |
| 369 // sync status must be provided (see profile pref registration calls below). |
| 370 DCHECK(IsLocalStatePrefService(this)); |
| 371 RegisterPreference(path, |
| 372 default_value, |
| 373 UNSYNCABLE_PREF); |
| 299 } | 374 } |
| 300 | 375 |
| 301 void PrefService::RegisterLocalizedBooleanPref(const char* path, | 376 void PrefService::RegisterLocalizedBooleanPref(const char* path, |
| 302 int locale_default_message_id) { | 377 int locale_default_message_id) { |
| 303 RegisterPreference( | 378 // If this fails, the pref service in use is a profile pref service, so the |
| 304 path, | 379 // sync status must be provided (see profile pref registration calls below). |
| 305 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id)); | 380 DCHECK(IsLocalStatePrefService(this)); |
| 381 RegisterPreference( |
| 382 path, |
| 383 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN, locale_default_message_id), |
| 384 UNSYNCABLE_PREF); |
| 306 } | 385 } |
| 307 | 386 |
| 308 void PrefService::RegisterLocalizedIntegerPref(const char* path, | 387 void PrefService::RegisterLocalizedIntegerPref(const char* path, |
| 309 int locale_default_message_id) { | 388 int locale_default_message_id) { |
| 310 RegisterPreference( | 389 // If this fails, the pref service in use is a profile pref service, so the |
| 311 path, | 390 // sync status must be provided (see profile pref registration calls below). |
| 312 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id)); | 391 DCHECK(IsLocalStatePrefService(this)); |
| 392 RegisterPreference( |
| 393 path, |
| 394 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id), |
| 395 UNSYNCABLE_PREF); |
| 313 } | 396 } |
| 314 | 397 |
| 315 void PrefService::RegisterLocalizedDoublePref(const char* path, | 398 void PrefService::RegisterLocalizedDoublePref(const char* path, |
| 316 int locale_default_message_id) { | 399 int locale_default_message_id) { |
| 317 RegisterPreference( | 400 // If this fails, the pref service in use is a profile pref service, so the |
| 318 path, | 401 // sync status must be provided (see profile pref registration calls below). |
| 319 CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id)); | 402 DCHECK(IsLocalStatePrefService(this)); |
| 403 RegisterPreference( |
| 404 path, |
| 405 CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id), |
| 406 UNSYNCABLE_PREF); |
| 320 } | 407 } |
| 321 | 408 |
| 322 void PrefService::RegisterLocalizedStringPref(const char* path, | 409 void PrefService::RegisterLocalizedStringPref(const char* path, |
| 323 int locale_default_message_id) { | 410 int locale_default_message_id) { |
| 324 RegisterPreference( | 411 // If this fails, the pref service in use is a profile pref service, so the |
| 325 path, | 412 // sync status must be provided (see profile pref registration calls below). |
| 326 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id)); | 413 DCHECK(IsLocalStatePrefService(this)); |
| 414 RegisterPreference( |
| 415 path, |
| 416 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id), |
| 417 UNSYNCABLE_PREF); |
| 418 } |
| 419 |
| 420 void PrefService::RegisterInt64Pref(const char* path, int64 default_value) { |
| 421 // If this fails, the pref service in use is a profile pref service, so the |
| 422 // sync status must be provided (see profile pref registration calls below). |
| 423 DCHECK(IsLocalStatePrefService(this)); |
| 424 RegisterPreference( |
| 425 path, |
| 426 Value::CreateStringValue(base::Int64ToString(default_value)), |
| 427 UNSYNCABLE_PREF); |
| 428 } |
| 429 |
| 430 // Profile prefs (must use the sync_status variable). |
| 431 void PrefService::RegisterBooleanPref(const char* path, |
| 432 bool default_value, |
| 433 PrefSyncStatus sync_status) { |
| 434 DCHECK(IsProfilePrefService(this)); |
| 435 RegisterPreference(path, |
| 436 Value::CreateBooleanValue(default_value), |
| 437 sync_status); |
| 438 } |
| 439 |
| 440 void PrefService::RegisterIntegerPref(const char* path, |
| 441 int default_value, |
| 442 PrefSyncStatus sync_status) { |
| 443 DCHECK(IsProfilePrefService(this)); |
| 444 RegisterPreference(path, |
| 445 Value::CreateIntegerValue(default_value), |
| 446 sync_status); |
| 447 } |
| 448 |
| 449 void PrefService::RegisterDoublePref(const char* path, |
| 450 double default_value, |
| 451 PrefSyncStatus sync_status) { |
| 452 DCHECK(IsProfilePrefService(this)); |
| 453 RegisterPreference(path, |
| 454 Value::CreateDoubleValue(default_value), |
| 455 sync_status); |
| 456 } |
| 457 |
| 458 void PrefService::RegisterStringPref(const char* path, |
| 459 const std::string& default_value, |
| 460 PrefSyncStatus sync_status) { |
| 461 DCHECK(IsProfilePrefService(this)); |
| 462 RegisterPreference(path, |
| 463 Value::CreateStringValue(default_value), |
| 464 sync_status); |
| 465 } |
| 466 |
| 467 void PrefService::RegisterFilePathPref(const char* path, |
| 468 const FilePath& default_value, |
| 469 PrefSyncStatus sync_status) { |
| 470 DCHECK(IsProfilePrefService(this)); |
| 471 RegisterPreference(path, |
| 472 Value::CreateStringValue(default_value.value()), |
| 473 sync_status); |
| 474 } |
| 475 |
| 476 void PrefService::RegisterListPref(const char* path, |
| 477 PrefSyncStatus sync_status) { |
| 478 DCHECK(IsProfilePrefService(this)); |
| 479 RegisterPreference(path, new ListValue(), sync_status); |
| 480 } |
| 481 |
| 482 void PrefService::RegisterListPref(const char* path, |
| 483 ListValue* default_value, |
| 484 PrefSyncStatus sync_status) { |
| 485 DCHECK(IsProfilePrefService(this)); |
| 486 RegisterPreference(path, default_value, sync_status); |
| 487 } |
| 488 |
| 489 void PrefService::RegisterDictionaryPref(const char* path, |
| 490 PrefSyncStatus sync_status) { |
| 491 DCHECK(IsProfilePrefService(this)); |
| 492 RegisterPreference(path, new DictionaryValue(), sync_status); |
| 493 } |
| 494 |
| 495 void PrefService::RegisterDictionaryPref(const char* path, |
| 496 DictionaryValue* default_value, |
| 497 PrefSyncStatus sync_status) { |
| 498 DCHECK(IsProfilePrefService(this)); |
| 499 RegisterPreference(path, default_value, sync_status); |
| 500 } |
| 501 |
| 502 void PrefService::RegisterLocalizedBooleanPref(const char* path, |
| 503 int locale_default_message_id, |
| 504 PrefSyncStatus sync_status) { |
| 505 DCHECK(IsProfilePrefService(this)); |
| 506 RegisterPreference( |
| 507 path, |
| 508 CreateLocaleDefaultValue(Value::TYPE_BOOLEAN,locale_default_message_id), |
| 509 sync_status); |
| 510 } |
| 511 |
| 512 void PrefService::RegisterLocalizedIntegerPref(const char* path, |
| 513 int locale_default_message_id, |
| 514 PrefSyncStatus sync_status) { |
| 515 DCHECK(IsProfilePrefService(this)); |
| 516 RegisterPreference( |
| 517 path, |
| 518 CreateLocaleDefaultValue(Value::TYPE_INTEGER, locale_default_message_id), |
| 519 sync_status); |
| 520 } |
| 521 |
| 522 void PrefService::RegisterLocalizedDoublePref(const char* path, |
| 523 int locale_default_message_id, |
| 524 PrefSyncStatus sync_status) { |
| 525 DCHECK(IsProfilePrefService(this)); |
| 526 RegisterPreference( |
| 527 path, |
| 528 CreateLocaleDefaultValue(Value::TYPE_DOUBLE, locale_default_message_id), |
| 529 sync_status); |
| 530 } |
| 531 |
| 532 void PrefService::RegisterLocalizedStringPref(const char* path, |
| 533 int locale_default_message_id, |
| 534 PrefSyncStatus sync_status) { |
| 535 DCHECK(IsProfilePrefService(this)); |
| 536 RegisterPreference( |
| 537 path, |
| 538 CreateLocaleDefaultValue(Value::TYPE_STRING, locale_default_message_id), |
| 539 sync_status); |
| 540 } |
| 541 |
| 542 void PrefService::RegisterInt64Pref(const char* path, |
| 543 int64 default_value, |
| 544 PrefSyncStatus sync_status) { |
| 545 DCHECK(IsProfilePrefService(this)); |
| 546 RegisterPreference( |
| 547 path, |
| 548 Value::CreateStringValue(base::Int64ToString(default_value)), |
| 549 sync_status); |
| 327 } | 550 } |
| 328 | 551 |
| 329 bool PrefService::GetBoolean(const char* path) const { | 552 bool PrefService::GetBoolean(const char* path) const { |
| 330 DCHECK(CalledOnValidThread()); | 553 DCHECK(CalledOnValidThread()); |
| 331 | 554 |
| 332 bool result = false; | 555 bool result = false; |
| 333 | 556 |
| 334 const Preference* pref = FindPreference(path); | 557 const Preference* pref = FindPreference(path); |
| 335 if (!pref) { | 558 if (!pref) { |
| 336 NOTREACHED() << "Trying to read an unregistered pref: " << path; | 559 NOTREACHED() << "Trying to read an unregistered pref: " << path; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 void PrefService::AddPrefObserver(const char* path, | 702 void PrefService::AddPrefObserver(const char* path, |
| 480 NotificationObserver* obs) { | 703 NotificationObserver* obs) { |
| 481 pref_notifier_->AddPrefObserver(path, obs); | 704 pref_notifier_->AddPrefObserver(path, obs); |
| 482 } | 705 } |
| 483 | 706 |
| 484 void PrefService::RemovePrefObserver(const char* path, | 707 void PrefService::RemovePrefObserver(const char* path, |
| 485 NotificationObserver* obs) { | 708 NotificationObserver* obs) { |
| 486 pref_notifier_->RemovePrefObserver(path, obs); | 709 pref_notifier_->RemovePrefObserver(path, obs); |
| 487 } | 710 } |
| 488 | 711 |
| 489 void PrefService::RegisterPreference(const char* path, Value* default_value) { | 712 void PrefService::RegisterPreference(const char* path, |
| 713 Value* default_value, |
| 714 PrefSyncStatus sync_status) { |
| 490 DCHECK(CalledOnValidThread()); | 715 DCHECK(CalledOnValidThread()); |
| 491 | 716 |
| 492 // The main code path takes ownership, but most don't. We'll be safe. | 717 // The main code path takes ownership, but most don't. We'll be safe. |
| 493 scoped_ptr<Value> scoped_value(default_value); | 718 scoped_ptr<Value> scoped_value(default_value); |
| 494 | 719 |
| 495 if (FindPreference(path)) { | 720 if (FindPreference(path)) { |
| 496 NOTREACHED() << "Tried to register duplicate pref " << path; | 721 NOTREACHED() << "Tried to register duplicate pref " << path; |
| 497 return; | 722 return; |
| 498 } | 723 } |
| 499 | 724 |
| 500 Value::ValueType orig_type = default_value->GetType(); | 725 Value::ValueType orig_type = default_value->GetType(); |
| 501 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << | 726 DCHECK(orig_type != Value::TYPE_NULL && orig_type != Value::TYPE_BINARY) << |
| 502 "invalid preference type: " << orig_type; | 727 "invalid preference type: " << orig_type; |
| 503 | 728 |
| 504 // Hand off ownership. | 729 // Hand off ownership. |
| 505 default_store_->SetDefaultValue(path, scoped_value.release()); | 730 default_store_->SetDefaultValue(path, scoped_value.release()); |
| 731 |
| 732 // Register with sync if necessary. |
| 733 if (sync_status == SYNCABLE_PREF && pref_sync_associator_.get()) |
| 734 pref_sync_associator_->RegisterPref(path); |
| 506 } | 735 } |
| 507 | 736 |
| 508 void PrefService::ClearPref(const char* path) { | 737 void PrefService::ClearPref(const char* path) { |
| 509 DCHECK(CalledOnValidThread()); | 738 DCHECK(CalledOnValidThread()); |
| 510 | 739 |
| 511 const Preference* pref = FindPreference(path); | 740 const Preference* pref = FindPreference(path); |
| 512 if (!pref) { | 741 if (!pref) { |
| 513 NOTREACHED() << "Trying to clear an unregistered pref: " << path; | 742 NOTREACHED() << "Trying to clear an unregistered pref: " << path; |
| 514 return; | 743 return; |
| 515 } | 744 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 554 } | 783 } |
| 555 std::string result("0"); | 784 std::string result("0"); |
| 556 bool rv = pref->GetValue()->GetAsString(&result); | 785 bool rv = pref->GetValue()->GetAsString(&result); |
| 557 DCHECK(rv); | 786 DCHECK(rv); |
| 558 | 787 |
| 559 int64 val; | 788 int64 val; |
| 560 base::StringToInt64(result, &val); | 789 base::StringToInt64(result, &val); |
| 561 return val; | 790 return val; |
| 562 } | 791 } |
| 563 | 792 |
| 564 void PrefService::RegisterInt64Pref(const char* path, int64 default_value) { | |
| 565 RegisterPreference( | |
| 566 path, Value::CreateStringValue(base::Int64ToString(default_value))); | |
| 567 } | |
| 568 | |
| 569 Value* PrefService::GetMutableUserPref(const char* path, | 793 Value* PrefService::GetMutableUserPref(const char* path, |
| 570 Value::ValueType type) { | 794 Value::ValueType type) { |
| 571 CHECK(type == Value::TYPE_DICTIONARY || type == Value::TYPE_LIST); | 795 CHECK(type == Value::TYPE_DICTIONARY || type == Value::TYPE_LIST); |
| 572 DCHECK(CalledOnValidThread()); | 796 DCHECK(CalledOnValidThread()); |
| 573 DLOG_IF(WARNING, IsManagedPreference(path)) << | 797 DLOG_IF(WARNING, IsManagedPreference(path)) << |
| 574 "Attempt to change managed preference " << path; | 798 "Attempt to change managed preference " << path; |
| 575 | 799 |
| 576 const Preference* pref = FindPreference(path); | 800 const Preference* pref = FindPreference(path); |
| 577 if (!pref) { | 801 if (!pref) { |
| 578 NOTREACHED() << "Trying to get an unregistered pref: " << path; | 802 NOTREACHED() << "Trying to get an unregistered pref: " << path; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 if (pref->GetType() != new_value->GetType()) { | 843 if (pref->GetType() != new_value->GetType()) { |
| 620 NOTREACHED() << "Trying to set pref " << path | 844 NOTREACHED() << "Trying to set pref " << path |
| 621 << " of type " << pref->GetType() | 845 << " of type " << pref->GetType() |
| 622 << " to value of type " << new_value->GetType(); | 846 << " to value of type " << new_value->GetType(); |
| 623 return; | 847 return; |
| 624 } | 848 } |
| 625 | 849 |
| 626 user_pref_store_->SetValue(path, owned_value.release()); | 850 user_pref_store_->SetValue(path, owned_value.release()); |
| 627 } | 851 } |
| 628 | 852 |
| 853 SyncableService* PrefService::GetSyncableService() { |
| 854 return pref_sync_associator_.get(); |
| 855 } |
| 856 |
| 629 /////////////////////////////////////////////////////////////////////////////// | 857 /////////////////////////////////////////////////////////////////////////////// |
| 630 // PrefService::Preference | 858 // PrefService::Preference |
| 631 | 859 |
| 632 PrefService::Preference::Preference(const PrefService* service, | 860 PrefService::Preference::Preference(const PrefService* service, |
| 633 const char* name, | 861 const char* name, |
| 634 Value::ValueType type) | 862 Value::ValueType type) |
| 635 : name_(name), | 863 : name_(name), |
| 636 type_(type), | 864 type_(type), |
| 637 pref_service_(service) { | 865 pref_service_(service) { |
| 638 DCHECK(name); | 866 DCHECK(name); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); | 910 return pref_value_store()->PrefValueFromDefaultStore(name_.c_str()); |
| 683 } | 911 } |
| 684 | 912 |
| 685 bool PrefService::Preference::IsUserModifiable() const { | 913 bool PrefService::Preference::IsUserModifiable() const { |
| 686 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); | 914 return pref_value_store()->PrefValueUserModifiable(name_.c_str()); |
| 687 } | 915 } |
| 688 | 916 |
| 689 bool PrefService::Preference::IsExtensionModifiable() const { | 917 bool PrefService::Preference::IsExtensionModifiable() const { |
| 690 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); | 918 return pref_value_store()->PrefValueExtensionModifiable(name_.c_str()); |
| 691 } | 919 } |
| OLD | NEW |