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

Unified Diff: components/autofill/browser/personal_data_manager.cc

Issue 13488009: Remove application locale cache in autofill code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 9 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: components/autofill/browser/personal_data_manager.cc
===================================================================
--- components/autofill/browser/personal_data_manager.cc (revision 192175)
+++ components/autofill/browser/personal_data_manager.cc (working copy)
@@ -15,7 +15,6 @@
#include "base/utf_string_conversions.h"
#include "chrome/common/chrome_notification_types.h"
#include "components/autofill/browser/autofill-inl.h"
-#include "components/autofill/browser/autofill_country.h"
#include "components/autofill/browser/autofill_field.h"
#include "components/autofill/browser/autofill_metrics.h"
#include "components/autofill/browser/form_group.h"
@@ -110,11 +109,12 @@
} // namespace
-PersonalDataManager::PersonalDataManager()
+PersonalDataManager::PersonalDataManager(const std::string& app_locale)
: browser_context_(NULL),
is_data_loaded_(false),
pending_profiles_query_(0),
pending_creditcards_query_(0),
+ app_locale_(app_locale),
metric_logger_(new AutofillMetrics),
has_logged_profile_count_(false) {}
@@ -218,7 +218,6 @@
// complete at the end.
PhoneNumber::PhoneCombineHelper home;
- const std::string app_locale = AutofillCountry::ApplicationLocale();
for (size_t i = 0; i < form.field_count(); ++i) {
const AutofillField* field = form.field(i);
string16 value = CollapseWhitespace(field->value, false);
@@ -246,7 +245,7 @@
DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type);
local_imported_credit_card->SetInfoForMonthInputType(value);
} else {
- local_imported_credit_card->SetInfo(field_type, value, app_locale);
+ local_imported_credit_card->SetInfo(field_type, value, app_locale_);
}
++importable_credit_card_fields;
} else {
@@ -255,7 +254,7 @@
// If the fields are not the phone fields in question home.SetInfo() is
// going to return false.
if (!home.SetInfo(field_type, value))
- imported_profile->SetInfo(field_type, value, app_locale);
+ imported_profile->SetInfo(field_type, value, app_locale_);
// Reject profiles with invalid country information.
if (field_type == ADDRESS_HOME_COUNTRY &&
@@ -269,9 +268,10 @@
// Construct the phone number. Reject the profile if the number is invalid.
if (imported_profile.get() && !home.IsEmpty()) {
string16 constructed_number;
- if (!home.ParseNumber(*imported_profile, app_locale, &constructed_number) ||
+ if (!home.ParseNumber(*imported_profile, app_locale_,
+ &constructed_number) ||
!imported_profile->SetInfo(PHONE_HOME_WHOLE_NUMBER, constructed_number,
- app_locale)) {
+ app_locale_)) {
imported_profile.reset();
}
}
@@ -296,7 +296,7 @@
iter != credit_cards_.end();
++iter) {
if ((*iter)->UpdateFromImportedCard(*local_imported_credit_card.get(),
- app_locale)) {
+ app_locale_)) {
merged_credit_card = true;
UpdateCreditCard(**iter);
local_imported_credit_card.reset();
@@ -324,7 +324,7 @@
if (browser_context_->IsOffTheRecord())
return;
- if (profile.IsEmpty())
+ if (profile.IsEmpty(app_locale_))
return;
// Don't add an existing profile.
@@ -354,7 +354,7 @@
if (!FindByGUID<AutofillProfile>(web_profiles_, profile.guid()))
return;
- if (profile.IsEmpty()) {
+ if (profile.IsEmpty(app_locale_)) {
RemoveByGUID(profile.guid());
return;
}
@@ -386,7 +386,7 @@
if (browser_context_->IsOffTheRecord())
return;
- if (credit_card.IsEmpty())
+ if (credit_card.IsEmpty(app_locale_))
return;
if (FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
@@ -415,7 +415,7 @@
if (!FindByGUID<CreditCard>(credit_cards_, credit_card.guid()))
return;
- if (credit_card.IsEmpty()) {
+ if (credit_card.IsEmpty(app_locale_)) {
RemoveByGUID(credit_card.guid());
return;
}
@@ -467,16 +467,15 @@
void PersonalDataManager::GetNonEmptyTypes(
FieldTypeSet* non_empty_types) {
- const std::string app_locale = AutofillCountry::ApplicationLocale();
const std::vector<AutofillProfile*>& profiles = GetProfiles();
for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin();
iter != profiles.end(); ++iter) {
- (*iter)->GetNonEmptyTypes(app_locale, non_empty_types);
+ (*iter)->GetNonEmptyTypes(app_locale_, non_empty_types);
}
for (ScopedVector<CreditCard>::const_iterator iter = credit_cards_.begin();
iter != credit_cards_.end(); ++iter) {
- (*iter)->GetNonEmptyTypes(app_locale, non_empty_types);
+ (*iter)->GetNonEmptyTypes(app_locale_, non_empty_types);
}
}
@@ -529,7 +528,6 @@
guid_pairs->clear();
const std::vector<AutofillProfile*>& profiles = GetProfiles();
- const std::string app_locale = AutofillCountry::ApplicationLocale();
std::vector<AutofillProfile*> matched_profiles;
for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin();
iter != profiles.end(); ++iter) {
@@ -537,7 +535,7 @@
// The value of the stored data for this field type in the |profile|.
std::vector<string16> multi_values;
- profile->GetMultiInfo(type, app_locale, &multi_values);
+ profile->GetMultiInfo(type, app_locale_, &multi_values);
for (size_t i = 0; i < multi_values.size(); ++i) {
if (!field_is_autofilled) {
@@ -602,13 +600,12 @@
std::vector<string16>* labels,
std::vector<string16>* icons,
std::vector<GUIDPair>* guid_pairs) {
- const std::string app_locale = AutofillCountry::ApplicationLocale();
for (std::vector<CreditCard*>::const_iterator iter = credit_cards().begin();
iter != credit_cards().end(); ++iter) {
CreditCard* credit_card = *iter;
// The value of the stored data for this field type in the |credit_card|.
- string16 creditcard_field_value = credit_card->GetInfo(type, app_locale);
+ string16 creditcard_field_value = credit_card->GetInfo(type, app_locale_);
if (!creditcard_field_value.empty() &&
StartsWith(creditcard_field_value, field_contents, false)) {
if (type == CREDIT_CARD_NUMBER)
@@ -617,7 +614,7 @@
string16 label;
if (credit_card->number().empty()) {
// If there is no CC number, return name to show something.
- label = credit_card->GetInfo(CREDIT_CARD_NAME, app_locale);
+ label = credit_card->GetInfo(CREDIT_CARD_NAME, app_locale_);
} else {
label = kCreditCardPrefix;
label.append(credit_card->LastFourDigits());
@@ -666,6 +663,7 @@
bool PersonalDataManager::MergeProfile(
const AutofillProfile& profile,
const std::vector<AutofillProfile*>& existing_profiles,
+ const std::string& app_locale,
std::vector<AutofillProfile>* merged_profiles) {
merged_profiles->clear();
@@ -682,7 +680,7 @@
StringToLowerASCII((*iter)->PrimaryValue()) ==
StringToLowerASCII(profile.PrimaryValue())) {
merged = true;
- (*iter)->OverwriteWithOrAddTo(profile);
+ (*iter)->OverwriteWithOrAddTo(profile, app_locale);
}
}
merged_profiles->push_back(**iter);
@@ -700,10 +698,14 @@
return;
// Remove empty profiles from input.
- profiles->erase(
- std::remove_if(profiles->begin(), profiles->end(),
- std::mem_fun_ref(&AutofillProfile::IsEmpty)),
- profiles->end());
+ for (std::vector<AutofillProfile>::iterator i = profiles->begin();
Ilya Sherman 2013/04/04 04:27:38 nit: Please use "it" for the iterator name.
jam 2013/04/04 17:58:12 Done.
jam 2013/04/04 17:58:12 Done.
+ i != profiles->end();) {
+ if (i->IsEmpty(app_locale_)) {
+ profiles->erase(i);
+ } else {
+ i++;
+ }
Ilya Sherman 2013/04/04 04:27:38 nit: No need for curly braces.
jam 2013/04/04 17:58:12 yeah, i prefer having them when there's an else. t
Ilya Sherman 2013/04/04 23:00:40 The style guide might not set a rule for this, but
+ }
// Ensure that profile labels are up to date. Currently, sync relies on
// labels to identify a profile.
@@ -760,11 +762,14 @@
return;
// Remove empty credit cards from input.
- credit_cards->erase(
- std::remove_if(
- credit_cards->begin(), credit_cards->end(),
- std::mem_fun_ref(&CreditCard::IsEmpty)),
- credit_cards->end());
+ for (std::vector<CreditCard>::iterator i = credit_cards->begin();
+ i != credit_cards->end();) {
Ilya Sherman 2013/04/04 04:27:38 nit: Please use "it" for the iterator name.
jam 2013/04/04 17:58:12 Done.
+ if (i->IsEmpty(app_locale_)) {
+ credit_cards->erase(i);
+ } else {
+ i++;
+ }
Ilya Sherman 2013/04/04 04:27:38 nit: No need for curly braces.
+ }
scoped_refptr<AutofillWebDataService> autofill_data(
AutofillWebDataService::FromBrowserContext(browser_context_));
@@ -902,12 +907,12 @@
for (std::vector<AutofillProfile*>::const_iterator iter =
auxiliary_profiles_.begin();
iter != auxiliary_profiles_.end(); ++iter) {
- if (imported_profile.IsSubsetOf(**iter))
+ if (imported_profile.IsSubsetOf(**iter, app_locale_))
return;
}
std::vector<AutofillProfile> profiles;
- MergeProfile(imported_profile, web_profiles_.get(), &profiles);
+ MergeProfile(imported_profile, web_profiles_.get(), app_locale_, &profiles);
SetProfiles(&profiles);
}
@@ -925,14 +930,13 @@
// Set to true if |imported_card| is merged into the credit card list.
bool merged = false;
- const std::string app_locale = AutofillCountry::ApplicationLocale();
std::vector<CreditCard> credit_cards;
for (std::vector<CreditCard*>::const_iterator card = credit_cards_.begin();
card != credit_cards_.end();
++card) {
// If |imported_card| has not yet been merged, check whether it should be
// with the current |card|.
- if (!merged && (*card)->UpdateFromImportedCard(imported_card, app_locale))
+ if (!merged && (*card)->UpdateFromImportedCard(imported_card, app_locale_))
merged = true;
credit_cards.push_back(**card);

Powered by Google App Engine
This is Rietveld 408576698