Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Android][Sync] Sync passwords from Android to Desktop (uplift to 1.74.x) #27351

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -37,7 +38,7 @@ class BravePasswordManagerAndroidUtilTest : public testing::Test {
0);
pref_service_.registry()->RegisterIntegerPref(
password_manager::prefs::kPasswordsUseUPMLocalAndSeparateStores,
static_cast<int>(kOff));
base::to_underlying(kOff));
pref_service_.registry()->RegisterBooleanPref(
password_manager::prefs::kCredentialsEnableService, false);
pref_service_.registry()->RegisterBooleanPref(
Expand Down Expand Up @@ -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<int>(kOn));
base::to_underlying(kOn));
pref_service()->SetBoolean(
password_manager::prefs::kUserAcknowledgedLocalPasswordsMigrationWarning,
true);
Expand Down Expand Up @@ -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<int>(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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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<int>(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
Loading