Commit fbe18ff6 authored by Tanmoy Mollik's avatar Tanmoy Mollik Committed by Commit Bot

Refactor autofill_prefs to use CoreAccountId

Bug: 959157
Change-Id: I8d46c9bb884ae4eb5986876cfbf290c63cd7899d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1892958Reviewed-by: default avatarMihai Sardarescu <msarda@chromium.org>
Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Tanmoy Mollik <triploblastic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#712561}
parent 7dd05f1c
......@@ -1318,7 +1318,7 @@ bool PersonalDataManager::ShouldSuggestServerCards() const {
// seeing them in the dropdown.
if (!prefs::IsUserOptedInWalletSyncTransport(
pref_service_,
sync_service_->GetAuthenticatedAccountInfo().account_id.id)) {
sync_service_->GetAuthenticatedAccountInfo().account_id)) {
return false;
}
}
......@@ -1844,8 +1844,7 @@ bool PersonalDataManager::ShouldShowCardsFromAccountOption() const {
features::kAutofillEnableAccountWalletStorage));
bool is_opted_in = prefs::IsUserOptedInWalletSyncTransport(
pref_service_,
sync_service_->GetAuthenticatedAccountInfo().account_id.id);
pref_service_, sync_service_->GetAuthenticatedAccountInfo().account_id);
AutofillMetrics::LogWalletSyncTransportCardsOptIn(is_opted_in);
......@@ -1857,7 +1856,7 @@ void PersonalDataManager::OnUserAcceptedCardsFromAccountOption() {
DCHECK_EQ(AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled,
GetSyncSigninState());
prefs::SetUserOptedInWalletSyncTransport(
pref_service_, sync_service_->GetAuthenticatedAccountInfo().account_id.id,
pref_service_, sync_service_->GetAuthenticatedAccountInfo().account_id,
/*opted_in=*/true);
}
......@@ -1914,8 +1913,7 @@ void PersonalDataManager::OnUserAcceptedUpstreamOffer() {
if (GetSyncSigninState() ==
AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled) {
prefs::SetUserOptedInWalletSyncTransport(
pref_service_,
sync_service_->GetAuthenticatedAccountInfo().account_id.id,
pref_service_, sync_service_->GetAuthenticatedAccountInfo().account_id,
/*opted_in=*/true);
}
}
......
......@@ -67,6 +67,7 @@ jumbo_static_library("common") {
"//components/prefs",
"//components/variations",
"//crypto",
"//google_apis:google_apis",
"//ui/base",
"//ui/gfx/geometry",
"//url",
......@@ -99,6 +100,7 @@ source_set("unit_tests") {
"//components/pref_registry",
"//components/prefs",
"//components/prefs:test_support",
"//google_apis:google_apis",
"//testing/gmock",
"//testing/gtest",
"//url",
......
include_rules = [
"+crypto/sha2.h",
"+google_apis/gaia/core_account_id.h",
]
......@@ -271,13 +271,13 @@ std::string GetAllProfilesValidityMapsEncodedString(const PrefService* prefs) {
}
void SetUserOptedInWalletSyncTransport(PrefService* prefs,
const std::string& account_id,
const CoreAccountId& account_id,
bool opted_in) {
// Get the hash of the account id. The hashing here is only a secondary bit of
// obfuscation. The primary privacy guarantees are handled by clearing this
// whenever cookies are cleared.
std::string account_hash;
base::Base64Encode(crypto::SHA256HashString(account_id), &account_hash);
base::Base64Encode(crypto::SHA256HashString(account_id.id), &account_hash);
DictionaryPrefUpdate update(prefs, prefs::kAutofillSyncTransportOptIn);
int value = GetSyncTransportOptInBitFieldForAccount(prefs, account_hash);
......@@ -300,10 +300,10 @@ void SetUserOptedInWalletSyncTransport(PrefService* prefs,
}
bool IsUserOptedInWalletSyncTransport(const PrefService* prefs,
const std::string& account_id) {
const CoreAccountId& account_id) {
// Get the hash of the account id.
std::string account_hash;
base::Base64Encode(crypto::SHA256HashString(account_id), &account_hash);
base::Base64Encode(crypto::SHA256HashString(account_id.id), &account_hash);
// Return whether the wallet opt-in bit is set.
return GetSyncTransportOptInBitFieldForAccount(prefs, account_hash) &
......
......@@ -7,6 +7,8 @@
#include <string>
#include "google_apis/gaia/core_account_id.h"
class PrefService;
namespace user_prefs {
......@@ -91,11 +93,11 @@ void SetPaymentsIntegrationEnabled(PrefService* prefs, bool enabled);
std::string GetAllProfilesValidityMapsEncodedString(const PrefService* prefs);
void SetUserOptedInWalletSyncTransport(PrefService* prefs,
const std::string& account_id,
const CoreAccountId& account_id,
bool opted_in);
bool IsUserOptedInWalletSyncTransport(const PrefService* prefs,
const std::string& account_id);
const CoreAccountId& account_id);
void ClearSyncTransportOptIns(PrefService* prefs);
......
......@@ -78,8 +78,8 @@ TEST_F(AutofillPrefsTest, MigrateDeprecatedAutofillPrefs) {
// Tests that setting and getting the AutofillSyncTransportOptIn works as
// expected.
TEST_F(AutofillPrefsTest, WalletSyncTransportPref_GetAndSet) {
const std::string account1 = "account1";
const std::string account2 = "account2";
const CoreAccountId account1("account1");
const CoreAccountId account2("account2");
// There should be no opt-in recorded at first.
ASSERT_FALSE(IsUserOptedInWalletSyncTransport(pref_service(), account1));
......@@ -129,7 +129,7 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_GetAndSet) {
// Tests that AutofillSyncTransportOptIn is not stored using the plain text
// account id.
TEST_F(AutofillPrefsTest, WalletSyncTransportPref_UsesHashAccountId) {
const std::string account1 = "account1";
const CoreAccountId account1("account1");
// There should be no opt-in recorded at first.
EXPECT_TRUE(pref_service()
......@@ -146,13 +146,13 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_UsesHashAccountId) {
auto* dictionary =
pref_service()->GetDictionary(prefs::kAutofillSyncTransportOptIn);
EXPECT_EQ(NULL,
dictionary->FindKeyOfType(account1, base::Value::Type::INTEGER));
dictionary->FindKeyOfType(account1.id, base::Value::Type::INTEGER));
}
// Tests that clearing the AutofillSyncTransportOptIn works as expected.
TEST_F(AutofillPrefsTest, WalletSyncTransportPref_Clear) {
const std::string account1 = "account1";
const std::string account2 = "account2";
const CoreAccountId account1("account1");
const CoreAccountId account2("account2");
// There should be no opt-in recorded at first.
EXPECT_TRUE(pref_service()
......@@ -181,7 +181,7 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_Clear) {
// Tests that the account id hash that we generate can be written and read from
// JSON properly.
TEST_F(AutofillPrefsTest, WalletSyncTransportPref_CanBeSetAndReadFromJSON) {
const std::string account1 = "account1";
const CoreAccountId account1("account1");
// Set the opt-in for the first account.
SetUserOptedInWalletSyncTransport(pref_service(), account1, true);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment