| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/autofill_manager.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (!form.user_submitted) | 202 if (!form.user_submitted) |
| 203 return; | 203 return; |
| 204 | 204 |
| 205 // Grab a copy of the form data. | 205 // Grab a copy of the form data. |
| 206 upload_form_structure_.reset(new FormStructure(form)); | 206 upload_form_structure_.reset(new FormStructure(form)); |
| 207 | 207 |
| 208 // Disregard forms that we wouldn't ever autofill in the first place. | 208 // Disregard forms that we wouldn't ever autofill in the first place. |
| 209 if (!upload_form_structure_->ShouldBeParsed(true)) | 209 if (!upload_form_structure_->ShouldBeParsed(true)) |
| 210 return; | 210 return; |
| 211 | 211 |
| 212 DeterminePossibleFieldTypesForUpload(); | 212 FormStructure* cached_upload_form_structure = NULL; |
| 213 AutoFillField* ignored; |
| 214 if (!FindCachedFormAndField(form, form.fields.front(), |
| 215 &cached_upload_form_structure, &ignored)) { |
| 216 cached_upload_form_structure = NULL; |
| 217 } |
| 218 |
| 219 DeterminePossibleFieldTypesForUpload(cached_upload_form_structure); |
| 213 // TODO(isherman): Consider uploading to server here rather than in | 220 // TODO(isherman): Consider uploading to server here rather than in |
| 214 // HandleSubmit(). | 221 // HandleSubmit(). |
| 215 | 222 |
| 216 if (!upload_form_structure_->IsAutoFillable(true)) | 223 if (!upload_form_structure_->IsAutoFillable(true)) |
| 217 return; | 224 return; |
| 218 | 225 |
| 219 HandleSubmit(); | 226 HandleSubmit(); |
| 220 } | 227 } |
| 221 | 228 |
| 222 void AutoFillManager::OnFormsSeen(const std::vector<FormData>& forms) { | 229 void AutoFillManager::OnFormsSeen(const std::vector<FormData>& forms) { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 if (prefs->FindPreference(prefs::kFormAutofillEnabled)) { | 486 if (prefs->FindPreference(prefs::kFormAutofillEnabled)) { |
| 480 bool enabled = prefs->GetBoolean(prefs::kFormAutofillEnabled); | 487 bool enabled = prefs->GetBoolean(prefs::kFormAutofillEnabled); |
| 481 prefs->ClearPref(prefs::kFormAutofillEnabled); | 488 prefs->ClearPref(prefs::kFormAutofillEnabled); |
| 482 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled); | 489 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled); |
| 483 return enabled; | 490 return enabled; |
| 484 } | 491 } |
| 485 | 492 |
| 486 return prefs->GetBoolean(prefs::kAutoFillEnabled); | 493 return prefs->GetBoolean(prefs::kAutoFillEnabled); |
| 487 } | 494 } |
| 488 | 495 |
| 489 void AutoFillManager::DeterminePossibleFieldTypesForUpload() { | 496 void AutoFillManager::DeterminePossibleFieldTypesForUpload( |
| 497 const FormStructure* cached_upload_form_structure) { |
| 490 for (size_t i = 0; i < upload_form_structure_->field_count(); i++) { | 498 for (size_t i = 0; i < upload_form_structure_->field_count(); i++) { |
| 491 const AutoFillField* field = upload_form_structure_->field(i); | 499 const AutoFillField* field = upload_form_structure_->field(i); |
| 492 FieldTypeSet field_types; | 500 FieldTypeSet field_types; |
| 493 GetPersonalDataManager()->GetPossibleFieldTypes( | 501 GetPersonalDataManager()->GetPossibleFieldTypes( |
| 494 field->value(), &field_types); | 502 field->value(), &field_types); |
| 495 DCHECK(!field_types.empty()); | 503 DCHECK(!field_types.empty()); |
| 496 upload_form_structure_->set_possible_types(i, field_types); | 504 upload_form_structure_->set_possible_types(i, field_types); |
| 497 | 505 |
| 498 if (field->form_control_type() == ASCIIToUTF16("select-one")) { | 506 if (field->form_control_type() == ASCIIToUTF16("select-one")) { |
| 499 // TODO(isherman): <select> fields don't support |is_autofilled()|. Since | 507 // TODO(isherman): <select> fields don't support |is_autofilled()|. Since |
| 500 // this is heavily relied upon by our metrics, we just don't log anything | 508 // this is heavily relied upon by our metrics, we just don't log anything |
| 501 // for all <select> fields. Better to have less data than misleading data. | 509 // for all <select> fields. Better to have less data than misleading data. |
| 502 continue; | 510 continue; |
| 503 } | 511 } |
| 504 | 512 |
| 505 // Log various quality metrics. | 513 // Log various quality metrics. |
| 506 metric_logger_->Log(AutoFillMetrics::FIELD_SUBMITTED); | 514 metric_logger_->Log(AutoFillMetrics::FIELD_SUBMITTED); |
| 507 if (field_types.find(EMPTY_TYPE) == field_types.end() && | 515 if (field_types.find(EMPTY_TYPE) == field_types.end() && |
| 508 field_types.find(UNKNOWN_TYPE) == field_types.end()) { | 516 field_types.find(UNKNOWN_TYPE) == field_types.end()) { |
| 509 if (field->is_autofilled()) | 517 if (field->is_autofilled()) { |
| 510 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILLED); | 518 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILLED); |
| 511 else | 519 } else { |
| 512 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED); | 520 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED); |
| 521 |
| 522 AutoFillFieldType heuristic_type = cached_upload_form_structure? |
| 523 cached_upload_form_structure->field(i)->heuristic_type() : |
| 524 UNKNOWN_TYPE; |
| 525 if (heuristic_type == UNKNOWN_TYPE) |
| 526 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN); |
| 527 else if (field_types.count(heuristic_type)) |
| 528 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MATCH); |
| 529 else |
| 530 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH); |
| 531 |
| 532 AutoFillFieldType server_type = cached_upload_form_structure? |
| 533 cached_upload_form_structure->field(i)->server_type() : |
| 534 NO_SERVER_DATA; |
| 535 if (server_type == NO_SERVER_DATA) |
| 536 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_UNKNOWN); |
| 537 else if (field_types.count(server_type)) |
| 538 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MATCH); |
| 539 else |
| 540 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH); |
| 541 } |
| 542 |
| 513 | 543 |
| 514 // TODO(isherman): Other things we might want to log here: | 544 // TODO(isherman): Other things we might want to log here: |
| 515 // * Did the field's heuristic type match the PDM type? | |
| 516 // * Per Vadim's email, a combination of (1) whether heuristics fired, | 545 // * Per Vadim's email, a combination of (1) whether heuristics fired, |
| 517 // (2) whether the server returned something interesting, (3) whether | 546 // (2) whether the server returned something interesting, (3) whether |
| 518 // the user filled the field | 547 // the user filled the field |
| 519 // * Whether the server type matches the heursitic type | 548 // * Whether the server type matches the heursitic type |
| 520 // - Perhaps only if at least one of the types is not unknown/no data. | 549 // - Perhaps only if at least one of the types is not unknown/no data. |
| 521 } | 550 } |
| 522 } | 551 } |
| 523 } | 552 } |
| 524 | 553 |
| 525 void AutoFillManager::HandleSubmit() { | 554 void AutoFillManager::HandleSubmit() { |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 return true; | 645 return true; |
| 617 } | 646 } |
| 618 | 647 |
| 619 bool AutoFillManager::FindCachedFormAndField(const FormData& form, | 648 bool AutoFillManager::FindCachedFormAndField(const FormData& form, |
| 620 const FormField& field, | 649 const FormField& field, |
| 621 FormStructure** form_structure, | 650 FormStructure** form_structure, |
| 622 AutoFillField** autofill_field) { | 651 AutoFillField** autofill_field) { |
| 623 // Find the FormStructure that corresponds to |form|. | 652 // Find the FormStructure that corresponds to |form|. |
| 624 *form_structure = NULL; | 653 *form_structure = NULL; |
| 625 for (std::vector<FormStructure*>::const_iterator iter = | 654 for (std::vector<FormStructure*>::const_iterator iter = |
| 626 form_structures_.begin(); | 655 form_structures_.begin(); |
| 627 iter != form_structures_.end(); ++iter) { | 656 iter != form_structures_.end(); ++iter) { |
| 628 if (**iter == form) { | 657 if (**iter == form) { |
| 629 *form_structure = *iter; | 658 *form_structure = *iter; |
| 630 break; | 659 break; |
| 631 } | 660 } |
| 632 } | 661 } |
| 633 | 662 |
| 634 if (!(*form_structure)) | 663 if (!(*form_structure)) |
| 635 return false; | 664 return false; |
| 636 | 665 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 776 field->max_length() == PhoneNumber::kSuffixLength) { | 805 field->max_length() == PhoneNumber::kSuffixLength) { |
| 777 number = number.substr(PhoneNumber::kSuffixOffset, | 806 number = number.substr(PhoneNumber::kSuffixOffset, |
| 778 PhoneNumber::kSuffixLength); | 807 PhoneNumber::kSuffixLength); |
| 779 field->set_value(number); | 808 field->set_value(number); |
| 780 } else { | 809 } else { |
| 781 field->set_value(number); | 810 field->set_value(number); |
| 782 } | 811 } |
| 783 } | 812 } |
| 784 | 813 |
| 785 void AutoFillManager::ParseForms(const std::vector<FormData>& forms) { | 814 void AutoFillManager::ParseForms(const std::vector<FormData>& forms) { |
| 786 std::vector<FormStructure *> non_queryable_forms; | 815 std::vector<FormStructure*> non_queryable_forms; |
| 787 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 816 for (std::vector<FormData>::const_iterator iter = forms.begin(); |
| 788 iter != forms.end(); ++iter) { | 817 iter != forms.end(); ++iter) { |
| 789 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); | 818 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); |
| 790 if (!form_structure->ShouldBeParsed(false)) | 819 if (!form_structure->ShouldBeParsed(false)) |
| 791 continue; | 820 continue; |
| 792 | 821 |
| 793 // Set aside forms with method GET so that they are not included in the | 822 // Set aside forms with method GET so that they are not included in the |
| 794 // query to the server. | 823 // query to the server. |
| 795 if (form_structure->ShouldBeParsed(true)) | 824 if (form_structure->ShouldBeParsed(true)) |
| 796 form_structures_.push_back(form_structure.release()); | 825 form_structures_.push_back(form_structure.release()); |
| 797 else | 826 else |
| 798 non_queryable_forms.push_back(form_structure.release()); | 827 non_queryable_forms.push_back(form_structure.release()); |
| 799 } | 828 } |
| 800 | 829 |
| 801 // If none of the forms were parsed, no use querying the server. | 830 // If none of the forms were parsed, no use querying the server. |
| 802 if (!form_structures_.empty() && !disable_download_manager_requests_) { | 831 if (!form_structures_.empty() && !disable_download_manager_requests_) |
| 803 download_manager_.StartQueryRequest(form_structures_, | 832 download_manager_.StartQueryRequest(form_structures_, *metric_logger_); |
| 804 *metric_logger_); | |
| 805 } | |
| 806 | 833 |
| 807 for (std::vector<FormStructure *>::const_iterator iter = | 834 for (std::vector<FormStructure*>::const_iterator iter = |
| 808 non_queryable_forms.begin(); | 835 non_queryable_forms.begin(); |
| 809 iter != non_queryable_forms.end(); ++iter) { | 836 iter != non_queryable_forms.end(); ++iter) { |
| 810 form_structures_.push_back(*iter); | 837 form_structures_.push_back(*iter); |
| 811 } | 838 } |
| 812 } | 839 } |
| 813 | 840 |
| 814 // When sending IDs (across processes) to the renderer we pack credit card and | 841 // When sending IDs (across processes) to the renderer we pack credit card and |
| 815 // profile IDs into a single integer. Credit card IDs are sent in the high | 842 // profile IDs into a single integer. Credit card IDs are sent in the high |
| 816 // word and profile IDs are sent in the low word. | 843 // word and profile IDs are sent in the low word. |
| 817 int AutoFillManager::PackGUIDs(const std::string& cc_guid, | 844 int AutoFillManager::PackGUIDs(const std::string& cc_guid, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 860 return std::string(); | 887 return std::string(); |
| 861 | 888 |
| 862 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); | 889 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); |
| 863 if (iter == id_guid_map_.end()) { | 890 if (iter == id_guid_map_.end()) { |
| 864 NOTREACHED(); | 891 NOTREACHED(); |
| 865 return std::string(); | 892 return std::string(); |
| 866 } | 893 } |
| 867 | 894 |
| 868 return iter->second; | 895 return iter->second; |
| 869 } | 896 } |
| OLD | NEW |