diff --git a/browser/password_manager/android/brave_password_manager_android_util_unittest.cc b/browser/password_manager/android/brave_password_manager_android_util_unittest.cc index 5322439432a0..f492ff6a6fe2 100644 --- a/browser/password_manager/android/brave_password_manager_android_util_unittest.cc +++ b/browser/password_manager/android/brave_password_manager_android_util_unittest.cc @@ -7,6 +7,7 @@ #include "base/files/file_util.h" #include "base/test/scoped_feature_list.h" #include "base/test/test_file_util.h" +#include "base/types/cxx23_to_underlying.h" #include "chrome/browser/password_manager/android/password_manager_android_util.h" #include "components/password_manager/core/browser/features/password_features.h" #include "components/password_manager/core/browser/password_manager_constants.h" @@ -37,7 +38,7 @@ class BravePasswordManagerAndroidUtilTest : public testing::Test { 0); pref_service_.registry()->RegisterIntegerPref( password_manager::prefs::kPasswordsUseUPMLocalAndSeparateStores, - static_cast(kOff)); + base::to_underlying(kOff)); pref_service_.registry()->RegisterBooleanPref( password_manager::prefs::kCredentialsEnableService, false); pref_service_.registry()->RegisterBooleanPref( @@ -90,7 +91,7 @@ TEST_F(BravePasswordManagerAndroidUtilTest, // This is a state of a local user that has just been migrated. pref_service()->SetInteger(kPasswordsUseUPMLocalAndSeparateStores, - static_cast(kOn)); + base::to_underlying(kOn)); pref_service()->SetBoolean( password_manager::prefs::kUserAcknowledgedLocalPasswordsMigrationWarning, true); @@ -119,9 +120,12 @@ TEST_F(BravePasswordManagerAndroidUtilTest, SetUsesSplitStoresAndUPMForLocal(pref_service(), login_db_directory()); - // SetUsesSplitStoresAndUPMForLocal must not delete DB on Brave + // Pref should be kOff, as we want keep using profile store instead of the + // account store, so the paswords will be synced from Android to Desktop EXPECT_EQ(pref_service()->GetInteger(kPasswordsUseUPMLocalAndSeparateStores), - static_cast(kOn)); + base::to_underlying(kOff)); + + // SetUsesSplitStoresAndUPMForLocal must not delete DB on Brave EXPECT_TRUE(PathExists(profile_db_path)); EXPECT_TRUE(PathExists(account_db_path)); EXPECT_TRUE(PathExists(profile_db_journal_path)); diff --git a/chromium_src/chrome/browser/password_manager/android/password_manager_android_util.cc b/chromium_src/chrome/browser/password_manager/android/password_manager_android_util.cc index 58ffe9936f53..76f989bff938 100644 --- a/chromium_src/chrome/browser/password_manager/android/password_manager_android_util.cc +++ b/chromium_src/chrome/browser/password_manager/android/password_manager_android_util.cc @@ -3,6 +3,9 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#include "components/password_manager/core/common/password_manager_pref_names.h" +#include "components/prefs/pref_service.h" + #define SetUsesSplitStoresAndUPMForLocal \ SetUsesSplitStoresAndUPMForLocal_ChromiumImpl @@ -12,11 +15,42 @@ namespace password_manager_android_util { +namespace { + +// On Android passwords can be saved into two stores: kAccountStore and +// kProfileStore. Account store is not synced through Chromium sync and supposed +// to store passwords at Google Account. Profile store is the store which saves +// passwords at profile and passwords are synced as before. Decision which store +// to use is made at PasswordSaveManagerImpl::GetPasswordStoreForSavingImpl. +// Finally, `kPasswordsUseUPMLocalAndSeparateStores` pref is checked. +// The stack: +// features_util::CanCreateAccountStore +// features_util::internal::CanAccountStorageBeEnabled +// features_util::internal::IsUserEligibleForAccountStorage +// features_util::GetDefaultPasswordStore +// PasswordFeatureManagerImpl::GetDefaultPasswordStore +// PasswordSaveManagerImpl::AccountStoreIsDefault +// PasswordSaveManagerImpl::GetPasswordStoreForSavingImpl +// There are two ways to make passwords be saved at the profile store and be +// synced: +// 1) override PasswordSaveManagerImpl::AccountStoreIsDefault +// 2) set `kPasswordsUseUPMLocalAndSeparateStores` pref to `kOff` +// Choosing option 2. +void ForcePasswordsProfileStore(PrefService* pref_service) { + pref_service->SetInteger( + password_manager::prefs::kPasswordsUseUPMLocalAndSeparateStores, + static_cast(UseUpmLocalAndSeparateStoresState::kOff)); +} + +} // namespace + // Prevent deleting passwords local DB during migration. // Happens at SetUsesSplitStoresAndUPMForLocal => // MaybeDeactivateSplitStoresAndLocalUpm => // MaybeDeleteLoginDataFiles void SetUsesSplitStoresAndUPMForLocal( PrefService* pref_service, - const base::FilePath& login_db_directory) {} + const base::FilePath& login_db_directory) { + ForcePasswordsProfileStore(pref_service); +} } // namespace password_manager_android_util