/chrome/browser/password_manager/password_manager_settings_service_factory.cc

https://github.com/chromium/chromium · C++ · 71 lines · 53 code · 9 blank · 9 comment · 1 complexity · ef6a285230bf555a5bb9b0e072d418a2 MD5 · raw file

  1. // Copyright 2022 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "chrome/browser/password_manager/password_manager_settings_service_factory.h"
  5. #include "chrome/browser/password_manager/password_manager_settings_service_impl.h"
  6. #include "chrome/browser/profiles/incognito_helpers.h"
  7. #include "chrome/browser/profiles/profile.h"
  8. #include "chrome/browser/sync/sync_service_factory.h"
  9. #include "components/keyed_service/content/browser_context_dependency_manager.h"
  10. #include "components/password_manager/core/browser/password_manager_settings_service.h"
  11. #include "components/password_manager/core/common/password_manager_features.h"
  12. #if BUILDFLAG(IS_ANDROID)
  13. #include "chrome/browser/password_manager/android/password_manager_settings_service_android_impl.h"
  14. #include "components/password_manager/core/common/password_manager_pref_names.h"
  15. #include "components/prefs/pref_service.h"
  16. #endif
  17. // static
  18. PasswordManagerSettingsService*
  19. PasswordManagerSettingsServiceFactory::GetForProfile(Profile* profile) {
  20. return static_cast<PasswordManagerSettingsService*>(
  21. GetInstance()->GetServiceForBrowserContext(profile, true));
  22. }
  23. // static
  24. PasswordManagerSettingsServiceFactory*
  25. PasswordManagerSettingsServiceFactory::GetInstance() {
  26. return base::Singleton<PasswordManagerSettingsServiceFactory>::get();
  27. }
  28. PasswordManagerSettingsServiceFactory::PasswordManagerSettingsServiceFactory()
  29. : BrowserContextKeyedServiceFactory(
  30. "PasswordManagerSettingsService",
  31. BrowserContextDependencyManager::GetInstance()) {
  32. DependsOn(SyncServiceFactory::GetInstance());
  33. }
  34. PasswordManagerSettingsServiceFactory::
  35. ~PasswordManagerSettingsServiceFactory() = default;
  36. KeyedService* PasswordManagerSettingsServiceFactory::BuildServiceInstanceFor(
  37. content::BrowserContext* context) const {
  38. Profile* profile = Profile::FromBrowserContext(context);
  39. #if BUILDFLAG(IS_ANDROID)
  40. if (password_manager::features::UsesUnifiedPasswordManagerUi()) {
  41. return new PasswordManagerSettingsServiceAndroidImpl(
  42. profile->GetPrefs(), SyncServiceFactory::GetForProfile(profile));
  43. }
  44. // Reset the migration pref in case the client is no longer in the enabled
  45. // group.
  46. profile->GetPrefs()->SetBoolean(
  47. password_manager::prefs::kSettingsMigratedToUPM, false);
  48. return new PasswordManagerSettingsServiceImpl(profile->GetPrefs());
  49. #else
  50. return new PasswordManagerSettingsServiceImpl(profile->GetPrefs());
  51. #endif
  52. }
  53. content::BrowserContext*
  54. PasswordManagerSettingsServiceFactory::GetBrowserContextToUse(
  55. content::BrowserContext* context) const {
  56. // As the service is used to read prefs and that checking them depends on
  57. // sync status it needs to be accessed as for the regular profile.
  58. return chrome::GetBrowserContextRedirectedInIncognito(context);
  59. }
  60. bool PasswordManagerSettingsServiceFactory::ServiceIsNULLWhileTesting() const {
  61. return true;
  62. }