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/autofill_profile.h" | 5 #include "components/autofill/core/browser/autofill_profile.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <ostream> | 10 #include <ostream> |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 129 |
| 130 base::string16 GetFormGroupInfo(const FormGroup& form_group, | 130 base::string16 GetFormGroupInfo(const FormGroup& form_group, |
| 131 const AutofillType& type, | 131 const AutofillType& type, |
| 132 const std::string& app_locale) { | 132 const std::string& app_locale) { |
| 133 return app_locale.empty() ? | 133 return app_locale.empty() ? |
| 134 form_group.GetRawInfo(type.GetStorableType()) : | 134 form_group.GetRawInfo(type.GetStorableType()) : |
| 135 form_group.GetInfo(type, app_locale); | 135 form_group.GetInfo(type, app_locale); |
| 136 } | 136 } |
| 137 | 137 |
| 138 template <class T> | 138 template <class T> |
| 139 void CopyValuesToItems(ServerFieldType type, | 139 void CopyRawValuesToItems(ServerFieldType type, |
| 140 const std::vector<base::string16>& values, | 140 const std::vector<base::string16>& values, |
| 141 std::vector<T>* form_group_items, | 141 const T& prototype, |
| 142 const T& prototype) { | 142 std::vector<T>* form_group_items) { |
| 143 form_group_items->resize(values.size(), prototype); | 143 form_group_items->resize(values.size(), prototype); |
| 144 for (size_t i = 0; i < form_group_items->size(); ++i) { | 144 for (size_t i = 0; i < form_group_items->size(); ++i) { |
| 145 (*form_group_items)[i].SetRawInfo(type, values[i]); | 145 (*form_group_items)[i].SetRawInfo(type, values[i]); |
| 146 } | 146 } |
| 147 // Must have at least one (possibly empty) element. | 147 // Must have at least one (possibly empty) element. |
| 148 if (form_group_items->empty()) | 148 form_group_items->resize(std::max(1UL, values.size()), prototype); |
| 149 form_group_items->resize(1, prototype); | |
| 150 } | 149 } |
| 151 | 150 |
| 152 template <class T> | 151 template <class T> |
| 152 void CopyValuesToItems(AutofillType type, | |
| 153 const std::vector<base::string16>& values, | |
| 154 const T& prototype, | |
| 155 const std::string& app_locale, | |
| 156 std::vector<T>* form_group_items) { | |
| 157 form_group_items->resize(values.size(), prototype); | |
| 158 for (size_t i = 0; i < form_group_items->size(); ++i) { | |
| 159 (*form_group_items)[i].SetInfo(type, values[i], app_locale); | |
| 160 } | |
| 161 // Must have at least one (possibly empty) element. | |
| 162 form_group_items->resize(std::max(1UL, values.size()), prototype); | |
| 163 } | |
| 164 | |
| 165 template <class T> | |
| 153 void CopyItemsToValues(const AutofillType& type, | 166 void CopyItemsToValues(const AutofillType& type, |
| 154 const std::vector<T>& form_group_items, | 167 const std::vector<T>& form_group_items, |
| 155 const std::string& app_locale, | 168 const std::string& app_locale, |
| 156 std::vector<base::string16>* values) { | 169 std::vector<base::string16>* values) { |
| 157 values->resize(form_group_items.size()); | 170 values->resize(form_group_items.size()); |
| 158 for (size_t i = 0; i < values->size(); ++i) { | 171 for (size_t i = 0; i < values->size(); ++i) { |
| 159 (*values)[i] = GetFormGroupInfo(form_group_items[i], type, app_locale); | 172 (*values)[i] = GetFormGroupInfo(form_group_items[i], type, app_locale); |
| 160 } | 173 } |
| 161 } | 174 } |
| 162 | 175 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 342 | 355 |
| 343 return values[variant]; | 356 return values[variant]; |
| 344 } | 357 } |
| 345 | 358 |
| 346 void AutofillProfile::SetRawMultiInfo( | 359 void AutofillProfile::SetRawMultiInfo( |
| 347 ServerFieldType type, | 360 ServerFieldType type, |
| 348 const std::vector<base::string16>& values) { | 361 const std::vector<base::string16>& values) { |
| 349 switch (AutofillType(type).group()) { | 362 switch (AutofillType(type).group()) { |
| 350 case NAME: | 363 case NAME: |
| 351 case NAME_BILLING: | 364 case NAME_BILLING: |
| 352 CopyValuesToItems(type, values, &name_, NameInfo()); | 365 CopyRawValuesToItems(type, values, NameInfo(), &name_); |
| 353 break; | 366 break; |
| 367 | |
| 354 case EMAIL: | 368 case EMAIL: |
| 355 CopyValuesToItems(type, values, &email_, EmailInfo()); | 369 CopyRawValuesToItems(type, values, EmailInfo(), &email_); |
| 356 break; | 370 break; |
| 371 | |
| 357 case PHONE_HOME: | 372 case PHONE_HOME: |
| 358 case PHONE_BILLING: | 373 case PHONE_BILLING: |
| 359 CopyValuesToItems(type, | 374 CopyRawValuesToItems(type, values, PhoneNumber(this), &phone_number_); |
| 360 values, | |
| 361 &phone_number_, | |
| 362 PhoneNumber(this)); | |
| 363 break; | 375 break; |
| 376 | |
| 364 default: | 377 default: |
| 365 if (values.size() == 1) { | 378 if (values.size() == 1U) { |
| 366 SetRawInfo(type, values[0]); | 379 SetRawInfo(type, values[0]); |
| 367 } else if (values.size() == 0) { | 380 } else if (values.empty()) { |
| 368 SetRawInfo(type, base::string16()); | 381 SetRawInfo(type, base::string16()); |
| 369 } else { | 382 } else { |
| 370 // Shouldn't attempt to set multiple values on single-valued field. | 383 // Shouldn't attempt to set multiple values on single-valued field. |
| 371 NOTREACHED(); | 384 NOTREACHED(); |
| 372 } | 385 } |
| 373 break; | 386 break; |
| 374 } | 387 } |
| 375 } | 388 } |
| 376 | 389 |
| 377 void AutofillProfile::GetRawMultiInfo( | 390 void AutofillProfile::GetRawMultiInfo( |
| 378 ServerFieldType type, | 391 ServerFieldType type, |
| 379 std::vector<base::string16>* values) const { | 392 std::vector<base::string16>* values) const { |
| 380 GetMultiInfoImpl(AutofillType(type), std::string(), values); | 393 GetMultiInfoImpl(AutofillType(type), std::string(), values); |
| 381 } | 394 } |
| 382 | 395 |
| 396 void AutofillProfile::SetMultiInfo(const AutofillType& type, | |
| 397 const std::vector<base::string16>& values, | |
| 398 const std::string& app_locale) { | |
| 399 switch (AutofillType(type).group()) { | |
| 400 case NAME: | |
| 401 case NAME_BILLING: | |
| 402 CopyValuesToItems(type, values, NameInfo(), app_locale, &name_); | |
| 403 break; | |
| 404 | |
| 405 case EMAIL: | |
| 406 CopyValuesToItems(type, values, EmailInfo(), app_locale, &email_); | |
| 407 break; | |
| 408 | |
| 409 case PHONE_HOME: | |
| 410 case PHONE_BILLING: | |
| 411 CopyValuesToItems( | |
| 412 type, values, PhoneNumber(this), app_locale, &phone_number_); | |
| 413 break; | |
| 414 | |
| 415 default: | |
| 416 if (values.size() == 1) { | |
| 417 SetInfo(type, values[0], app_locale); | |
| 418 } else if (values.size() == 0) { | |
|
Ilya Sherman
2014/07/17 18:50:56
nit: Update this code to match the changes you mad
Evan Stade
2014/07/22 01:50:53
Done.
| |
| 419 SetInfo(type, base::string16(), app_locale); | |
| 420 } else { | |
| 421 // Shouldn't attempt to set multiple values on single-valued field. | |
| 422 NOTREACHED(); | |
| 423 } | |
| 424 break; | |
| 425 } | |
| 426 } | |
| 427 | |
| 383 void AutofillProfile::GetMultiInfo(const AutofillType& type, | 428 void AutofillProfile::GetMultiInfo(const AutofillType& type, |
| 384 const std::string& app_locale, | 429 const std::string& app_locale, |
| 385 std::vector<base::string16>* values) const { | 430 std::vector<base::string16>* values) const { |
| 386 GetMultiInfoImpl(type, app_locale, values); | 431 GetMultiInfoImpl(type, app_locale, values); |
| 387 } | 432 } |
| 388 | 433 |
| 389 bool AutofillProfile::IsEmpty(const std::string& app_locale) const { | 434 bool AutofillProfile::IsEmpty(const std::string& app_locale) const { |
| 390 ServerFieldTypeSet types; | 435 ServerFieldTypeSet types; |
| 391 GetNonEmptyTypes(app_locale, &types); | 436 GetNonEmptyTypes(app_locale, &types); |
| 392 return types.empty(); | 437 return types.empty(); |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 936 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 981 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
| 937 << " " | 982 << " " |
| 938 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 983 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
| 939 << " " | 984 << " " |
| 940 << profile.language_code() | 985 << profile.language_code() |
| 941 << " " | 986 << " " |
| 942 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 987 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
| 943 } | 988 } |
| 944 | 989 |
| 945 } // namespace autofill | 990 } // namespace autofill |
| OLD | NEW |