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

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

Issue 347183005: autofill names - dont parse when calling SetRawInfo(FULL_NAME) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix android test expectation Created 6 years, 5 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/contact_info.h" 5 #include "components/autofill/core/browser/contact_info.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <ostream> 8 #include <ostream>
9 #include <string> 9 #include <string>
10 10
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 if (this == &info) 152 if (this == &info)
153 return *this; 153 return *this;
154 154
155 given_ = info.given_; 155 given_ = info.given_;
156 middle_ = info.middle_; 156 middle_ = info.middle_;
157 family_ = info.family_; 157 family_ = info.family_;
158 full_ = info.full_; 158 full_ = info.full_;
159 return *this; 159 return *this;
160 } 160 }
161 161
162 bool NameInfo::EqualsIgnoreCase(const NameInfo& info) { 162 bool NameInfo::ParsedNamesAreEqual(const NameInfo& info) {
163 return (StringToLowerASCII(given_) == StringToLowerASCII(info.given_) && 163 return (StringToLowerASCII(given_) == StringToLowerASCII(info.given_) &&
164 StringToLowerASCII(middle_) == StringToLowerASCII(info.middle_) && 164 StringToLowerASCII(middle_) == StringToLowerASCII(info.middle_) &&
165 StringToLowerASCII(family_) == StringToLowerASCII(info.family_)); 165 StringToLowerASCII(family_) == StringToLowerASCII(info.family_));
166 } 166 }
167 167
168 void NameInfo::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { 168 void NameInfo::GetSupportedTypes(ServerFieldTypeSet* supported_types) const {
169 supported_types->insert(NAME_FIRST); 169 supported_types->insert(NAME_FIRST);
170 supported_types->insert(NAME_MIDDLE); 170 supported_types->insert(NAME_MIDDLE);
171 supported_types->insert(NAME_LAST); 171 supported_types->insert(NAME_LAST);
172 supported_types->insert(NAME_MIDDLE_INITIAL); 172 supported_types->insert(NAME_MIDDLE_INITIAL);
173 supported_types->insert(NAME_FULL); 173 supported_types->insert(NAME_FULL);
174 } 174 }
175 175
176 base::string16 NameInfo::GetRawInfo(ServerFieldType type) const { 176 base::string16 NameInfo::GetRawInfo(ServerFieldType type) const {
177 DCHECK_EQ(NAME, AutofillType(type).group()); 177 DCHECK_EQ(NAME, AutofillType(type).group());
178 switch (type) { 178 switch (type) {
179 case NAME_FIRST: 179 case NAME_FIRST:
180 return given_; 180 return given_;
181 181
182 case NAME_MIDDLE: 182 case NAME_MIDDLE:
183 return middle_; 183 return middle_;
184 184
185 case NAME_LAST: 185 case NAME_LAST:
186 return family_; 186 return family_;
187 187
188 case NAME_MIDDLE_INITIAL: 188 case NAME_MIDDLE_INITIAL:
189 return MiddleInitial(); 189 return MiddleInitial();
190 190
191 case NAME_FULL: 191 case NAME_FULL:
192 return FullName(); 192 return full_;
193 193
194 default: 194 default:
195 return base::string16(); 195 return base::string16();
196 } 196 }
197 } 197 }
198 198
199 void NameInfo::SetRawInfo(ServerFieldType type, const base::string16& value) { 199 void NameInfo::SetRawInfo(ServerFieldType type, const base::string16& value) {
200 DCHECK_EQ(NAME, AutofillType(type).group()); 200 DCHECK_EQ(NAME, AutofillType(type).group());
201 201
202 // Always clear out the full name if we're making a change.
203 if (value != GetRawInfo(type))
204 full_.clear();
205
206 switch (type) { 202 switch (type) {
207 case NAME_FIRST: 203 case NAME_FIRST:
208 given_ = value; 204 given_ = value;
209 break; 205 break;
210 206
211 case NAME_MIDDLE: 207 case NAME_MIDDLE:
212 case NAME_MIDDLE_INITIAL: 208 case NAME_MIDDLE_INITIAL:
213 middle_ = value; 209 middle_ = value;
214 break; 210 break;
215 211
216 case NAME_LAST: 212 case NAME_LAST:
217 family_ = value; 213 family_ = value;
218 break; 214 break;
219 215
220 case NAME_FULL: 216 case NAME_FULL:
221 // TODO(estade): this should just set |full_|; only SetInfo should attempt 217 full_ = value;
222 // to be smart. http://crbug.com/384640
223 SetFullName(value);
224 break; 218 break;
225 219
226 default: 220 default:
227 NOTREACHED(); 221 NOTREACHED();
228 } 222 }
229 } 223 }
230 224
225 base::string16 NameInfo::GetInfo(const AutofillType& type,
226 const std::string& app_locale) const {
227 if (type.GetStorableType() == NAME_FULL)
228 return FullName();
229
230 return GetRawInfo(type.GetStorableType());
231 }
232
233 bool NameInfo::SetInfo(const AutofillType& type,
234 const base::string16& value,
235 const std::string& app_locale) {
236 // Always clear out the full name if we're making a change.
237 if (value != GetInfo(type, app_locale))
238 full_.clear();
239
240 if (type.GetStorableType() == NAME_FULL) {
241 SetFullName(value);
242 return true;
243 }
244
245 return FormGroup::SetInfo(type, value, app_locale);
246 }
247
231 base::string16 NameInfo::FullName() const { 248 base::string16 NameInfo::FullName() const {
232 if (!full_.empty()) 249 if (!full_.empty())
233 return full_; 250 return full_;
234 251
235 std::vector<base::string16> full_name; 252 std::vector<base::string16> full_name;
236 if (!given_.empty()) 253 if (!given_.empty())
237 full_name.push_back(given_); 254 full_name.push_back(given_);
238 255
239 if (!middle_.empty()) 256 if (!middle_.empty())
240 full_name.push_back(middle_); 257 full_name.push_back(middle_);
241 258
242 if (!family_.empty()) 259 if (!family_.empty())
243 full_name.push_back(family_); 260 full_name.push_back(family_);
244 261
245 return JoinString(full_name, ' '); 262 return JoinString(full_name, ' ');
246 } 263 }
247 264
248 base::string16 NameInfo::MiddleInitial() const { 265 base::string16 NameInfo::MiddleInitial() const {
249 if (middle_.empty()) 266 if (middle_.empty())
250 return base::string16(); 267 return base::string16();
251 268
252 base::string16 middle_name(middle_); 269 base::string16 middle_name(middle_);
253 base::string16 initial; 270 base::string16 initial;
254 initial.push_back(middle_name[0]); 271 initial.push_back(middle_name[0]);
255 return initial; 272 return initial;
256 } 273 }
257 274
258 void NameInfo::SetFullName(const base::string16& full) { 275 void NameInfo::SetFullName(const base::string16& full) {
259 // Hack: don't do anything if this wouldn't change the full, concatenated
260 // name. Otherwise when unpickling data from the database, "First|Middle|"
261 // will get parsed as "First||Middle".
262 // TODO(estade): we should be able to remove this when fixing the TODO in
263 // SetRawInfo. http://crbug.com/384640
264 if (FullName() == full)
265 return;
266
267 full_ = full; 276 full_ = full;
268 277
269 // If |full| is empty, leave the other name parts alone. This might occur 278 // If |full| is empty, leave the other name parts alone. This might occur
270 // due to a migrated database with an empty |full_name| value. 279 // due to a migrated database with an empty |full_name| value.
271 if (full.empty()) 280 if (full.empty())
272 return; 281 return;
273 282
274 NameParts parts = SplitName(full); 283 NameParts parts = SplitName(full);
275 given_ = parts.given; 284 given_ = parts.given;
276 middle_ = parts.middle; 285 middle_ = parts.middle;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 return base::string16(); 345 return base::string16();
337 } 346 }
338 347
339 void CompanyInfo::SetRawInfo(ServerFieldType type, 348 void CompanyInfo::SetRawInfo(ServerFieldType type,
340 const base::string16& value) { 349 const base::string16& value) {
341 DCHECK_EQ(COMPANY_NAME, type); 350 DCHECK_EQ(COMPANY_NAME, type);
342 company_name_ = value; 351 company_name_ = value;
343 } 352 }
344 353
345 } // namespace autofill 354 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/contact_info.h ('k') | components/autofill/core/browser/contact_info_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698