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

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

Issue 13697002: Make autofill's Address store country using the country code so that app locale isn't needed for th… (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/address.cc
===================================================================
--- components/autofill/browser/address.cc (revision 192389)
+++ components/autofill/browser/address.cc (working copy)
@@ -9,6 +9,7 @@
#include "base/basictypes.h"
#include "base/logging.h"
#include "base/string_util.h"
+#include "base/utf_string_conversions.h"
#include "components/autofill/browser/autofill_country.h"
#include "components/autofill/browser/autofill_type.h"
#include "components/autofill/browser/field_types.h"
@@ -66,49 +67,47 @@
return zip_code_;
if (type == ADDRESS_HOME_COUNTRY)
- return Country();
+ return country_code_;
return string16();
}
void Address::SetRawInfo(AutofillFieldType type, const string16& value) {
type = AutofillType::GetEquivalentFieldType(type);
- if (type == ADDRESS_HOME_LINE1)
+ if (type == ADDRESS_HOME_LINE1) {
line1_ = value;
- else if (type == ADDRESS_HOME_LINE2)
+ } else if (type == ADDRESS_HOME_LINE2) {
line2_ = value;
- else if (type == ADDRESS_HOME_CITY)
+ } else if (type == ADDRESS_HOME_CITY) {
city_ = value;
- else if (type == ADDRESS_HOME_STATE)
+ } else if (type == ADDRESS_HOME_STATE) {
state_ = value;
- else if (type == ADDRESS_HOME_COUNTRY)
- // TODO(isherman): When setting the country, it should only be possible to
- // call this with a country code, which means we should be able to drop the
- // call to GetCountryCode() below.
- country_code_ =
- AutofillCountry::GetCountryCode(value,
- AutofillCountry::ApplicationLocale());
- else if (type == ADDRESS_HOME_ZIP)
+ } else if (type == ADDRESS_HOME_COUNTRY) {
+ DCHECK(value.empty() || value.length() == 2u);
+ country_code_ = value;
+ } else if (type == ADDRESS_HOME_ZIP) {
zip_code_ = value;
- else
+ } else {
NOTREACHED();
+ }
}
-void Address::GetMatchingTypes(const string16& text,
- const std::string& app_locale,
- FieldTypeSet* matching_types) const {
- FormGroup::GetMatchingTypes(text, app_locale, matching_types);
+string16 Address::GetInfo(AutofillFieldType type,
+ const std::string& app_locale) const {
+ if (type == ADDRESS_HOME_COUNTRY && !country_code_.empty())
+ return AutofillCountry(WideToASCII(country_code_), app_locale).name();
- // Check to see if the |text| canonicalized as a country name is a match.
- std::string country_code = AutofillCountry::GetCountryCode(text, app_locale);
- if (!country_code.empty() && country_code_ == country_code)
- matching_types->insert(ADDRESS_HOME_COUNTRY);
+ return GetRawInfo(type);
}
-string16 Address::Country() const {
- if (country_code().empty())
- return string16();
-
- std::string app_locale = AutofillCountry::ApplicationLocale();
- return AutofillCountry(country_code(), app_locale).name();
+bool Address::SetInfo(AutofillFieldType type,
+ const string16& value,
+ const std::string& app_locale) {
+ if (type == ADDRESS_HOME_COUNTRY && !value.empty()) {
+ country_code_ =
+ ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale));
Ilya Sherman 2013/04/05 05:18:01 We should return false from this case if the conve
jam 2013/04/05 06:45:54 Done.
+ } else {
+ SetRawInfo(type, value);
+ }
+ return true;
}

Powered by Google App Engine
This is Rietveld 408576698