#include "chrome/browser/password_manager/password_store_backend_factory.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/metrics/histogram_functions.h"
#include "base/task/bind_post_task.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "chrome/browser/password_manager/android/password_store_proxy_backend.h"
#include "components/password_manager/core/browser/affiliation/password_affiliation_source_adapter.h"
#include "components/password_manager/core/browser/features/password_features.h"
#include "components/password_manager/core/browser/password_manager_buildflags.h"
#include "components/password_manager/core/browser/password_store/login_database.h"
#include "components/password_manager/core/browser/password_store/password_store.h"
#include "components/password_manager/core/browser/password_store/password_store_backend.h"
#include "components/password_manager/core/browser/password_store/password_store_built_in_backend.h"
#include "components/password_manager/core/browser/password_store_factory_util.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#include "components/prefs/pref_service.h"
#if !BUILDFLAG(USE_LOGIN_DATABASE_AS_BACKEND)
#include "chrome/browser/password_manager/android/android_backend_with_double_deletion.h"
#include "chrome/browser/password_manager/android/password_manager_eviction_util.h"
#include "chrome/browser/password_manager/android/password_store_android_account_backend.h"
#include "chrome/browser/password_manager/android/password_store_android_local_backend.h"
#include "chrome/browser/password_manager/android/password_store_backend_migration_decorator.h"
#include "chrome/browser/password_manager/android/password_store_proxy_backend.h"
#include "components/password_manager/core/common/password_manager_pref_names.h"
#endif
#if BUILDFLAG(IS_ANDROID)
#include "chrome/browser/password_manager/android/password_manager_android_util.h"
#endif
#if BUILDFLAG(IS_WIN) || BUILDFLAG(IS_MAC)
#include "chrome/browser/policy/policy_path_parser.h"
#endif
namespace {
PasswordStoreBackend;
PasswordStoreBuiltInBackend;
#if !BUILDFLAG(USE_LOGIN_DATABASE_AS_BACKEND)
using password_manager::prefs::UseUpmLocalAndSeparateStoresState;
#endif
std::unique_ptr<PasswordStoreBackend> CreateProfilePasswordStoreBuiltInBackend(
const base::FilePath& login_db_directory,
PrefService* prefs,
os_crypt_async::OSCryptAsync* os_crypt_async) { … }
#if !BUILDFLAG(USE_LOGIN_DATABASE_AS_BACKEND)
std::unique_ptr<PasswordStoreBackend>
CreateProfilePasswordStoreBackendForUpmAndroid(
PrefService* prefs,
password_manager::PasswordAffiliationSourceAdapter&
password_affiliation_adapter,
const base::FilePath& login_db_directory,
os_crypt_async::OSCryptAsync* os_crypt_async) {
base::UmaHistogramBoolean(
"PasswordManager.PasswordStore.WasEnrolledInUPMWhenBackendWasCreated",
!prefs->GetBoolean(password_manager::prefs::
kUnenrolledFromGoogleMobileServicesDueToErrors));
auto useSplitStores =
static_cast<UseUpmLocalAndSeparateStoresState>(prefs->GetInteger(
password_manager::prefs::kPasswordsUseUPMLocalAndSeparateStores));
switch (useSplitStores) {
case UseUpmLocalAndSeparateStoresState::kOffAndMigrationPending:
return std::make_unique<
password_manager::PasswordStoreBackendMigrationDecorator>(
CreateProfilePasswordStoreBuiltInBackend(login_db_directory, prefs,
os_crypt_async),
std::make_unique<password_manager::PasswordStoreAndroidLocalBackend>(
prefs, password_affiliation_adapter),
prefs);
case UseUpmLocalAndSeparateStoresState::kOn:
if (base::FeatureList::IsEnabled(
password_manager::features::
kClearLoginDatabaseForAllMigratedUPMUsers)) {
return std::make_unique<
password_manager::PasswordStoreAndroidLocalBackend>(
prefs, password_affiliation_adapter);
}
return std::make_unique<AndroidBackendWithDoubleDeletion>(
CreateProfilePasswordStoreBuiltInBackend(login_db_directory, prefs,
os_crypt_async),
std::make_unique<password_manager::PasswordStoreAndroidLocalBackend>(
prefs, password_affiliation_adapter));
case UseUpmLocalAndSeparateStoresState::kOff: {
auto android_account_backend = std::make_unique<
password_manager::PasswordStoreAndroidAccountBackend>(
prefs, &password_affiliation_adapter,
password_manager::kProfileStore);
return std::make_unique<password_manager::PasswordStoreProxyBackend>(
CreateProfilePasswordStoreBuiltInBackend(login_db_directory, prefs,
os_crypt_async),
std::move(android_account_backend), prefs);
}
}
}
#endif
}
std::unique_ptr<PasswordStoreBackend> CreateProfilePasswordStoreBackend(
const base::FilePath& login_db_directory,
PrefService* prefs,
password_manager::PasswordAffiliationSourceAdapter&
password_affiliation_adapter,
os_crypt_async::OSCryptAsync* os_crypt_async) { … }
std::unique_ptr<PasswordStoreBackend> CreateAccountPasswordStoreBackend(
const base::FilePath& login_db_directory,
PrefService* prefs,
password_manager::UnsyncedCredentialsDeletionNotifier
unsynced_deletions_notifier,
os_crypt_async::OSCryptAsync* os_crypt_async) { … }