Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(89)

Unified Diff: chrome/browser/autofill/android/personal_data_manager_android.cc

Issue 2413533003: [Payments] Normalize billing address before sending to the merchant. (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/autofill/android/personal_data_manager_android.cc
diff --git a/chrome/browser/autofill/android/personal_data_manager_android.cc b/chrome/browser/autofill/android/personal_data_manager_android.cc
index ad2750d4f802b6436035fdb4368650e99aea6bfb..bdb81b8e8a4cc7838b6c6246fe9978423497d900 100644
--- a/chrome/browser/autofill/android/personal_data_manager_android.cc
+++ b/chrome/browser/autofill/android/personal_data_manager_android.cc
@@ -285,7 +285,7 @@ class AddressNormalizationRequester
}
private:
- virtual ~AddressNormalizationRequester() {}
+ ~AddressNormalizationRequester() override {}
void OnRulesSuccessfullyLoaded() override {
if (personal_data_manager_android_) {
@@ -580,6 +580,8 @@ void PersonalDataManagerAndroid::SetProfileUseStatsForTesting(
ConvertJavaStringToUTF8(env, jguid));
profile->set_use_count(static_cast<size_t>(count));
profile->set_use_date(base::Time::FromTimeT(date));
+
+ personal_data_manager_->UpdateProfileForTest(*profile);
personal_data_manager_->NotifyPersonalDataChangedForTest();
}
@@ -623,6 +625,8 @@ void PersonalDataManagerAndroid::SetCreditCardUseStatsForTesting(
ConvertJavaStringToUTF8(env, jguid));
card->set_use_count(static_cast<size_t>(count));
card->set_use_date(base::Time::FromTimeT(date));
+
+ personal_data_manager_->UpdateCreditCardForTest(*card);
personal_data_manager_->NotifyPersonalDataChangedForTest();
}
@@ -662,11 +666,13 @@ void PersonalDataManagerAndroid::OnAddressValidationRulesLoaded(
const std::string& region_code,
bool success) {
// Check if an address normalization is pending.
- std::map<std::string, Delegate*>::iterator it =
+ std::map<std::string, std::vector<Delegate*>>::iterator it =
pending_normalization_.find(region_code);
if (it != pending_normalization_.end()) {
- // The Delegate will self delete after normalizing.
- it->second->OnRulesSuccessfullyLoaded();
+ // Each Delegate will self delete after normalizing.
+ std::vector<Delegate*> delegates = it->second;
+ for (size_t i = 0; i < it->second.size(); ++i)
+ it->second[i]->OnRulesSuccessfullyLoaded();
pending_normalization_.erase(it);
}
}
@@ -690,8 +696,17 @@ jboolean PersonalDataManagerAndroid::StartAddressNormalization(
} else {
// Setup the variables so the profile gets normalized when the rules have
// finished loading.
- pending_normalization_.insert(
- std::pair<std::string, Delegate*>(region_code, requester));
+ if (pending_normalization_.find(region_code) ==
+ pending_normalization_.end()) {
+ pending_normalization_.insert(
+ std::pair<std::string, std::vector<Delegate*>>(
+ region_code, std::vector<Delegate*>()));
+ }
+
+ std::map<std::string, std::vector<Delegate*>>::iterator it =
+ pending_normalization_.find(region_code);
+ it->second.push_back(requester);
+
return true;
}
}
@@ -723,9 +738,17 @@ ScopedJavaLocalRef<jobject> PersonalDataManagerAndroid::NormalizeAddress(
return CreateJavaProfileFromNative(env, *profile);
}
-void PersonalDataManagerAndroid::CancelPendingAddressNormalization(
+void PersonalDataManagerAndroid::CancelPendingAddressNormalizations(
JNIEnv* env,
const base::android::JavaParamRef<jobject>& unused_obj) {
+ // Delete all the pending normalization delegates.
+ for (auto it = pending_normalization_.begin();
+ it != pending_normalization_.end(); it++) {
+ for (size_t i = 0; i < it->second.size(); ++i) {
+ delete it->second[i];
+ }
+ }
+
pending_normalization_.clear();
}

Powered by Google App Engine
This is Rietveld 408576698