Chromium Code Reviews| 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 return; | 213 return; |
| 214 | 214 |
| 215 FormStructure* cached_upload_form_structure = NULL; | 215 FormStructure* cached_upload_form_structure = NULL; |
| 216 AutoFillField* ignored; | 216 AutoFillField* ignored; |
| 217 if (!FindCachedFormAndField(form, form.fields.front(), | 217 if (!FindCachedFormAndField(form, form.fields.front(), |
| 218 &cached_upload_form_structure, &ignored)) { | 218 &cached_upload_form_structure, &ignored)) { |
| 219 cached_upload_form_structure = NULL; | 219 cached_upload_form_structure = NULL; |
| 220 } | 220 } |
| 221 | 221 |
| 222 DeterminePossibleFieldTypesForUpload(cached_upload_form_structure); | 222 DeterminePossibleFieldTypesForUpload(cached_upload_form_structure); |
| 223 | |
| 224 UploadFormData(); | |
| 225 | |
| 223 // TODO(isherman): Consider uploading to server here rather than in | 226 // TODO(isherman): Consider uploading to server here rather than in |
| 224 // HandleSubmit(). | 227 // SaveFormData(). |
| 225 | 228 |
| 226 if (!upload_form_structure_->IsAutoFillable(true)) | 229 if (!upload_form_structure_->IsAutoFillable(true)) |
| 227 return; | 230 return; |
| 228 | 231 |
| 229 HandleSubmit(); | 232 SaveFormData(); |
| 230 } | 233 } |
| 231 | 234 |
| 232 void AutoFillManager::OnFormsSeen(const std::vector<FormData>& forms) { | 235 void AutoFillManager::OnFormsSeen(const std::vector<FormData>& forms) { |
| 233 if (!IsAutoFillEnabled()) | 236 if (!IsAutoFillEnabled()) |
| 234 return; | 237 return; |
| 235 | 238 |
| 236 ParseForms(forms); | 239 ParseForms(forms); |
| 237 } | 240 } |
| 238 | 241 |
| 239 void AutoFillManager::OnQueryFormFieldAutoFill( | 242 void AutoFillManager::OnQueryFormFieldAutoFill( |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 prefs->ClearPref(prefs::kFormAutofillEnabled); | 482 prefs->ClearPref(prefs::kFormAutofillEnabled); |
| 480 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled); | 483 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled); |
| 481 return enabled; | 484 return enabled; |
| 482 } | 485 } |
| 483 | 486 |
| 484 return prefs->GetBoolean(prefs::kAutoFillEnabled); | 487 return prefs->GetBoolean(prefs::kAutoFillEnabled); |
| 485 } | 488 } |
| 486 | 489 |
| 487 void AutoFillManager::DeterminePossibleFieldTypesForUpload( | 490 void AutoFillManager::DeterminePossibleFieldTypesForUpload( |
| 488 const FormStructure* cached_upload_form_structure) { | 491 const FormStructure* cached_upload_form_structure) { |
| 492 download_manager_.ClearPresence(); | |
| 493 | |
| 489 for (size_t i = 0; i < upload_form_structure_->field_count(); i++) { | 494 for (size_t i = 0; i < upload_form_structure_->field_count(); i++) { |
| 490 const AutoFillField* field = upload_form_structure_->field(i); | 495 const AutoFillField* field = upload_form_structure_->field(i); |
| 491 FieldTypeSet field_types; | 496 FieldTypeSet field_types; |
| 492 personal_data_->GetPossibleFieldTypes(field->value(), &field_types); | 497 personal_data_->GetPossibleFieldTypes(field->value(), &field_types); |
| 493 DCHECK(!field_types.empty()); | |
| 494 upload_form_structure_->set_possible_types(i, field_types); | |
| 495 | 498 |
| 496 if (field->form_control_type() == ASCIIToUTF16("select-one")) { | 499 if (field->form_control_type() == ASCIIToUTF16("select-one")) { |
| 497 // TODO(isherman): <select> fields don't support |is_autofilled()|. Since | 500 // TODO(isherman): <select> fields don't support |is_autofilled()|. Since |
| 498 // this is heavily relied upon by our metrics, we just don't log anything | 501 // this is heavily relied upon by our metrics, we just don't log anything |
| 499 // for all <select> fields. Better to have less data than misleading data. | 502 // for all <select> fields. Better to have less data than misleading data. |
| 500 continue; | 503 } else { |
|
dhollowa
2011/01/18 22:31:26
As per our discussion, let's pull this logging stu
GeorgeY
2011/01/20 19:12:29
Moved back (with a slight change) so you could com
| |
| 504 // Log various quality metrics. | |
| 505 metric_logger_->Log(AutoFillMetrics::FIELD_SUBMITTED); | |
| 506 if (field_types.find(EMPTY_TYPE) == field_types.end() && | |
| 507 field_types.find(UNKNOWN_TYPE) == field_types.end()) { | |
| 508 if (field->is_autofilled()) { | |
| 509 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILLED); | |
| 510 } else { | |
| 511 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED); | |
| 512 | |
| 513 AutoFillFieldType heuristic_type = cached_upload_form_structure? | |
| 514 cached_upload_form_structure->field(i)->heuristic_type() : | |
| 515 UNKNOWN_TYPE; | |
| 516 if (heuristic_type == UNKNOWN_TYPE) | |
| 517 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN); | |
| 518 else if (field_types.count(heuristic_type)) | |
| 519 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MATCH); | |
| 520 else | |
| 521 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH); | |
| 522 | |
| 523 AutoFillFieldType server_type = cached_upload_form_structure? | |
| 524 cached_upload_form_structure->field(i)->server_type() : | |
| 525 NO_SERVER_DATA; | |
| 526 if (server_type == NO_SERVER_DATA) | |
| 527 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_UNKNOWN); | |
| 528 else if (field_types.count(server_type)) | |
| 529 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MATCH); | |
| 530 else | |
| 531 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH); | |
| 532 } | |
| 533 | |
| 534 | |
| 535 // TODO(isherman): Other things we might want to log here: | |
| 536 // * Per Vadim's email, a combination of (1) whether heuristics fired, | |
| 537 // (2) whether the server returned something interesting, (3) whether | |
| 538 // the user filled the field | |
| 539 // * Whether the server type matches the heursitic type | |
| 540 // - Perhaps only if at least one of the types is not unknown/no data. | |
| 541 } | |
| 542 } | |
| 543 DCHECK(!field_types.empty()); | |
| 544 if (field_types.size() > 1) { | |
| 545 // If there is more than one possibility, do not poison the crowd-sourced | |
| 546 // data by returning UNKNOWN_TYPE. | |
| 547 field_types.clear(); | |
| 548 field_types.insert(UNKNOWN_TYPE); | |
| 501 } | 549 } |
| 502 | 550 |
| 503 // Log various quality metrics. | 551 upload_form_structure_->set_possible_types(i, field_types); |
| 504 metric_logger_->Log(AutoFillMetrics::FIELD_SUBMITTED); | 552 download_manager_.SetPresenceBit(*(field_types.begin())); |
| 505 if (field_types.find(EMPTY_TYPE) == field_types.end() && | |
| 506 field_types.find(UNKNOWN_TYPE) == field_types.end()) { | |
| 507 if (field->is_autofilled()) { | |
| 508 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILLED); | |
| 509 } else { | |
| 510 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED); | |
| 511 | |
| 512 AutoFillFieldType heuristic_type = cached_upload_form_structure? | |
| 513 cached_upload_form_structure->field(i)->heuristic_type() : | |
| 514 UNKNOWN_TYPE; | |
| 515 if (heuristic_type == UNKNOWN_TYPE) | |
| 516 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN); | |
| 517 else if (field_types.count(heuristic_type)) | |
| 518 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MATCH); | |
| 519 else | |
| 520 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH); | |
| 521 | |
| 522 AutoFillFieldType server_type = cached_upload_form_structure? | |
| 523 cached_upload_form_structure->field(i)->server_type() : | |
| 524 NO_SERVER_DATA; | |
| 525 if (server_type == NO_SERVER_DATA) | |
| 526 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_UNKNOWN); | |
| 527 else if (field_types.count(server_type)) | |
| 528 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MATCH); | |
| 529 else | |
| 530 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH); | |
| 531 } | |
| 532 | |
| 533 | |
| 534 // TODO(isherman): Other things we might want to log here: | |
| 535 // * Per Vadim's email, a combination of (1) whether heuristics fired, | |
| 536 // (2) whether the server returned something interesting, (3) whether | |
| 537 // the user filled the field | |
| 538 // * Whether the server type matches the heursitic type | |
| 539 // - Perhaps only if at least one of the types is not unknown/no data. | |
| 540 } | |
| 541 } | 553 } |
| 542 } | 554 } |
| 543 | 555 |
| 544 void AutoFillManager::HandleSubmit() { | 556 void AutoFillManager::SaveFormData() { |
| 545 // If there wasn't enough data to import then we don't want to send an upload | 557 // If there wasn't enough data to import then we don't want to send an upload |
| 546 // to the server. | 558 // to the server. |
| 547 // TODO(jhawkins): Import form data from |form_structures_|. That will | 559 // TODO(jhawkins): Import form data from |form_structures_|. That will |
| 548 // require querying the FormManager for updated field values. | 560 // require querying the FormManager for updated field values. |
| 549 std::vector<FormStructure*> import; | 561 std::vector<FormStructure*> import; |
| 550 import.push_back(upload_form_structure_.get()); | 562 import.push_back(upload_form_structure_.get()); |
| 551 if (!personal_data_->ImportFormData(import)) | 563 if (!personal_data_->ImportFormData(import)) |
| 552 return; | 564 return; |
| 553 | 565 |
| 554 // Did we get credit card info? | 566 // Did we get credit card info? |
| 555 AutoFillProfile* profile; | 567 AutoFillProfile* profile; |
| 556 CreditCard* credit_card; | 568 CreditCard* credit_card; |
| 557 personal_data_->GetImportedFormData(&profile, &credit_card); | 569 personal_data_->GetImportedFormData(&profile, &credit_card); |
| 558 | 570 |
| 559 if (!credit_card) { | 571 if (!credit_card) |
| 560 UploadFormData(); | |
| 561 return; | 572 return; |
| 562 } | |
| 563 | 573 |
| 564 // Show an infobar to offer to save the credit card info. | 574 // Show an infobar to offer to save the credit card info. |
| 565 if (tab_contents_) { | 575 if (tab_contents_) { |
| 566 tab_contents_->AddInfoBar(new AutoFillCCInfoBarDelegate(tab_contents_, | 576 tab_contents_->AddInfoBar(new AutoFillCCInfoBarDelegate(tab_contents_, |
| 567 this)); | 577 this)); |
| 568 } | 578 } |
| 569 } | 579 } |
| 570 | 580 |
| 571 void AutoFillManager::UploadFormData() { | 581 void AutoFillManager::UploadFormData() { |
| 572 if (!disable_download_manager_requests_ && upload_form_structure_.get()) { | 582 if (!disable_download_manager_requests_ && upload_form_structure_.get()) { |
| 573 bool was_autofilled = false; | 583 bool was_autofilled = false; |
| 574 // Check if the form among last 3 forms that were auto-filled. | 584 // Check if the form among last 3 forms that were auto-filled. |
| 575 // Clear older signatures. | 585 // Clear older signatures. |
| 576 std::list<std::string>::iterator it; | 586 std::list<std::string>::iterator it; |
| 577 int total_form_checked = 0; | 587 int total_form_checked = 0; |
| 578 for (it = autofilled_forms_signatures_.begin(); | 588 for (it = autofilled_forms_signatures_.begin(); |
| 579 it != autofilled_forms_signatures_.end() && total_form_checked < 3; | 589 it != autofilled_forms_signatures_.end() && total_form_checked < 3; |
| 580 ++it, ++total_form_checked) { | 590 ++it, ++total_form_checked) { |
| 581 if (*it == upload_form_structure_->FormSignature()) | 591 if (*it == upload_form_structure_->FormSignature()) { |
|
dhollowa
2011/01/18 22:31:26
nit: Style guide says no braces if the body and co
GeorgeY
2011/01/20 19:12:29
Done.
| |
| 582 was_autofilled = true; | 592 was_autofilled = true; |
| 593 } | |
| 583 } | 594 } |
| 584 // Remove outdated form signatures. | 595 // Remove outdated form signatures. |
| 585 if (total_form_checked == 3 && it != autofilled_forms_signatures_.end()) { | 596 if (total_form_checked == 3 && it != autofilled_forms_signatures_.end()) { |
| 586 autofilled_forms_signatures_.erase(it, | 597 autofilled_forms_signatures_.erase(it, |
| 587 autofilled_forms_signatures_.end()); | 598 autofilled_forms_signatures_.end()); |
| 588 } | 599 } |
| 589 download_manager_.StartUploadRequest(*(upload_form_structure_.get()), | 600 download_manager_.StartUploadRequest(*(upload_form_structure_.get()), |
| 590 was_autofilled); | 601 was_autofilled); |
| 591 } | 602 } |
| 592 } | 603 } |
| 593 | 604 |
| 594 void AutoFillManager::Reset() { | 605 void AutoFillManager::Reset() { |
| 595 upload_form_structure_.reset(); | 606 upload_form_structure_.reset(); |
| 596 form_structures_.reset(); | 607 form_structures_.reset(); |
| 597 } | 608 } |
| 598 | 609 |
| 599 void AutoFillManager::OnInfoBarClosed(bool should_save) { | 610 void AutoFillManager::OnInfoBarClosed(bool should_save) { |
| 600 if (should_save) | 611 if (should_save) |
| 601 personal_data_->SaveImportedCreditCard(); | 612 personal_data_->SaveImportedCreditCard(); |
| 602 UploadFormData(); | |
| 603 } | 613 } |
| 604 | 614 |
| 605 AutoFillManager::AutoFillManager() | 615 AutoFillManager::AutoFillManager() |
| 606 : tab_contents_(NULL), | 616 : tab_contents_(NULL), |
| 607 personal_data_(NULL), | 617 personal_data_(NULL), |
| 608 download_manager_(NULL), | 618 download_manager_(NULL), |
| 609 disable_download_manager_requests_(true), | 619 disable_download_manager_requests_(true), |
| 610 metric_logger_(new AutoFillMetrics), | 620 metric_logger_(new AutoFillMetrics), |
| 611 cc_infobar_(NULL) { | 621 cc_infobar_(NULL) { |
| 612 } | 622 } |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 886 return std::string(); | 896 return std::string(); |
| 887 | 897 |
| 888 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); | 898 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); |
| 889 if (iter == id_guid_map_.end()) { | 899 if (iter == id_guid_map_.end()) { |
| 890 NOTREACHED(); | 900 NOTREACHED(); |
| 891 return std::string(); | 901 return std::string(); |
| 892 } | 902 } |
| 893 | 903 |
| 894 return iter->second; | 904 return iter->second; |
| 895 } | 905 } |
| OLD | NEW |