Commit cf9f80b0 authored by Roger McFarlane's avatar Roger McFarlane Committed by Commit Bot

[autofill] Base64 decode when parsing profile validity info.

The server generated profile validity priority pref is encoded as a
base64 encoded serialized proto within a pref string value.

Misc:
  - Fixes the name of a member variable (was missing trailing _)
  - Move impl of a method whose address is taken from .h to .cc

Bug: 913685
Change-Id: I6ddf194a54d536289b1fcb5a95067d24cb642f4c
Reviewed-on: https://chromium-review.googlesource.com/c/1371006
Commit-Queue: Roger McFarlane <rogerm@chromium.org>
Reviewed-by: default avatarSebastien Seguin-Gagnon <sebsg@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615874}
parent 18144b14
...@@ -878,13 +878,10 @@ void AutofillProfile::SetValidityState( ...@@ -878,13 +878,10 @@ void AutofillProfile::SetValidityState(
void AutofillProfile::UpdateServerValidityMap( void AutofillProfile::UpdateServerValidityMap(
const ProfileValidityMap& validity_map) const { const ProfileValidityMap& validity_map) const {
server_validity_states_.clear(); server_validity_states_.clear();
const auto& field_validity_states = validity_map.field_validity_states(); const auto& field_validity_states = validity_map.field_validity_states();
for (auto current_pair = field_validity_states.begin(); for (const auto& current_pair : field_validity_states) {
current_pair != field_validity_states.end(); ++current_pair) { const auto field_type = static_cast<ServerFieldType>(current_pair.first);
const auto& field_type = static_cast<ServerFieldType>(current_pair->first); const auto field_validity = static_cast<ValidityState>(current_pair.second);
const auto& field_validity =
static_cast<ValidityState>(current_pair->second);
server_validity_states_[field_type] = field_validity; server_validity_states_[field_type] = field_validity;
} }
} }
......
...@@ -1149,9 +1149,9 @@ std::vector<AutofillProfile*> PersonalDataManager::GetProfiles() const { ...@@ -1149,9 +1149,9 @@ std::vector<AutofillProfile*> PersonalDataManager::GetProfiles() const {
void PersonalDataManager::UpdateProfilesValidityMapsIfNeeded( void PersonalDataManager::UpdateProfilesValidityMapsIfNeeded(
const std::vector<AutofillProfile*>& profiles) { const std::vector<AutofillProfile*>& profiles) {
if (!profile_validities_need_update) if (!profile_validities_need_update_)
return; return;
profile_validities_need_update = false; profile_validities_need_update_ = false;
for (auto* profile : profiles) { for (auto* profile : profiles) {
profile->UpdateServerValidityMap(GetProfileValidityByGUID(profile->guid())); profile->UpdateServerValidityMap(GetProfileValidityByGUID(profile->guid()));
} }
...@@ -1230,7 +1230,7 @@ void PersonalDataManager::Refresh() { ...@@ -1230,7 +1230,7 @@ void PersonalDataManager::Refresh() {
LoadProfiles(); LoadProfiles();
LoadCreditCards(); LoadCreditCards();
LoadPaymentsCustomerData(); LoadPaymentsCustomerData();
profile_validities_need_update = true; profile_validities_need_update_ = true;
} }
std::vector<AutofillProfile*> PersonalDataManager::GetProfilesToSuggest() std::vector<AutofillProfile*> PersonalDataManager::GetProfilesToSuggest()
...@@ -1590,12 +1590,13 @@ const ProfileValidityMap& PersonalDataManager::GetProfileValidityByGUID( ...@@ -1590,12 +1590,13 @@ const ProfileValidityMap& PersonalDataManager::GetProfileValidityByGUID(
const std::string& guid) { const std::string& guid) {
static const ProfileValidityMap& empty_validity_map = ProfileValidityMap(); static const ProfileValidityMap& empty_validity_map = ProfileValidityMap();
if (!synced_profile_validity_) { if (!synced_profile_validity_) {
profile_validities_need_update = true; profile_validities_need_update_ = true;
synced_profile_validity_ = std::make_unique<UserProfileValidityMap>(); synced_profile_validity_ = std::make_unique<UserProfileValidityMap>();
if (!synced_profile_validity_->ParseFromString( if (!synced_profile_validity_->ParseFromString(
::autofill::prefs::GetAllProfilesValidityMapsEncodedString( ::autofill::prefs::GetAllProfilesValidityMapsEncodedString(
pref_service_))) pref_service_))) {
return empty_validity_map; return empty_validity_map;
}
} }
auto it = synced_profile_validity_->profile_validity().find(guid); auto it = synced_profile_validity_->profile_validity().find(guid);
...@@ -2708,4 +2709,9 @@ void PersonalDataManager::ApplyCardFixesAndCleanups() { ...@@ -2708,4 +2709,9 @@ void PersonalDataManager::ApplyCardFixesAndCleanups() {
ClearCreditCardNonSettingsOrigins(); // Ran everytime it is called. ClearCreditCardNonSettingsOrigins(); // Ran everytime it is called.
} }
void PersonalDataManager::ResetProfileValidity() {
synced_profile_validity_.reset();
profile_validities_need_update_ = true;
}
} // namespace autofill } // namespace autofill
...@@ -617,7 +617,7 @@ class PersonalDataManager : public KeyedService, ...@@ -617,7 +617,7 @@ class PersonalDataManager : public KeyedService,
base::ObserverList<PersonalDataManagerObserver>::Unchecked observers_; base::ObserverList<PersonalDataManagerObserver>::Unchecked observers_;
// |profile_valditiies_need_update| whenever the profile validities are out of // |profile_valditiies_need_update| whenever the profile validities are out of
bool profile_validities_need_update = true; bool profile_validities_need_update_ = true;
private: private:
// Saves |imported_credit_card| to the WebDB if it exists. Returns the guid of // Saves |imported_credit_card| to the WebDB if it exists. Returns the guid of
...@@ -746,10 +746,7 @@ class PersonalDataManager : public KeyedService, ...@@ -746,10 +746,7 @@ class PersonalDataManager : public KeyedService,
void ApplyCardFixesAndCleanups(); void ApplyCardFixesAndCleanups();
// Resets |synced_profile_validity_|. // Resets |synced_profile_validity_|.
void ResetProfileValidity() { void ResetProfileValidity();
synced_profile_validity_.reset();
profile_validities_need_update = true;
}
const std::string app_locale_; const std::string app_locale_;
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "base/base64.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "base/files/scoped_temp_dir.h" #include "base/files/scoped_temp_dir.h"
#include "base/guid.h" #include "base/guid.h"
...@@ -2138,6 +2139,7 @@ TEST_F(PersonalDataManagerTest, ...@@ -2138,6 +2139,7 @@ TEST_F(PersonalDataManagerTest,
profile_validity_map; profile_validity_map;
ASSERT_TRUE(user_profile_validity_map.SerializeToString( ASSERT_TRUE(user_profile_validity_map.SerializeToString(
&autofill_profile_validity)); &autofill_profile_validity));
base::Base64Encode(autofill_profile_validity, &autofill_profile_validity);
personal_data_->pref_service_->SetString(prefs::kAutofillProfileValidity, personal_data_->pref_service_->SetString(prefs::kAutofillProfileValidity,
autofill_profile_validity); autofill_profile_validity);
} }
...@@ -6752,6 +6754,7 @@ TEST_F(PersonalDataManagerTest, RequestProfileValidity) { ...@@ -6752,6 +6754,7 @@ TEST_F(PersonalDataManagerTest, RequestProfileValidity) {
// Empty validity map. // Empty validity map.
ASSERT_TRUE( ASSERT_TRUE(
user_profile_validity_map.SerializeToString(&autofill_profile_validity)); user_profile_validity_map.SerializeToString(&autofill_profile_validity));
base::Base64Encode(autofill_profile_validity, &autofill_profile_validity);
personal_data_->pref_service_->SetString(prefs::kAutofillProfileValidity, personal_data_->pref_service_->SetString(prefs::kAutofillProfileValidity,
autofill_profile_validity); autofill_profile_validity);
...@@ -6778,6 +6781,7 @@ TEST_F(PersonalDataManagerTest, RequestProfileValidity) { ...@@ -6778,6 +6781,7 @@ TEST_F(PersonalDataManagerTest, RequestProfileValidity) {
profile_validity_map; profile_validity_map;
ASSERT_TRUE( ASSERT_TRUE(
user_profile_validity_map.SerializeToString(&autofill_profile_validity)); user_profile_validity_map.SerializeToString(&autofill_profile_validity));
base::Base64Encode(autofill_profile_validity, &autofill_profile_validity);
personal_data_->pref_service_->SetString(prefs::kAutofillProfileValidity, personal_data_->pref_service_->SetString(prefs::kAutofillProfileValidity,
autofill_profile_validity); autofill_profile_validity);
...@@ -6792,6 +6796,7 @@ TEST_F(PersonalDataManagerTest, RequestProfileValidity) { ...@@ -6792,6 +6796,7 @@ TEST_F(PersonalDataManagerTest, RequestProfileValidity) {
profile_validity_map; profile_validity_map;
ASSERT_TRUE( ASSERT_TRUE(
user_profile_validity_map.SerializeToString(&autofill_profile_validity)); user_profile_validity_map.SerializeToString(&autofill_profile_validity));
base::Base64Encode(autofill_profile_validity, &autofill_profile_validity);
personal_data_->pref_service_->SetString(prefs::kAutofillProfileValidity, personal_data_->pref_service_->SetString(prefs::kAutofillProfileValidity,
autofill_profile_validity); autofill_profile_validity);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "components/autofill/core/common/autofill_prefs.h" #include "components/autofill/core/common/autofill_prefs.h"
#include "base/base64.h"
#include "components/pref_registry/pref_registry_syncable.h" #include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/prefs/scoped_user_pref_update.h" #include "components/prefs/scoped_user_pref_update.h"
...@@ -267,7 +268,10 @@ void SetPaymentsIntegrationEnabled(PrefService* prefs, bool enabled) { ...@@ -267,7 +268,10 @@ void SetPaymentsIntegrationEnabled(PrefService* prefs, bool enabled) {
} }
std::string GetAllProfilesValidityMapsEncodedString(const PrefService* prefs) { std::string GetAllProfilesValidityMapsEncodedString(const PrefService* prefs) {
return prefs->GetString(kAutofillProfileValidity); std::string value = prefs->GetString(kAutofillProfileValidity);
if (base::Base64Decode(value, &value))
return value;
return std::string();
} }
void SetUserOptedInWalletSyncTransport(PrefService* prefs, void SetUserOptedInWalletSyncTransport(PrefService* prefs,
......
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