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", pref_filename.AsUTF8Unsafe()}}))); | |
michaeln
2016/07/09 03:00:38
is this a full path? probably don't want to includ
afakhry
2016/07/11 16:47:45
Done.
| |
379 } | 382 } |
380 #else | 383 #else |
381 // On ChromeOS error screen with message about broken local state | 384 // On ChromeOS error screen with message about broken local state |
382 // will be displayed. | 385 // will be displayed. |
383 | 386 |
384 // A supplementary error message about broken local state - is included | 387 // A supplementary error message about broken local state - is included |
385 // in logs and user feedbacks. | 388 // in logs and user feedbacks. |
386 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE && | 389 if (error != PersistentPrefStore::PREF_READ_ERROR_NONE && |
387 error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) { | 390 error != PersistentPrefStore::PREF_READ_ERROR_NO_FILE) { |
388 LOG(ERROR) << "An error happened during prefs loading: " << error; | 391 LOG(ERROR) << "An error happened during prefs loading: " << error; |
(...skipping 17 matching lines...) Expand all Loading... | |
406 std::string seed; | 409 std::string seed; |
407 #if defined(GOOGLE_CHROME_BUILD) | 410 #if defined(GOOGLE_CHROME_BUILD) |
408 seed = ResourceBundle::GetSharedInstance().GetRawDataResource( | 411 seed = ResourceBundle::GetSharedInstance().GetRawDataResource( |
409 IDR_PREF_HASH_SEED_BIN).as_string(); | 412 IDR_PREF_HASH_SEED_BIN).as_string(); |
410 #endif | 413 #endif |
411 return base::WrapUnique(new ProfilePrefStoreManager( | 414 return base::WrapUnique(new ProfilePrefStoreManager( |
412 profile_path, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, | 415 profile_path, GetTrackingConfiguration(), kTrackedPrefsReportingIDsCount, |
413 seed, device_id, g_browser_process->local_state())); | 416 seed, device_id, g_browser_process->local_state())); |
414 } | 417 } |
415 | 418 |
416 void PrepareFactory( | 419 void PrepareFactory(const base::FilePath& pref_filename, |
417 syncable_prefs::PrefServiceSyncableFactory* factory, | 420 syncable_prefs::PrefServiceSyncableFactory* factory, |
418 policy::PolicyService* policy_service, | 421 policy::PolicyService* policy_service, |
419 SupervisedUserSettingsService* supervised_user_settings, | 422 SupervisedUserSettingsService* supervised_user_settings, |
420 scoped_refptr<PersistentPrefStore> user_pref_store, | 423 scoped_refptr<PersistentPrefStore> user_pref_store, |
421 const scoped_refptr<PrefStore>& extension_prefs, | 424 const scoped_refptr<PrefStore>& extension_prefs, |
422 bool async) { | 425 bool async) { |
423 policy::BrowserPolicyConnector* policy_connector = | 426 policy::BrowserPolicyConnector* policy_connector = |
424 g_browser_process->browser_policy_connector(); | 427 g_browser_process->browser_policy_connector(); |
425 factory->SetManagedPolicies(policy_service, policy_connector); | 428 factory->SetManagedPolicies(policy_service, policy_connector); |
426 factory->SetRecommendedPolicies(policy_service, policy_connector); | 429 factory->SetRecommendedPolicies(policy_service, policy_connector); |
427 | 430 |
428 #if defined(ENABLE_SUPERVISED_USERS) | 431 #if defined(ENABLE_SUPERVISED_USERS) |
429 if (supervised_user_settings) { | 432 if (supervised_user_settings) { |
430 scoped_refptr<PrefStore> supervised_user_prefs = make_scoped_refptr( | 433 scoped_refptr<PrefStore> supervised_user_prefs = make_scoped_refptr( |
431 new SupervisedUserPrefStore(supervised_user_settings)); | 434 new SupervisedUserPrefStore(supervised_user_settings)); |
432 // TODO(bauerb): Temporary CHECK while investigating | 435 // TODO(bauerb): Temporary CHECK while investigating |
433 // https://crbug.com/425785. Remove when that bug is fixed. | 436 // https://crbug.com/425785. Remove when that bug is fixed. |
434 CHECK(async || supervised_user_prefs->IsInitializationComplete()); | 437 CHECK(async || supervised_user_prefs->IsInitializationComplete()); |
435 factory->set_supervised_user_prefs(supervised_user_prefs); | 438 factory->set_supervised_user_prefs(supervised_user_prefs); |
436 } | 439 } |
437 #endif | 440 #endif |
438 | 441 |
439 factory->set_async(async); | 442 factory->set_async(async); |
440 factory->set_extension_prefs(extension_prefs); | 443 factory->set_extension_prefs(extension_prefs); |
441 factory->set_command_line_prefs(make_scoped_refptr( | 444 factory->set_command_line_prefs(make_scoped_refptr( |
442 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess()))); | 445 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess()))); |
443 factory->set_read_error_callback(base::Bind(&HandleReadError)); | 446 factory->set_read_error_callback(base::Bind(&HandleReadError, pref_filename)); |
444 factory->set_user_prefs(user_pref_store); | 447 factory->set_user_prefs(user_pref_store); |
445 factory->SetPrefModelAssociatorClient( | 448 factory->SetPrefModelAssociatorClient( |
446 ChromePrefModelAssociatorClient::GetInstance()); | 449 ChromePrefModelAssociatorClient::GetInstance()); |
447 } | 450 } |
448 | 451 |
449 } // namespace | 452 } // namespace |
450 | 453 |
451 namespace chrome_prefs { | 454 namespace chrome_prefs { |
452 | 455 |
453 namespace internals { | 456 namespace internals { |
(...skipping 10 matching lines...) Expand all Loading... | |
464 | 467 |
465 } // namespace internals | 468 } // namespace internals |
466 | 469 |
467 std::unique_ptr<PrefService> CreateLocalState( | 470 std::unique_ptr<PrefService> CreateLocalState( |
468 const base::FilePath& pref_filename, | 471 const base::FilePath& pref_filename, |
469 base::SequencedTaskRunner* pref_io_task_runner, | 472 base::SequencedTaskRunner* pref_io_task_runner, |
470 policy::PolicyService* policy_service, | 473 policy::PolicyService* policy_service, |
471 const scoped_refptr<PrefRegistry>& pref_registry, | 474 const scoped_refptr<PrefRegistry>& pref_registry, |
472 bool async) { | 475 bool async) { |
473 syncable_prefs::PrefServiceSyncableFactory factory; | 476 syncable_prefs::PrefServiceSyncableFactory factory; |
474 PrepareFactory(&factory, policy_service, | 477 PrepareFactory(pref_filename, &factory, policy_service, |
475 NULL, // supervised_user_settings | 478 NULL, // supervised_user_settings |
476 new JsonPrefStore(pref_filename, pref_io_task_runner, | 479 new JsonPrefStore(pref_filename, pref_io_task_runner, |
477 std::unique_ptr<PrefFilter>()), | 480 std::unique_ptr<PrefFilter>()), |
478 NULL, // extension_prefs | 481 NULL, // extension_prefs |
479 async); | 482 async); |
480 return factory.Create(pref_registry.get()); | 483 return factory.Create(pref_registry.get()); |
481 } | 484 } |
482 | 485 |
483 std::unique_ptr<syncable_prefs::PrefServiceSyncable> CreateProfilePrefs( | 486 std::unique_ptr<syncable_prefs::PrefServiceSyncable> CreateProfilePrefs( |
484 const base::FilePath& profile_path, | 487 const base::FilePath& profile_path, |
(...skipping 16 matching lines...) Expand all Loading... | |
501 const base::Closure start_sync_flare_for_prefs = | 504 const base::Closure start_sync_flare_for_prefs = |
502 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path), | 505 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path), |
503 syncer::PREFERENCES); | 506 syncer::PREFERENCES); |
504 | 507 |
505 syncable_prefs::PrefServiceSyncableFactory factory; | 508 syncable_prefs::PrefServiceSyncableFactory factory; |
506 scoped_refptr<PersistentPrefStore> user_pref_store( | 509 scoped_refptr<PersistentPrefStore> user_pref_store( |
507 CreateProfilePrefStoreManager(profile_path) | 510 CreateProfilePrefStoreManager(profile_path) |
508 ->CreateProfilePrefStore(pref_io_task_runner, | 511 ->CreateProfilePrefStore(pref_io_task_runner, |
509 start_sync_flare_for_prefs, | 512 start_sync_flare_for_prefs, |
510 validation_delegate)); | 513 validation_delegate)); |
511 PrepareFactory(&factory, | 514 PrepareFactory(profile_path, &factory, policy_service, |
512 policy_service, | 515 supervised_user_settings, user_pref_store, extension_prefs, |
513 supervised_user_settings, | |
514 user_pref_store, | |
515 extension_prefs, | |
516 async); | 516 async); |
517 std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service = | 517 std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service = |
518 factory.CreateSyncable(pref_registry.get()); | 518 factory.CreateSyncable(pref_registry.get()); |
519 | 519 |
520 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); | 520 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); |
521 | 521 |
522 return pref_service; | 522 return pref_service; |
523 } | 523 } |
524 | 524 |
525 void DisableDomainCheckForTesting() { | 525 void DisableDomainCheckForTesting() { |
(...skipping 19 matching lines...) Expand all Loading... | |
545 | 545 |
546 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { | 546 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { |
547 ProfilePrefStoreManager::RegisterProfilePrefs(registry); | 547 ProfilePrefStoreManager::RegisterProfilePrefs(registry); |
548 } | 548 } |
549 | 549 |
550 void RegisterPrefs(PrefRegistrySimple* registry) { | 550 void RegisterPrefs(PrefRegistrySimple* registry) { |
551 ProfilePrefStoreManager::RegisterPrefs(registry); | 551 ProfilePrefStoreManager::RegisterPrefs(registry); |
552 } | 552 } |
553 | 553 |
554 } // namespace chrome_prefs | 554 } // namespace chrome_prefs |
OLD | NEW |