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 { ...@@ -1318,7 +1318,7 @@ bool PersonalDataManager::ShouldSuggestServerCards() const {
// seeing them in the dropdown. // seeing them in the dropdown.
if (!prefs::IsUserOptedInWalletSyncTransport( if (!prefs::IsUserOptedInWalletSyncTransport(
pref_service_, pref_service_,
sync_service_->GetAuthenticatedAccountInfo().account_id.id)) { sync_service_->GetAuthenticatedAccountInfo().account_id)) {
return false; return false;
} }
} }
...@@ -1844,8 +1844,7 @@ bool PersonalDataManager::ShouldShowCardsFromAccountOption() const { ...@@ -1844,8 +1844,7 @@ bool PersonalDataManager::ShouldShowCardsFromAccountOption() const {
features::kAutofillEnableAccountWalletStorage)); features::kAutofillEnableAccountWalletStorage));
bool is_opted_in = prefs::IsUserOptedInWalletSyncTransport( bool is_opted_in = prefs::IsUserOptedInWalletSyncTransport(
pref_service_, pref_service_, sync_service_->GetAuthenticatedAccountInfo().account_id);
sync_service_->GetAuthenticatedAccountInfo().account_id.id);
AutofillMetrics::LogWalletSyncTransportCardsOptIn(is_opted_in); AutofillMetrics::LogWalletSyncTransportCardsOptIn(is_opted_in);
...@@ -1857,7 +1856,7 @@ void PersonalDataManager::OnUserAcceptedCardsFromAccountOption() { ...@@ -1857,7 +1856,7 @@ void PersonalDataManager::OnUserAcceptedCardsFromAccountOption() {
DCHECK_EQ(AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled, DCHECK_EQ(AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled,
GetSyncSigninState()); GetSyncSigninState());
prefs::SetUserOptedInWalletSyncTransport( prefs::SetUserOptedInWalletSyncTransport(
pref_service_, sync_service_->GetAuthenticatedAccountInfo().account_id.id, pref_service_, sync_service_->GetAuthenticatedAccountInfo().account_id,
/*opted_in=*/true); /*opted_in=*/true);
} }
...@@ -1914,8 +1913,7 @@ void PersonalDataManager::OnUserAcceptedUpstreamOffer() { ...@@ -1914,8 +1913,7 @@ void PersonalDataManager::OnUserAcceptedUpstreamOffer() {
if (GetSyncSigninState() == if (GetSyncSigninState() ==
AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled) { AutofillSyncSigninState::kSignedInAndWalletSyncTransportEnabled) {
prefs::SetUserOptedInWalletSyncTransport( prefs::SetUserOptedInWalletSyncTransport(
pref_service_, pref_service_, sync_service_->GetAuthenticatedAccountInfo().account_id,
sync_service_->GetAuthenticatedAccountInfo().account_id.id,
/*opted_in=*/true); /*opted_in=*/true);
} }
} }
......
...@@ -67,6 +67,7 @@ jumbo_static_library("common") { ...@@ -67,6 +67,7 @@ jumbo_static_library("common") {
"//components/prefs", "//components/prefs",
"//components/variations", "//components/variations",
"//crypto", "//crypto",
"//google_apis:google_apis",
"//ui/base", "//ui/base",
"//ui/gfx/geometry", "//ui/gfx/geometry",
"//url", "//url",
...@@ -99,6 +100,7 @@ source_set("unit_tests") { ...@@ -99,6 +100,7 @@ source_set("unit_tests") {
"//components/pref_registry", "//components/pref_registry",
"//components/prefs", "//components/prefs",
"//components/prefs:test_support", "//components/prefs:test_support",
"//google_apis:google_apis",
"//testing/gmock", "//testing/gmock",
"//testing/gtest", "//testing/gtest",
"//url", "//url",
......
include_rules = [ include_rules = [
"+crypto/sha2.h", "+crypto/sha2.h",
"+google_apis/gaia/core_account_id.h",
] ]
...@@ -271,13 +271,13 @@ std::string GetAllProfilesValidityMapsEncodedString(const PrefService* prefs) { ...@@ -271,13 +271,13 @@ std::string GetAllProfilesValidityMapsEncodedString(const PrefService* prefs) {
} }
void SetUserOptedInWalletSyncTransport(PrefService* prefs, void SetUserOptedInWalletSyncTransport(PrefService* prefs,
const std::string& account_id, const CoreAccountId& account_id,
bool opted_in) { bool opted_in) {
// Get the hash of the account id. The hashing here is only a secondary bit of // 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 // obfuscation. The primary privacy guarantees are handled by clearing this
// whenever cookies are cleared. // whenever cookies are cleared.
std::string account_hash; 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); DictionaryPrefUpdate update(prefs, prefs::kAutofillSyncTransportOptIn);
int value = GetSyncTransportOptInBitFieldForAccount(prefs, account_hash); int value = GetSyncTransportOptInBitFieldForAccount(prefs, account_hash);
...@@ -300,10 +300,10 @@ void SetUserOptedInWalletSyncTransport(PrefService* prefs, ...@@ -300,10 +300,10 @@ void SetUserOptedInWalletSyncTransport(PrefService* prefs,
} }
bool IsUserOptedInWalletSyncTransport(const PrefService* prefs, bool IsUserOptedInWalletSyncTransport(const PrefService* prefs,
const std::string& account_id) { const CoreAccountId& account_id) {
// Get the hash of the account id. // Get the hash of the account id.
std::string account_hash; 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 whether the wallet opt-in bit is set.
return GetSyncTransportOptInBitFieldForAccount(prefs, account_hash) & return GetSyncTransportOptInBitFieldForAccount(prefs, account_hash) &
......
...@@ -7,6 +7,8 @@ ...@@ -7,6 +7,8 @@
#include <string> #include <string>
#include "google_apis/gaia/core_account_id.h"
class PrefService; class PrefService;
namespace user_prefs { namespace user_prefs {
...@@ -91,11 +93,11 @@ void SetPaymentsIntegrationEnabled(PrefService* prefs, bool enabled); ...@@ -91,11 +93,11 @@ void SetPaymentsIntegrationEnabled(PrefService* prefs, bool enabled);
std::string GetAllProfilesValidityMapsEncodedString(const PrefService* prefs); std::string GetAllProfilesValidityMapsEncodedString(const PrefService* prefs);
void SetUserOptedInWalletSyncTransport(PrefService* prefs, void SetUserOptedInWalletSyncTransport(PrefService* prefs,
const std::string& account_id, const CoreAccountId& account_id,
bool opted_in); bool opted_in);
bool IsUserOptedInWalletSyncTransport(const PrefService* prefs, bool IsUserOptedInWalletSyncTransport(const PrefService* prefs,
const std::string& account_id); const CoreAccountId& account_id);
void ClearSyncTransportOptIns(PrefService* prefs); void ClearSyncTransportOptIns(PrefService* prefs);
......
...@@ -78,8 +78,8 @@ TEST_F(AutofillPrefsTest, MigrateDeprecatedAutofillPrefs) { ...@@ -78,8 +78,8 @@ TEST_F(AutofillPrefsTest, MigrateDeprecatedAutofillPrefs) {
// Tests that setting and getting the AutofillSyncTransportOptIn works as // Tests that setting and getting the AutofillSyncTransportOptIn works as
// expected. // expected.
TEST_F(AutofillPrefsTest, WalletSyncTransportPref_GetAndSet) { TEST_F(AutofillPrefsTest, WalletSyncTransportPref_GetAndSet) {
const std::string account1 = "account1"; const CoreAccountId account1("account1");
const std::string account2 = "account2"; const CoreAccountId account2("account2");
// There should be no opt-in recorded at first. // There should be no opt-in recorded at first.
ASSERT_FALSE(IsUserOptedInWalletSyncTransport(pref_service(), account1)); ASSERT_FALSE(IsUserOptedInWalletSyncTransport(pref_service(), account1));
...@@ -129,7 +129,7 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_GetAndSet) { ...@@ -129,7 +129,7 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_GetAndSet) {
// Tests that AutofillSyncTransportOptIn is not stored using the plain text // Tests that AutofillSyncTransportOptIn is not stored using the plain text
// account id. // account id.
TEST_F(AutofillPrefsTest, WalletSyncTransportPref_UsesHashAccountId) { TEST_F(AutofillPrefsTest, WalletSyncTransportPref_UsesHashAccountId) {
const std::string account1 = "account1"; const CoreAccountId account1("account1");
// There should be no opt-in recorded at first. // There should be no opt-in recorded at first.
EXPECT_TRUE(pref_service() EXPECT_TRUE(pref_service()
...@@ -146,13 +146,13 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_UsesHashAccountId) { ...@@ -146,13 +146,13 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_UsesHashAccountId) {
auto* dictionary = auto* dictionary =
pref_service()->GetDictionary(prefs::kAutofillSyncTransportOptIn); pref_service()->GetDictionary(prefs::kAutofillSyncTransportOptIn);
EXPECT_EQ(NULL, 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. // Tests that clearing the AutofillSyncTransportOptIn works as expected.
TEST_F(AutofillPrefsTest, WalletSyncTransportPref_Clear) { TEST_F(AutofillPrefsTest, WalletSyncTransportPref_Clear) {
const std::string account1 = "account1"; const CoreAccountId account1("account1");
const std::string account2 = "account2"; const CoreAccountId account2("account2");
// There should be no opt-in recorded at first. // There should be no opt-in recorded at first.
EXPECT_TRUE(pref_service() EXPECT_TRUE(pref_service()
...@@ -181,7 +181,7 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_Clear) { ...@@ -181,7 +181,7 @@ TEST_F(AutofillPrefsTest, WalletSyncTransportPref_Clear) {
// Tests that the account id hash that we generate can be written and read from // Tests that the account id hash that we generate can be written and read from
// JSON properly. // JSON properly.
TEST_F(AutofillPrefsTest, WalletSyncTransportPref_CanBeSetAndReadFromJSON) { TEST_F(AutofillPrefsTest, WalletSyncTransportPref_CanBeSetAndReadFromJSON) {
const std::string account1 = "account1"; const CoreAccountId account1("account1");
// Set the opt-in for the first account. // Set the opt-in for the first account.
SetUserOptedInWalletSyncTransport(pref_service(), account1, true); 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