Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/prefs/chrome_pref_service_factory.cc

Issue 2107493002: Offer user to send feedback from profile error dialog (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Avoid a ref loop. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 std::string diagnostics("Corrupted file: ");
376 base::Bind(&ShowProfileErrorDialog, 377 diagnostics += pref_filename.DirName().BaseName().AsUTF8Unsafe() + "/" +
Lei Zhang 2016/07/16 00:35:21 Do you care that on Windows, this will be foo/bar,
afakhry 2016/07/18 17:43:51 No, it doesn't matter. All we need to know is the
377 PROFILE_ERROR_PREFERENCES, 378 pref_filename.BaseName().AsUTF8Unsafe() + "\n";
378 message_id)); 379 BrowserThread::PostTask(
380 BrowserThread::UI, FROM_HERE,
381 base::Bind(&ShowProfileErrorDialog, PROFILE_ERROR_PREFERENCES,
382 message_id, diagnostics));
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
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,
Lei Zhang 2016/07/16 00:35:21 Why is this the first param? Shouldn't it be |fact
afakhry 2016/07/18 17:43:51 Done.
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 DCHECK(async || supervised_user_prefs->IsInitializationComplete()); 436 DCHECK(async || supervised_user_prefs->IsInitializationComplete());
433 factory->set_supervised_user_prefs(supervised_user_prefs); 437 factory->set_supervised_user_prefs(supervised_user_prefs);
434 } 438 }
435 #endif 439 #endif
436 440
437 factory->set_async(async); 441 factory->set_async(async);
438 factory->set_extension_prefs(extension_prefs); 442 factory->set_extension_prefs(extension_prefs);
439 factory->set_command_line_prefs(make_scoped_refptr( 443 factory->set_command_line_prefs(make_scoped_refptr(
440 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess()))); 444 new CommandLinePrefStore(base::CommandLine::ForCurrentProcess())));
441 factory->set_read_error_callback(base::Bind(&HandleReadError)); 445 factory->set_read_error_callback(base::Bind(&HandleReadError, pref_filename));
442 factory->set_user_prefs(user_pref_store); 446 factory->set_user_prefs(user_pref_store);
443 factory->SetPrefModelAssociatorClient( 447 factory->SetPrefModelAssociatorClient(
444 ChromePrefModelAssociatorClient::GetInstance()); 448 ChromePrefModelAssociatorClient::GetInstance());
445 } 449 }
446 450
447 } // namespace 451 } // namespace
448 452
449 namespace chrome_prefs { 453 namespace chrome_prefs {
450 454
451 namespace internals { 455 namespace internals {
(...skipping 10 matching lines...) Expand all
462 466
463 } // namespace internals 467 } // namespace internals
464 468
465 std::unique_ptr<PrefService> CreateLocalState( 469 std::unique_ptr<PrefService> CreateLocalState(
466 const base::FilePath& pref_filename, 470 const base::FilePath& pref_filename,
467 base::SequencedTaskRunner* pref_io_task_runner, 471 base::SequencedTaskRunner* pref_io_task_runner,
468 policy::PolicyService* policy_service, 472 policy::PolicyService* policy_service,
469 const scoped_refptr<PrefRegistry>& pref_registry, 473 const scoped_refptr<PrefRegistry>& pref_registry,
470 bool async) { 474 bool async) {
471 syncable_prefs::PrefServiceSyncableFactory factory; 475 syncable_prefs::PrefServiceSyncableFactory factory;
472 PrepareFactory(&factory, policy_service, 476 PrepareFactory(pref_filename, &factory, policy_service,
473 NULL, // supervised_user_settings 477 NULL, // supervised_user_settings
474 new JsonPrefStore(pref_filename, pref_io_task_runner, 478 new JsonPrefStore(pref_filename, pref_io_task_runner,
475 std::unique_ptr<PrefFilter>()), 479 std::unique_ptr<PrefFilter>()),
476 NULL, // extension_prefs 480 NULL, // extension_prefs
477 async); 481 async);
478 return factory.Create(pref_registry.get()); 482 return factory.Create(pref_registry.get());
479 } 483 }
480 484
481 std::unique_ptr<syncable_prefs::PrefServiceSyncable> CreateProfilePrefs( 485 std::unique_ptr<syncable_prefs::PrefServiceSyncable> CreateProfilePrefs(
482 const base::FilePath& profile_path, 486 const base::FilePath& profile_path,
(...skipping 16 matching lines...) Expand all
499 const base::Closure start_sync_flare_for_prefs = 503 const base::Closure start_sync_flare_for_prefs =
500 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path), 504 base::Bind(sync_start_util::GetFlareForSyncableService(profile_path),
501 syncer::PREFERENCES); 505 syncer::PREFERENCES);
502 506
503 syncable_prefs::PrefServiceSyncableFactory factory; 507 syncable_prefs::PrefServiceSyncableFactory factory;
504 scoped_refptr<PersistentPrefStore> user_pref_store( 508 scoped_refptr<PersistentPrefStore> user_pref_store(
505 CreateProfilePrefStoreManager(profile_path) 509 CreateProfilePrefStoreManager(profile_path)
506 ->CreateProfilePrefStore(pref_io_task_runner, 510 ->CreateProfilePrefStore(pref_io_task_runner,
507 start_sync_flare_for_prefs, 511 start_sync_flare_for_prefs,
508 validation_delegate)); 512 validation_delegate));
509 PrepareFactory(&factory, 513 PrepareFactory(profile_path, &factory, policy_service,
510 policy_service, 514 supervised_user_settings, user_pref_store, extension_prefs,
511 supervised_user_settings,
512 user_pref_store,
513 extension_prefs,
514 async); 515 async);
515 std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service = 516 std::unique_ptr<syncable_prefs::PrefServiceSyncable> pref_service =
516 factory.CreateSyncable(pref_registry.get()); 517 factory.CreateSyncable(pref_registry.get());
517 518
518 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get()); 519 ConfigureDefaultSearchPrefMigrationToDictionaryValue(pref_service.get());
519 520
520 return pref_service; 521 return pref_service;
521 } 522 }
522 523
523 void DisableDomainCheckForTesting() { 524 void DisableDomainCheckForTesting() {
(...skipping 19 matching lines...) Expand all
543 544
544 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) { 545 void RegisterProfilePrefs(user_prefs::PrefRegistrySyncable* registry) {
545 ProfilePrefStoreManager::RegisterProfilePrefs(registry); 546 ProfilePrefStoreManager::RegisterProfilePrefs(registry);
546 } 547 }
547 548
548 void RegisterPrefs(PrefRegistrySimple* registry) { 549 void RegisterPrefs(PrefRegistrySimple* registry) {
549 ProfilePrefStoreManager::RegisterPrefs(registry); 550 ProfilePrefStoreManager::RegisterPrefs(registry);
550 } 551 }
551 552
552 } // namespace chrome_prefs 553 } // namespace chrome_prefs
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698