| 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/personal_data_manager.h" | 5 #include "components/autofill/core/browser/personal_data_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <list> | 10 #include <list> |
| (...skipping 1355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1366 } | 1366 } |
| 1367 NotifyPersonalDataChanged(); | 1367 NotifyPersonalDataChanged(); |
| 1368 } | 1368 } |
| 1369 | 1369 |
| 1370 bool PersonalDataManager::ImportAddressProfiles(const FormStructure& form) { | 1370 bool PersonalDataManager::ImportAddressProfiles(const FormStructure& form) { |
| 1371 if (!form.field_count()) | 1371 if (!form.field_count()) |
| 1372 return false; | 1372 return false; |
| 1373 | 1373 |
| 1374 // Relevant sections for address fields. | 1374 // Relevant sections for address fields. |
| 1375 std::set<std::string> sections; | 1375 std::set<std::string> sections; |
| 1376 for (const AutofillField* field : form) { | 1376 for (const auto& field : form) { |
| 1377 if (field->Type().group() != CREDIT_CARD) | 1377 if (field->Type().group() != CREDIT_CARD) |
| 1378 sections.insert(field->section()); | 1378 sections.insert(field->section()); |
| 1379 } | 1379 } |
| 1380 | 1380 |
| 1381 // We save a maximum of 2 profiles per submitted form (e.g. for shipping and | 1381 // We save a maximum of 2 profiles per submitted form (e.g. for shipping and |
| 1382 // billing). | 1382 // billing). |
| 1383 static const size_t kMaxNumAddressProfilesSaved = 2; | 1383 static const size_t kMaxNumAddressProfilesSaved = 2; |
| 1384 size_t num_saved_profiles = 0; | 1384 size_t num_saved_profiles = 0; |
| 1385 for (const std::string& section : sections) { | 1385 for (const std::string& section : sections) { |
| 1386 if (num_saved_profiles == kMaxNumAddressProfilesSaved) | 1386 if (num_saved_profiles == kMaxNumAddressProfilesSaved) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1403 | 1403 |
| 1404 // We only set complete phone, so aggregate phone parts in these vars and set | 1404 // We only set complete phone, so aggregate phone parts in these vars and set |
| 1405 // complete at the end. | 1405 // complete at the end. |
| 1406 PhoneNumber::PhoneCombineHelper combined_phone; | 1406 PhoneNumber::PhoneCombineHelper combined_phone; |
| 1407 | 1407 |
| 1408 // Used to detect and discard address forms with multiple fields of the same | 1408 // Used to detect and discard address forms with multiple fields of the same |
| 1409 // type. | 1409 // type. |
| 1410 std::set<ServerFieldType> types_seen; | 1410 std::set<ServerFieldType> types_seen; |
| 1411 | 1411 |
| 1412 // Go through each |form| field and attempt to constitute a valid profile. | 1412 // Go through each |form| field and attempt to constitute a valid profile. |
| 1413 for (const AutofillField* field : form) { | 1413 for (const auto& field : form) { |
| 1414 // Reject fields that are not within the specified |section|. | 1414 // Reject fields that are not within the specified |section|. |
| 1415 if (field->section() != section) | 1415 if (field->section() != section) |
| 1416 continue; | 1416 continue; |
| 1417 | 1417 |
| 1418 base::string16 value; | 1418 base::string16 value; |
| 1419 base::TrimWhitespace(field->value, base::TRIM_ALL, &value); | 1419 base::TrimWhitespace(field->value, base::TRIM_ALL, &value); |
| 1420 | 1420 |
| 1421 // If we don't know the type of the field, or the user hasn't entered any | 1421 // If we don't know the type of the field, or the user hasn't entered any |
| 1422 // information into the field, or the field is non-focusable (hidden), then | 1422 // information into the field, or the field is non-focusable (hidden), then |
| 1423 // skip it. | 1423 // skip it. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 bool should_return_local_card, | 1483 bool should_return_local_card, |
| 1484 std::unique_ptr<CreditCard>* imported_credit_card) { | 1484 std::unique_ptr<CreditCard>* imported_credit_card) { |
| 1485 DCHECK(!imported_credit_card->get()); | 1485 DCHECK(!imported_credit_card->get()); |
| 1486 | 1486 |
| 1487 // The candidate for credit card import. There are many ways for the candidate | 1487 // The candidate for credit card import. There are many ways for the candidate |
| 1488 // to be rejected (see everywhere this function returns false, below). | 1488 // to be rejected (see everywhere this function returns false, below). |
| 1489 CreditCard candidate_credit_card; | 1489 CreditCard candidate_credit_card; |
| 1490 candidate_credit_card.set_origin(form.source_url().spec()); | 1490 candidate_credit_card.set_origin(form.source_url().spec()); |
| 1491 | 1491 |
| 1492 std::set<ServerFieldType> types_seen; | 1492 std::set<ServerFieldType> types_seen; |
| 1493 for (const AutofillField* field : form) { | 1493 for (const auto& field : form) { |
| 1494 base::string16 value; | 1494 base::string16 value; |
| 1495 base::TrimWhitespace(field->value, base::TRIM_ALL, &value); | 1495 base::TrimWhitespace(field->value, base::TRIM_ALL, &value); |
| 1496 | 1496 |
| 1497 // If we don't know the type of the field, or the user hasn't entered any | 1497 // If we don't know the type of the field, or the user hasn't entered any |
| 1498 // information into the field, or the field is non-focusable (hidden), then | 1498 // information into the field, or the field is non-focusable (hidden), then |
| 1499 // skip it. | 1499 // skip it. |
| 1500 if (!field->IsFieldFillable() || !field->is_focusable || value.empty()) | 1500 if (!field->IsFieldFillable() || !field->is_focusable || value.empty()) |
| 1501 continue; | 1501 continue; |
| 1502 | 1502 |
| 1503 AutofillType field_type = field->Type(); | 1503 AutofillType field_type = field->Type(); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1853 } | 1853 } |
| 1854 | 1854 |
| 1855 // If the card was modified, apply the changes to the database. | 1855 // If the card was modified, apply the changes to the database. |
| 1856 if (was_modified) { | 1856 if (was_modified) { |
| 1857 database_->UpdateCreditCard(*credit_card); | 1857 database_->UpdateCreditCard(*credit_card); |
| 1858 } | 1858 } |
| 1859 } | 1859 } |
| 1860 } | 1860 } |
| 1861 | 1861 |
| 1862 } // namespace autofill | 1862 } // namespace autofill |
| OLD | NEW |