OLD | NEW |
---|---|
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 Loading... | |
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(UTF16ToASCII(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 } |
Ilya Sherman
2013/04/05 07:18:41
Hmm, I missed that you removed this. I'm pretty s
jam
2013/04/05 07:35:35
Done. I didn't see that this code was used for use
| |
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) { |
106 if (type == ADDRESS_HOME_COUNTRY && !value.empty()) { | |
107 country_code_ = | |
108 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); | |
109 return !country_code_.empty(); | |
110 } | |
111 | 111 |
112 std::string app_locale = AutofillCountry::ApplicationLocale(); | 112 SetRawInfo(type, value); |
113 return AutofillCountry(country_code(), app_locale).name(); | 113 return true; |
114 } | 114 } |
OLD | NEW |