Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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::ParsedBitsAreEqual(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 middle_.size() == info.middle_.size() && | |
|
Ilya Sherman
2014/06/27 06:25:08
Why is this check necessary? How can the strings
Evan Stade
2014/06/28 01:01:35
this is totally not necessary. It was just me bein
| |
| 165 StringToLowerASCII(family_) == StringToLowerASCII(info.family_)); | 166 StringToLowerASCII(family_) == StringToLowerASCII(info.family_)); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void NameInfo::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { | 169 void NameInfo::GetSupportedTypes(ServerFieldTypeSet* supported_types) const { |
| 169 supported_types->insert(NAME_FIRST); | 170 supported_types->insert(NAME_FIRST); |
| 170 supported_types->insert(NAME_MIDDLE); | 171 supported_types->insert(NAME_MIDDLE); |
| 171 supported_types->insert(NAME_LAST); | 172 supported_types->insert(NAME_LAST); |
| 172 supported_types->insert(NAME_MIDDLE_INITIAL); | 173 supported_types->insert(NAME_MIDDLE_INITIAL); |
| 173 supported_types->insert(NAME_FULL); | 174 supported_types->insert(NAME_FULL); |
| 174 } | 175 } |
| 175 | 176 |
| 176 base::string16 NameInfo::GetRawInfo(ServerFieldType type) const { | 177 base::string16 NameInfo::GetRawInfo(ServerFieldType type) const { |
| 177 DCHECK_EQ(NAME, AutofillType(type).group()); | 178 DCHECK_EQ(NAME, AutofillType(type).group()); |
| 178 switch (type) { | 179 switch (type) { |
| 179 case NAME_FIRST: | 180 case NAME_FIRST: |
| 180 return given_; | 181 return given_; |
| 181 | 182 |
| 182 case NAME_MIDDLE: | 183 case NAME_MIDDLE: |
| 183 return middle_; | 184 return middle_; |
| 184 | 185 |
| 185 case NAME_LAST: | 186 case NAME_LAST: |
| 186 return family_; | 187 return family_; |
| 187 | 188 |
| 188 case NAME_MIDDLE_INITIAL: | 189 case NAME_MIDDLE_INITIAL: |
| 189 return MiddleInitial(); | 190 return MiddleInitial(); |
| 190 | 191 |
| 191 case NAME_FULL: | 192 case NAME_FULL: |
| 192 return FullName(); | 193 return full_; |
| 193 | 194 |
| 194 default: | 195 default: |
| 195 return base::string16(); | 196 return base::string16(); |
| 196 } | 197 } |
| 197 } | 198 } |
| 198 | 199 |
| 199 void NameInfo::SetRawInfo(ServerFieldType type, const base::string16& value) { | 200 void NameInfo::SetRawInfo(ServerFieldType type, const base::string16& value) { |
| 200 DCHECK_EQ(NAME, AutofillType(type).group()); | 201 DCHECK_EQ(NAME, AutofillType(type).group()); |
| 201 | 202 |
| 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) { | 203 switch (type) { |
| 207 case NAME_FIRST: | 204 case NAME_FIRST: |
| 208 given_ = value; | 205 given_ = value; |
| 209 break; | 206 break; |
| 210 | 207 |
| 211 case NAME_MIDDLE: | 208 case NAME_MIDDLE: |
| 212 case NAME_MIDDLE_INITIAL: | 209 case NAME_MIDDLE_INITIAL: |
| 213 middle_ = value; | 210 middle_ = value; |
| 214 break; | 211 break; |
| 215 | 212 |
| 216 case NAME_LAST: | 213 case NAME_LAST: |
| 217 family_ = value; | 214 family_ = value; |
| 218 break; | 215 break; |
| 219 | 216 |
| 220 case NAME_FULL: | 217 case NAME_FULL: |
| 221 // TODO(estade): this should just set |full_|; only SetInfo should attempt | 218 full_ = value; |
| 222 // to be smart. http://crbug.com/384640 | |
| 223 SetFullName(value); | |
| 224 break; | 219 break; |
| 225 | 220 |
| 226 default: | 221 default: |
| 227 NOTREACHED(); | 222 NOTREACHED(); |
| 228 } | 223 } |
| 229 } | 224 } |
| 230 | 225 |
| 226 base::string16 NameInfo::GetInfo(const AutofillType& type, | |
| 227 const std::string& app_locale) const { | |
| 228 if (type.GetStorableType() == NAME_FULL) | |
| 229 return FullName(); | |
| 230 | |
| 231 return GetRawInfo(type.GetStorableType()); | |
| 232 } | |
| 233 | |
| 234 bool NameInfo::SetInfo(const AutofillType& type, | |
| 235 const base::string16& value, | |
| 236 const std::string& app_locale) { | |
| 237 // Always clear out the full name if we're making a change. | |
| 238 if (value != GetInfo(type, app_locale)) | |
| 239 full_.clear(); | |
| 240 | |
| 241 if (type.GetStorableType() == NAME_FULL) { | |
| 242 SetFullName(value); | |
| 243 return true; | |
| 244 } | |
| 245 | |
| 246 return FormGroup::SetInfo(type, value, app_locale); | |
| 247 } | |
| 248 | |
| 231 base::string16 NameInfo::FullName() const { | 249 base::string16 NameInfo::FullName() const { |
| 232 if (!full_.empty()) | 250 if (!full_.empty()) |
| 233 return full_; | 251 return full_; |
| 234 | 252 |
| 235 std::vector<base::string16> full_name; | 253 std::vector<base::string16> full_name; |
| 236 if (!given_.empty()) | 254 if (!given_.empty()) |
| 237 full_name.push_back(given_); | 255 full_name.push_back(given_); |
| 238 | 256 |
| 239 if (!middle_.empty()) | 257 if (!middle_.empty()) |
| 240 full_name.push_back(middle_); | 258 full_name.push_back(middle_); |
| 241 | 259 |
| 242 if (!family_.empty()) | 260 if (!family_.empty()) |
| 243 full_name.push_back(family_); | 261 full_name.push_back(family_); |
| 244 | 262 |
| 245 return JoinString(full_name, ' '); | 263 return JoinString(full_name, ' '); |
| 246 } | 264 } |
| 247 | 265 |
| 248 base::string16 NameInfo::MiddleInitial() const { | 266 base::string16 NameInfo::MiddleInitial() const { |
| 249 if (middle_.empty()) | 267 if (middle_.empty()) |
| 250 return base::string16(); | 268 return base::string16(); |
| 251 | 269 |
| 252 base::string16 middle_name(middle_); | 270 base::string16 middle_name(middle_); |
| 253 base::string16 initial; | 271 base::string16 initial; |
| 254 initial.push_back(middle_name[0]); | 272 initial.push_back(middle_name[0]); |
| 255 return initial; | 273 return initial; |
| 256 } | 274 } |
| 257 | 275 |
| 258 void NameInfo::SetFullName(const base::string16& full) { | 276 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; | 277 full_ = full; |
| 268 | 278 |
| 269 // If |full| is empty, leave the other name parts alone. This might occur | 279 // 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. | 280 // due to a migrated database with an empty |full_name| value. |
| 271 if (full.empty()) | 281 if (full.empty()) |
| 272 return; | 282 return; |
| 273 | 283 |
| 274 NameParts parts = SplitName(full); | 284 NameParts parts = SplitName(full); |
| 275 given_ = parts.given; | 285 given_ = parts.given; |
| 276 middle_ = parts.middle; | 286 middle_ = parts.middle; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 return base::string16(); | 346 return base::string16(); |
| 337 } | 347 } |
| 338 | 348 |
| 339 void CompanyInfo::SetRawInfo(ServerFieldType type, | 349 void CompanyInfo::SetRawInfo(ServerFieldType type, |
| 340 const base::string16& value) { | 350 const base::string16& value) { |
| 341 DCHECK_EQ(COMPANY_NAME, type); | 351 DCHECK_EQ(COMPANY_NAME, type); |
| 342 company_name_ = value; | 352 company_name_ = value; |
| 343 } | 353 } |
| 344 | 354 |
| 345 } // namespace autofill | 355 } // namespace autofill |
| OLD | NEW |