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

Side by Side Diff: components/autofill/core/browser/address.cc

Issue 22040002: [Autofill] Add a separate enumeration for HTML field type hints. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser test Created 7 years, 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/core/browser/address.h" 5 #include "components/autofill/core/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"
(...skipping 26 matching lines...) Expand all
37 line1_ = address.line1_; 37 line1_ = address.line1_;
38 line2_ = address.line2_; 38 line2_ = address.line2_;
39 city_ = address.city_; 39 city_ = address.city_;
40 state_ = address.state_; 40 state_ = address.state_;
41 country_code_ = address.country_code_; 41 country_code_ = address.country_code_;
42 zip_code_ = address.zip_code_; 42 zip_code_ = address.zip_code_;
43 return *this; 43 return *this;
44 } 44 }
45 45
46 base::string16 Address::GetRawInfo(ServerFieldType type) const { 46 base::string16 Address::GetRawInfo(ServerFieldType type) const {
47 type = AutofillType::GetEquivalentFieldType(type); 47 // TODO(isherman): Is GetStorableType even necessary?
48 if (type == ADDRESS_HOME_LINE1) 48 switch (AutofillType(type).GetStorableType()) {
49 return line1_; 49 case ADDRESS_HOME_LINE1:
50 return line1_;
50 51
51 if (type == ADDRESS_HOME_LINE2) 52 case ADDRESS_HOME_LINE2:
52 return line2_; 53 return line2_;
53 54
54 if (type == ADDRESS_HOME_CITY) 55 case ADDRESS_HOME_CITY:
55 return city_; 56 return city_;
56 57
57 if (type == ADDRESS_HOME_STATE) 58 case ADDRESS_HOME_STATE:
58 return state_; 59 return state_;
59 60
60 if (type == ADDRESS_HOME_ZIP) 61 case ADDRESS_HOME_ZIP:
61 return zip_code_; 62 return zip_code_;
62 63
63 if (type == ADDRESS_HOME_COUNTRY) 64 case ADDRESS_HOME_COUNTRY:
64 return country_code_; 65 return country_code_;
65 66
66 return base::string16(); 67 default:
68 return base::string16();
69 }
67 } 70 }
68 71
69 void Address::SetRawInfo(ServerFieldType type, const base::string16& value) { 72 void Address::SetRawInfo(ServerFieldType type, const base::string16& value) {
70 type = AutofillType::GetEquivalentFieldType(type); 73 // TODO(isherman): Is GetStorableType even necessary?
71 if (type == ADDRESS_HOME_LINE1) { 74 switch (AutofillType(type).GetStorableType()) {
72 line1_ = value; 75 case ADDRESS_HOME_LINE1:
73 } else if (type == ADDRESS_HOME_LINE2) { 76 line1_ = value;
74 line2_ = value; 77 break;
75 } else if (type == ADDRESS_HOME_CITY) { 78
76 city_ = value; 79 case ADDRESS_HOME_LINE2:
77 } else if (type == ADDRESS_HOME_STATE) { 80 line2_ = value;
78 state_ = value; 81 break;
79 } else if (type == ADDRESS_HOME_COUNTRY) { 82
80 DCHECK(value.empty() || value.length() == 2u); 83 case ADDRESS_HOME_CITY:
81 country_code_ = value; 84 city_ = value;
82 } else if (type == ADDRESS_HOME_ZIP) { 85 break;
83 zip_code_ = value; 86
84 } else { 87 case ADDRESS_HOME_STATE:
85 NOTREACHED(); 88 state_ = value;
89 break;
90
91 case ADDRESS_HOME_COUNTRY:
92 DCHECK(value.empty() || value.length() == 2u);
93 country_code_ = value;
94 break;
95
96 case ADDRESS_HOME_ZIP:
97 zip_code_ = value;
98 break;
99
100 default:
101 NOTREACHED();
86 } 102 }
87 } 103 }
88 104
89 base::string16 Address::GetInfo(const AutofillType& type, 105 base::string16 Address::GetInfo(const AutofillType& type,
90 const std::string& app_locale) const { 106 const std::string& app_locale) const {
91 ServerFieldType server_type = 107 ServerFieldType storable_type = type.GetStorableType();
92 AutofillType::GetEquivalentFieldType(type.server_type()); 108 if (storable_type == ADDRESS_HOME_COUNTRY && !country_code_.empty())
93 if (server_type == ADDRESS_HOME_COUNTRY && !country_code_.empty())
94 return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name(); 109 return AutofillCountry(UTF16ToASCII(country_code_), app_locale).name();
95 110
96 return GetRawInfo(server_type); 111 return GetRawInfo(storable_type);
97 } 112 }
98 113
99 bool Address::SetInfo(const AutofillType& type, 114 bool Address::SetInfo(const AutofillType& type,
100 const base::string16& value, 115 const base::string16& value,
101 const std::string& app_locale) { 116 const std::string& app_locale) {
102 ServerFieldType server_type = 117 ServerFieldType storable_type = type.GetStorableType();
103 AutofillType::GetEquivalentFieldType(type.server_type()); 118 if (storable_type == ADDRESS_HOME_COUNTRY && !value.empty()) {
104 if (server_type == ADDRESS_HOME_COUNTRY && !value.empty()) {
105 country_code_ = 119 country_code_ =
106 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale)); 120 ASCIIToUTF16(AutofillCountry::GetCountryCode(value, app_locale));
107 return !country_code_.empty(); 121 return !country_code_.empty();
108 } 122 }
109 123
110 SetRawInfo(server_type, value); 124 SetRawInfo(storable_type, value);
111 return true; 125 return true;
112 } 126 }
113 127
114 void Address::GetMatchingTypes(const base::string16& text, 128 void Address::GetMatchingTypes(const base::string16& text,
115 const std::string& app_locale, 129 const std::string& app_locale,
116 ServerFieldTypeSet* matching_types) const { 130 ServerFieldTypeSet* matching_types) const {
117 FormGroup::GetMatchingTypes(text, app_locale, matching_types); 131 FormGroup::GetMatchingTypes(text, app_locale, matching_types);
118 132
119 // Check to see if the |text| canonicalized as a country name is a match. 133 // Check to see if the |text| canonicalized as a country name is a match.
120 std::string country_code = AutofillCountry::GetCountryCode(text, app_locale); 134 std::string country_code = AutofillCountry::GetCountryCode(text, app_locale);
121 if (!country_code.empty() && country_code_ == ASCIIToUTF16(country_code)) 135 if (!country_code.empty() && country_code_ == ASCIIToUTF16(country_code))
122 matching_types->insert(ADDRESS_HOME_COUNTRY); 136 matching_types->insert(ADDRESS_HOME_COUNTRY);
123 } 137 }
124 138
125 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { 139 void Address::GetSupportedTypes(ServerFieldTypeSet* supported_types) const {
126 supported_types->insert(ADDRESS_HOME_LINE1); 140 supported_types->insert(ADDRESS_HOME_LINE1);
127 supported_types->insert(ADDRESS_HOME_LINE2); 141 supported_types->insert(ADDRESS_HOME_LINE2);
128 supported_types->insert(ADDRESS_HOME_CITY); 142 supported_types->insert(ADDRESS_HOME_CITY);
129 supported_types->insert(ADDRESS_HOME_STATE); 143 supported_types->insert(ADDRESS_HOME_STATE);
130 supported_types->insert(ADDRESS_HOME_ZIP); 144 supported_types->insert(ADDRESS_HOME_ZIP);
131 supported_types->insert(ADDRESS_HOME_COUNTRY); 145 supported_types->insert(ADDRESS_HOME_COUNTRY);
132 } 146 }
133 147
134 } // namespace autofill 148 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/browser/wallet/wallet_items.cc ('k') | components/autofill/core/browser/autofill_data_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698