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

Side by Side 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, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/autofill/browser/address.h" 5 #include "components/autofill/browser/address.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "base/utf_string_conversions.h"
12 #include "components/autofill/browser/autofill_country.h" 13 #include "components/autofill/browser/autofill_country.h"
13 #include "components/autofill/browser/autofill_type.h" 14 #include "components/autofill/browser/autofill_type.h"
14 #include "components/autofill/browser/field_types.h" 15 #include "components/autofill/browser/field_types.h"
15 16
16 namespace { 17 namespace {
17 18
18 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0}; 19 const char16 kAddressSplitChars[] = {'-', ',', '#', '.', ' ', 0};
19 20
20 } // namespace 21 } // namespace
21 22
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 if (type == ADDRESS_HOME_CITY) 60 if (type == ADDRESS_HOME_CITY)
60 return city_; 61 return city_;
61 62
62 if (type == ADDRESS_HOME_STATE) 63 if (type == ADDRESS_HOME_STATE)
63 return state_; 64 return state_;
64 65
65 if (type == ADDRESS_HOME_ZIP) 66 if (type == ADDRESS_HOME_ZIP)
66 return zip_code_; 67 return zip_code_;
67 68
68 if (type == ADDRESS_HOME_COUNTRY) 69 if (type == ADDRESS_HOME_COUNTRY)
69 return Country(); 70 return country_code_;
70 71
71 return string16(); 72 return string16();
72 } 73 }
73 74
74 void Address::SetRawInfo(AutofillFieldType type, const string16& value) { 75 void Address::SetRawInfo(AutofillFieldType type, const string16& value) {
75 type = AutofillType::GetEquivalentFieldType(type); 76 type = AutofillType::GetEquivalentFieldType(type);
76 if (type == ADDRESS_HOME_LINE1) 77 if (type == ADDRESS_HOME_LINE1) {
77 line1_ = value; 78 line1_ = value;
78 else if (type == ADDRESS_HOME_LINE2) 79 } else if (type == ADDRESS_HOME_LINE2) {
79 line2_ = value; 80 line2_ = value;
80 else if (type == ADDRESS_HOME_CITY) 81 } else if (type == ADDRESS_HOME_CITY) {
81 city_ = value; 82 city_ = value;
82 else if (type == ADDRESS_HOME_STATE) 83 } else if (type == ADDRESS_HOME_STATE) {
83 state_ = value; 84 state_ = value;
84 else if (type == ADDRESS_HOME_COUNTRY) 85 } else if (type == ADDRESS_HOME_COUNTRY) {
85 // TODO(isherman): When setting the country, it should only be possible to 86 DCHECK(value.empty() || value.length() == 2u);
86 // call this with a country code, which means we should be able to drop the 87 country_code_ = value;
87 // call to GetCountryCode() below. 88 } else if (type == ADDRESS_HOME_ZIP) {
88 country_code_ =
89 AutofillCountry::GetCountryCode(value,
90 AutofillCountry::ApplicationLocale());
91 else if (type == ADDRESS_HOME_ZIP)
92 zip_code_ = value; 89 zip_code_ = value;
93 else 90 } else {
94 NOTREACHED(); 91 NOTREACHED();
92 }
95 } 93 }
96 94
97 void Address::GetMatchingTypes(const string16& text, 95 string16 Address::GetInfo(AutofillFieldType type,
98 const std::string& app_locale, 96 const std::string& app_locale) const {
99 FieldTypeSet* matching_types) const { 97 if (type == ADDRESS_HOME_COUNTRY && !country_code_.empty())
100 FormGroup::GetMatchingTypes(text, app_locale, matching_types); 98 return AutofillCountry(WideToASCII(country_code_), app_locale).name();
101 99
102 // Check to see if the |text| canonicalized as a country name is a match. 100 return GetRawInfo(type);
103 std::string country_code = AutofillCountry::GetCountryCode(text, app_locale);
104 if (!country_code.empty() && country_code_ == country_code)
105 matching_types->insert(ADDRESS_HOME_COUNTRY);
106 } 101 }
107 102
108 string16 Address::Country() const { 103 bool Address::SetInfo(AutofillFieldType type,
109 if (country_code().empty()) 104 const string16& value,
110 return string16(); 105 const std::string& app_locale) {
111 106 if (type == ADDRESS_HOME_COUNTRY && !value.empty()) {
112 std::string app_locale = AutofillCountry::ApplicationLocale(); 107 country_code_ =
113 return AutofillCountry(country_code(), app_locale).name(); 108 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.
109 } else {
110 SetRawInfo(type, value);
111 }
112 return true;
114 } 113 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698