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

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: Addressed comments 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);
please use gerrit instead 2016/10/18 17:30:32 No tests here, so let's not add this call until we
sebsg 2016/10/18 22:44:32 Done.
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);
please use gerrit instead 2016/10/18 17:30:32 Ditto
sebsg 2016/10/18 22:44:32 Done.
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 =
please use gerrit instead 2016/10/18 17:30:32 s/std::map<std::string, std::vector<Delegate*>>::i
sebsg 2016/10/18 22:44:32 Done.
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.
please use gerrit instead 2016/10/18 17:30:32 Remove this comment, please.
sebsg 2016/10/18 22:44:32 Done.
+ std::vector<Delegate*> delegates = it->second;
please use gerrit instead 2016/10/18 17:30:32 std::vector<std::unique_ptr<Delegate>>
sebsg 2016/10/18 22:44:32 Done.
+ for (size_t i = 0; i < it->second.size(); ++i)
please use gerrit instead 2016/10/18 17:30:32 s/it->second/delegates/
sebsg 2016/10/18 22:44:32 Done.
+ it->second[i]->OnRulesSuccessfullyLoaded();
please use gerrit instead 2016/10/18 17:30:32 s/it->second/delegates/
sebsg 2016/10/18 22:44:32 Done.
pending_normalization_.erase(it);
please use gerrit instead 2016/10/18 17:30:32 This is the line that deletes the Delegate objects
sebsg 2016/10/18 22:44:32 Done.
}
}
@@ -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*>>(
please use gerrit instead 2016/10/18 17:30:32 pending_normalization_.insert(std::make_pair(regio
sebsg 2016/10/18 22:44:32 It seems you cannot use initializer lists with mov
+ 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();
please use gerrit instead 2016/10/18 17:30:32 Since PersonalDataManagerAndroid now owns all of t
sebsg 2016/10/18 22:44:32 Done.
+ 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