| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chrome_pref_service_factory.h" | 5 #include "chrome/browser/prefs/chrome_pref_service_factory.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 data.enforcement_level = PrefHashFilter::ENFORCE_ON_LOAD; | 346 data.enforcement_level = PrefHashFilter::ENFORCE_ON_LOAD; |
| 347 } | 347 } |
| 348 #endif | 348 #endif |
| 349 | 349 |
| 350 result.push_back(data); | 350 result.push_back(data); |
| 351 } | 351 } |
| 352 return result; | 352 return result; |
| 353 } | 353 } |
| 354 | 354 |
| 355 // Shows notifications which correspond to PersistentPrefStore's reading errors. | 355 // Shows notifications which correspond to PersistentPrefStore's reading errors. |
| 356 void HandleReadError(PersistentPrefStore::PrefReadError error) { | 356 void HandleReadError(const base::FilePath& pref_filename, |
| 357 PersistentPrefStore::PrefReadError error) { |
| 357 // Sample the histogram also for the successful case in order to get a | 358 // Sample the histogram also for the successful case in order to get a |
| 358 // baseline on the success rate in addition to the error distribution. | 359 // baseline on the success rate in addition to the error distribution. |
| 359 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, | 360 UMA_HISTOGRAM_ENUMERATION("PrefService.ReadError", error, |
| 360 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); | 361 PersistentPrefStore::PREF_READ_ERROR_MAX_ENUM); |
| 361 | 362 |
| 362 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { | 363 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE) { |
| 363 #if !defined(OS_CHROMEOS) | 364 #if !defined(OS_CHROMEOS) |
| 364 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for | 365 // Failing to load prefs on startup is a bad thing(TM). See bug 38352 for |
| 365 // an example problem that this can cause. | 366 // an example problem that this can cause. |
| 366 // Do some diagnosis and try to avoid losing data. | 367 // Do some diagnosis and try to avoid losing data. |
| 367 int message_id = 0; | 368 int message_id = 0; |
| 368 if (error <= PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE) { | 369 if (error <= PersistentPrefStore::PREF_READ_ERROR_JSON_TYPE) { |
| 369 message_id = IDS_PREFERENCES_CORRUPT_ERROR; | 370 message_id = IDS_PREFERENCES_CORRUPT_ERROR; |
| 370 } else if (error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) { | 371 } else if (error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) { |
| 371 message_id = IDS_PREFERENCES_UNREADABLE_ERROR; | 372 message_id = IDS_PREFERENCES_UNREADABLE_ERROR; |
| 372 } | 373 } |
| 373 | 374 |
| 374 if (message_id) { | 375 if (message_id) { |
| 375 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 376 BrowserThread::PostTask( |
| 376 base::Bind(&ShowProfileErrorDialog, | 377 BrowserThread::UI, FROM_HERE, |
| 377 PROFILE_ERROR_PREFERENCES, | 378 base::Bind(&ShowProfileErrorDialog, PROFILE_ERROR_PREFERENCES, |
| 378 message_id)); | 379 message_id, |
| 380 sql::DatabaseDiagnosticMap( |
| 381 {{"Corrupted file", |
| 382 pref_filename.BaseName().AsUTF8Unsafe()}}))); |
| 379 } | 383 } |
| 380 #else | 384 #else |
| 381 // On ChromeOS error screen with message about broken local state | 385 // On ChromeOS error screen with message about broken local state |
| 382 // will be displayed. | 386 // will be displayed. |
| 383 | 387 |
| 384 // A supplementary error message about broken local state - is included | 388 // A supplementary error message about broken local state - is included |
| 385 // in logs and user feedbacks. | 389 // in logs and user feedbacks. |
| 386 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE && | 390 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE && |
| 387 error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) { | 391 error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) { |
| 388 LOG(ERROR) << "An error happened during prefs loading: " << error; | 392 LOG(ERROR) << "An error happened during prefs loading: " << error; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 406 std::string seed; | 410 std::string seed; |
| 407 #if defined(GOOGLE_CHROME_BUILD) | 411 #if defined(GOOGLE_CHROME_BUILD) |
| 408 seed = ResourceBundle::GetSharedInstance().GetRawDataResource( | 412 seed = ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 409 IDR_PREF_HASH_SEED_BIN).as_string(); | 413 IDR_PREF_HASH_SEED_BIN).as_string(); |
| 410 #endif | 414 #endif |
| 411 return base::WrapUnique(new ProfilePrefStoreManager( | 415 return base::WrapUnique(new ProfilePrefStoreManager( |
| 412 profile_path, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, | 416 profile_path, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, |
| 413 seed, device_id, g_browser_process->local_state())); | 417 seed, device_id, g_browser_process->local_state())); |
| 414 } | 418 } |
| 415 | 419 |
| 416 void PrepareFactory( | 420 void PrepareFactory(const base::FilePath& pref_filename, |
| 417 syncable_prefs::PrefServiceSyncableFactory* factory, | 421 syncable_prefs::PrefServiceSyncableFactory* factory, |
| 418 policy::PolicyService* policy_service, | 422 policy::PolicyService* policy_service, |
| 419 SupervisedUserSettingsService* supervised_user_settings, | 423 SupervisedUserSettingsService* supervised_user_settings, |
| 420 scoped_refptr<PersistentPrefStore> user_pref_store, | 424 scoped_refptr<PersistentPrefStore> user_pref_store, |
| 421 const scoped_refptr<PrefStore>& extension_prefs, | 425 const scoped_refptr<PrefStore>& extension_prefs, |
| 422 bool async) { | 426 bool async) { |
| 423 policy::BrowserPolicyConnector* policy_connector = | 427 policy::BrowserPolicyConnector* policy_connector = |
| 424 g_browser_process->browser_policy_connector(); | 428 g_browser_process->browser_policy_connector(); |
| 425 factory->SetManagedPolicies(policy_service, policy_connector); | 429 factory->SetManagedPolicies(policy_service, policy_connector); |
| 426 factory->SetRecommendedPolicies(policy_service, policy_connector); | 430 factory->SetRecommendedPolicies(policy_service, policy_connector); |
| 427 | 431 |
| 428 #if defined(ENABLE_SUPERVISED_USERS) | 432 #if defined(ENABLE_SUPERVISED_USERS) |
| 429 if (supervised_user_settings) { | 433 if (supervised_user_settings) { |
| 430 scoped_refptr<PrefStore> supervised_user_prefs = make_scoped_refptr( | 434 scoped_refptr<PrefStore> supervised_user_prefs = make_scoped_refptr( |
| 431 new SupervisedUserPrefStore(supervised_user_settings)); | 435 new SupervisedUserPrefStore(supervised_user_settings)); |
| 432 // TODO(bauerb): Temporary CHECK while investigating | 436 // TODO(bauerb): Temporary CHECK while investigating |
| 433 // https://crbug.com/425785. Remove when that bug is fixed. | 437 // https://crbug.com/425785. Remove when that bug is fixed. |
| 434 CHECK(async || supervised_user_prefs->IsInitializationComplete()); | 438 CHECK(async || supervised_user_prefs->IsInitializationComplete()); |
| 435 factory->set_supervised_user_prefs(supervised_user_prefs); | 439 factory->set_supervised_user_prefs(supervised_user_prefs); |
| 436 } | 440 } |
| 437 #endif | 441 #endif |
| 438 | 442 |
| 439 factory->set_async(async); | 443 factory->set_async(async); |
| 440 factory->set_extension_prefs(extension_prefs); | 444 factory->set_extension_prefs(extension_prefs); |
| 441 factory->set_command_line_prefs(make_scoped_refptr( | 445 factory->set_command_line_prefs(make_scoped_refptr( |
| 442 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess()))); | 446 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess()))); |
| 443 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 447 factory->set_read_error_callback(base::Bind(&HandleReadError, pref_filename)); |
| 444 factory->set_user_prefs(user_pref_store); | 448 factory->set_user_prefs(user_pref_store); |
| 445 factory->SetPrefModelAssociatorClient( | 449 factory->SetPrefModelAssociatorClient( |
| 446 ChromePrefModelAssociatorClient::GetInstance()); | 450 ChromePrefModelAssociatorClient::GetInstance()); |
| 447 } | 451 } |
| 448 | 452 |
| 449 } // namespace | 453 } // namespace |
| 450 | 454 |
| 451 namespace chrome_prefs { | 455 namespace chrome_prefs { |
| 452 | 456 |
| 453 namespace internals { | 457 namespace internals { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 464 | 468 |
| 465 } // namespace internals | 469 } // namespace internals |
| 466 | 470 |
| 467 std::unique_ptr<PrefService> CreateLocalState( | 471 std::unique_ptr<PrefService> CreateLocalState( |
| 468 const base::FilePath& pref_filename, | 472 const base::FilePath& pref_filename, |
| 469 base::SequencedTaskRunner* pref_io_task_runner, | 473 base::SequencedTaskRunner* pref_io_task_runner, |
| 470 policy::PolicyService* policy_service, | 474 policy::PolicyService* policy_service, |
| 471 const scoped_refptr<PrefRegistry>& pref_registry, | 475 const scoped_refptr<PrefRegistry>& pref_registry, |
| 472 bool async) { | 476 bool async) { |
| 473 syncable_prefs::PrefServiceSyncableFactory factory; | 477 syncable_prefs::PrefServiceSyncableFactory factory; |
| 474 PrepareFactory(&factory, policy_service, | 478 PrepareFactory(pref_filename, &factory, policy_service, |
| 475 NULL, // supervised_user_settings | 479 NULL, // supervised_user_settings |
| 476 new JsonPrefStore(pref_filename, pref_io_task_runner, | 480 new JsonPrefStore(pref_filename, pref_io_task_runner, |
| 477 std::unique_ptr<PrefFilter>()), | 481 std::unique_ptr<PrefFilter>()), |
| 478 NULL, // extension_prefs | 482 NULL, // extension_prefs |
| 479 async); | 483 async); |
| 480 return factory.Create(pref_registry.get()); | 484 return factory.Create(pref_registry.get()); |
| 481 } | 485 } |
| 482 | 486 |
| 483 std::unique_ptr<syncable_prefs::PrefServiceSyncable> CreateProfilePrefs( | 487 std::unique_ptr<syncable_prefs::PrefServiceSyncable> CreateProfilePrefs( |
| 484 const base::FilePath& profile_path, | 488 const base::FilePath& profile_path, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 501 const base::Closure start_sync_flare_for_prefs = | 505 const base::Closure start_sync_flare_for_prefs = |
| 502 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path), | 506 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path), |
| 503 syncer::PREFERENCES); | 507 syncer::PREFERENCES); |
| 504 | 508 |
| 505 syncable_prefs::PrefServiceSyncableFactory factory; | 509 syncable_prefs::PrefServiceSyncableFactory factory; |
| 506 scoped_refptr<PersistentPrefStore> user_pref_store( | 510 scoped_refptr<PersistentPrefStore> user_pref_store( |
| 507 CreateProfilePrefStoreManager(profile_path) | 511 CreateProfilePrefStoreManager(profile_path) |
| 508 ->CreateProfilePrefStore(pref_io_task_runner, | 512 ->CreateProfilePrefStore(pref_io_task_runner, |
| 509 start_sync_flare_for_prefs, | 513 start_sync_flare_for_prefs, |
| 510 validation_delegate)); | 514 validation_delegate)); |
| 511 PrepareFactory(&factory, | 515 PrepareFactory(profile_path, &factory, policy_service, |
| 512 policy_service, | 516 supervised_user_settings, user_pref_store, extension_prefs, |
| 513 supervised_user_settings, | |
| 514 user_pref_store, | |
| 515 extension_prefs, | |
| 516 async); | 517 async); |
| 517 std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service = | 518 std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service = |
| 518 factory.CreateSyncable(pref_registry.get()); | 519 factory.CreateSyncable(pref_registry.get()); |
| 519 | 520 |
| 520 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); | 521 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); |
| 521 | 522 |
| 522 return pref_service; | 523 return pref_service; |
| 523 } | 524 } |
| 524 | 525 |
| 525 void DisableDomainCheckForTesting() { | 526 void DisableDomainCheckForTesting() { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 545 | 546 |
| 546 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 547 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
| 547 ProfilePrefStoreManager::RegisterProfilePrefs(registry); | 548 ProfilePrefStoreManager::RegisterProfilePrefs(registry); |
| 548 } | 549 } |
| 549 | 550 |
| 550 void RegisterPrefs(PrefRegistrySimple* registry) { | 551 void RegisterPrefs(PrefRegistrySimple* registry) { |
| 551 ProfilePrefStoreManager::RegisterPrefs(registry); | 552 ProfilePrefStoreManager::RegisterPrefs(registry); |
| 552 } | 553 } |
| 553 | 554 |
| 554 } // namespace chrome_prefs | 555 } // namespace chrome_prefs |
| OLD | NEW |