Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/browser/autofill/autofill_manager.cc

Issue 6286003: Refactoring of upload, form saving, and UMA logging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move upload. Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 return; 199 return;
200 200
201 if (tab_contents_->profile()->IsOffTheRecord()) 201 if (tab_contents_->profile()->IsOffTheRecord())
202 return; 202 return;
203 203
204 // Don't save data that was submitted through JavaScript. 204 // Don't save data that was submitted through JavaScript.
205 if (!form.user_submitted) 205 if (!form.user_submitted)
206 return; 206 return;
207 207
208 // Grab a copy of the form data. 208 // Grab a copy of the form data.
209 upload_form_structure_.reset(new FormStructure(form)); 209 FormStructure submitted_form(form);
210 210
211 // Disregard forms that we wouldn't ever autofill in the first place. 211 // Disregard forms that we wouldn't ever autofill in the first place.
212 if (!upload_form_structure_->ShouldBeParsed(true)) 212 if (!submitted_form.ShouldBeParsed(true))
213 return; 213 return;
214 214
215 FormStructure* cached_upload_form_structure = NULL; 215 DeterminePossibleFieldTypesForUpload(&submitted_form);
216 AutoFillField* ignored; 216 LogMetricsAboutSubmittedForm(form, &submitted_form);
217 if (!FindCachedFormAndField(form, form.fields.front(),
218 &cached_upload_form_structure, &ignored)) {
219 cached_upload_form_structure = NULL;
220 }
221 217
222 DeterminePossibleFieldTypesForUpload(cached_upload_form_structure); 218 UploadFormData(submitted_form);
223 // TODO(isherman): Consider uploading to server here rather than in
224 // HandleSubmit().
225 219
226 if (!upload_form_structure_->IsAutoFillable(true)) 220 if (!submitted_form.IsAutoFillable(true))
227 return; 221 return;
228 222
229 HandleSubmit(); 223 ImportFormData(submitted_form);
230 } 224 }
231 225
232 void AutoFillManager::OnFormsSeen(const std::vector<FormData>& forms) { 226 void AutoFillManager::OnFormsSeen(const std::vector<FormData>& forms) {
233 if (!IsAutoFillEnabled()) 227 if (!IsAutoFillEnabled())
234 return; 228 return;
235 229
236 ParseForms(forms); 230 ParseForms(forms);
237 } 231 }
238 232
239 void AutoFillManager::OnQueryFormFieldAutoFill( 233 void AutoFillManager::OnQueryFormFieldAutoFill(
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 bool enabled = prefs->GetBoolean(prefs::kFormAutofillEnabled); 472 bool enabled = prefs->GetBoolean(prefs::kFormAutofillEnabled);
479 prefs->ClearPref(prefs::kFormAutofillEnabled); 473 prefs->ClearPref(prefs::kFormAutofillEnabled);
480 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled); 474 prefs->SetBoolean(prefs::kAutoFillEnabled, enabled);
481 return enabled; 475 return enabled;
482 } 476 }
483 477
484 return prefs->GetBoolean(prefs::kAutoFillEnabled); 478 return prefs->GetBoolean(prefs::kAutoFillEnabled);
485 } 479 }
486 480
487 void AutoFillManager::DeterminePossibleFieldTypesForUpload( 481 void AutoFillManager::DeterminePossibleFieldTypesForUpload(
488 const FormStructure* cached_upload_form_structure) { 482 FormStructure* submitted_form) {
489 for (size_t i = 0; i < upload_form_structure_->field_count(); i++) { 483 for (size_t i = 0; i < submitted_form->field_count(); i++) {
490 const AutoFillField* field = upload_form_structure_->field(i); 484 const AutoFillField* field = submitted_form->field(i);
491 FieldTypeSet field_types; 485 FieldTypeSet field_types;
492 personal_data_->GetPossibleFieldTypes(field->value(), &field_types); 486 personal_data_->GetPossibleFieldTypes(field->value(), &field_types);
493 DCHECK(!field_types.empty()); 487 DCHECK(!field_types.empty());
494 upload_form_structure_->set_possible_types(i, field_types); 488 submitted_form->set_possible_types(i, field_types);
489 }
490 }
491
492 void AutoFillManager::LogMetricsAboutSubmittedForm(
493 const FormData& form,
494 const FormStructure* submitted_form) {
495 FormStructure* cached_submitted_form = NULL;
496 AutoFillField* ignored;
497 if (!FindCachedFormAndField(form, form.fields.front(),
498 &cached_submitted_form, &ignored)) {
499 cached_submitted_form = NULL;
500 }
501
502 for (size_t i = 0; i < submitted_form->field_count(); i++) {
503 const AutoFillField* field = submitted_form->field(i);
504 FieldTypeSet field_types;
505 personal_data_->GetPossibleFieldTypes(field->value(), &field_types);
506 DCHECK(!field_types.empty());
495 507
496 if (field->form_control_type() == ASCIIToUTF16("select-one")) { 508 if (field->form_control_type() == ASCIIToUTF16("select-one")) {
497 // TODO(isherman): <select> fields don't support |is_autofilled()|. Since 509 // 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 510 // 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. 511 // for all <select> fields. Better to have less data than misleading data.
500 continue; 512 continue;
501 } 513 }
502 514
503 // Log various quality metrics. 515 // Log various quality metrics.
504 metric_logger_->Log(AutoFillMetrics::FIELD_SUBMITTED); 516 metric_logger_->Log(AutoFillMetrics::FIELD_SUBMITTED);
505 if (field_types.find(EMPTY_TYPE) == field_types.end() && 517 if (field_types.find(EMPTY_TYPE) == field_types.end() &&
506 field_types.find(UNKNOWN_TYPE) == field_types.end()) { 518 field_types.find(UNKNOWN_TYPE) == field_types.end()) {
507 if (field->is_autofilled()) { 519 if (field->is_autofilled()) {
508 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILLED); 520 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILLED);
509 } else { 521 } else {
510 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED); 522 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED);
511 523
512 AutoFillFieldType heuristic_type = cached_upload_form_structure? 524 AutoFillFieldType heuristic_type = cached_submitted_form?
513 cached_upload_form_structure->field(i)->heuristic_type() : 525 cached_submitted_form->field(i)->heuristic_type() :
514 UNKNOWN_TYPE; 526 UNKNOWN_TYPE;
515 if (heuristic_type == UNKNOWN_TYPE) 527 if (heuristic_type == UNKNOWN_TYPE)
516 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN); 528 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN);
517 else if (field_types.count(heuristic_type)) 529 else if (field_types.count(heuristic_type))
518 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MATCH); 530 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MATCH);
519 else 531 else
520 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH); 532 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH);
521 533
522 AutoFillFieldType server_type = cached_upload_form_structure? 534 AutoFillFieldType server_type = cached_submitted_form?
523 cached_upload_form_structure->field(i)->server_type() : 535 cached_submitted_form->field(i)->server_type() :
524 NO_SERVER_DATA; 536 NO_SERVER_DATA;
525 if (server_type == NO_SERVER_DATA) 537 if (server_type == NO_SERVER_DATA)
526 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_UNKNOWN); 538 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_UNKNOWN);
527 else if (field_types.count(server_type)) 539 else if (field_types.count(server_type))
528 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MATCH); 540 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MATCH);
529 else 541 else
530 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH); 542 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH);
531 } 543 }
532 544
533
534 // TODO(isherman): Other things we might want to log here: 545 // TODO(isherman): Other things we might want to log here:
535 // * Per Vadim's email, a combination of (1) whether heuristics fired, 546 // * Per Vadim's email, a combination of (1) whether heuristics fired,
536 // (2) whether the server returned something interesting, (3) whether 547 // (2) whether the server returned something interesting, (3) whether
537 // the user filled the field 548 // the user filled the field
538 // * Whether the server type matches the heursitic type 549 // * Whether the server type matches the heursitic type
539 // - Perhaps only if at least one of the types is not unknown/no data. 550 // - Perhaps only if at least one of the types is not unknown/no data.
540 } 551 }
541 } 552 }
542 } 553 }
543 554
544 void AutoFillManager::HandleSubmit() { 555 void AutoFillManager::ImportFormData(const FormStructure& submitted_form) {
545 // If there wasn't enough data to import then we don't want to send an upload 556 std::vector<const FormStructure*> import;
546 // to the server. 557 import.push_back(&submitted_form);
547 // TODO(jhawkins): Import form data from |form_structures_|. That will
548 // require querying the FormManager for updated field values.
549 std::vector<FormStructure*> import;
550 import.push_back(upload_form_structure_.get());
551 if (!personal_data_->ImportFormData(import)) 558 if (!personal_data_->ImportFormData(import))
552 return; 559 return;
553 560
554 // Did we get credit card info? 561 // Did we get credit card info?
555 AutoFillProfile* profile; 562 AutoFillProfile* profile;
556 CreditCard* credit_card; 563 CreditCard* credit_card;
557 personal_data_->GetImportedFormData(&profile, &credit_card); 564 personal_data_->GetImportedFormData(&profile, &credit_card);
558 565
559 if (!credit_card) { 566 // If credit card information was submitted, show an infobar to offer to save
560 UploadFormData(); 567 // it.
561 return; 568 if (credit_card && tab_contents_) {
562 }
563
564 // Show an infobar to offer to save the credit card info.
565 if (tab_contents_) {
566 tab_contents_->AddInfoBar(new AutoFillCCInfoBarDelegate(tab_contents_, 569 tab_contents_->AddInfoBar(new AutoFillCCInfoBarDelegate(tab_contents_,
567 this)); 570 this));
568 } 571 }
569 } 572 }
570 573
571 void AutoFillManager::UploadFormData() { 574 void AutoFillManager::UploadFormData(const FormStructure& submitted_form) {
572 if (!disable_download_manager_requests_ && upload_form_structure_.get()) { 575 if (!disable_download_manager_requests_) {
573 bool was_autofilled = false; 576 bool was_autofilled = false;
574 // Check if the form among last 3 forms that were auto-filled. 577 // Check if the form among last 3 forms that were auto-filled.
575 // Clear older signatures. 578 // Clear older signatures.
576 std::list<std::string>::iterator it; 579 std::list<std::string>::iterator it;
577 int total_form_checked = 0; 580 int total_form_checked = 0;
578 for (it = autofilled_forms_signatures_.begin(); 581 for (it = autofilled_forms_signatures_.begin();
579 it != autofilled_forms_signatures_.end() && total_form_checked < 3; 582 it != autofilled_forms_signatures_.end() && total_form_checked < 3;
580 ++it, ++total_form_checked) { 583 ++it, ++total_form_checked) {
581 if (*it == upload_form_structure_->FormSignature()) 584 if (*it == submitted_form.FormSignature())
582 was_autofilled = true; 585 was_autofilled = true;
583 } 586 }
584 // Remove outdated form signatures. 587 // Remove outdated form signatures.
585 if (total_form_checked == 3 && it != autofilled_forms_signatures_.end()) { 588 if (total_form_checked == 3 && it != autofilled_forms_signatures_.end()) {
586 autofilled_forms_signatures_.erase(it, 589 autofilled_forms_signatures_.erase(it,
587 autofilled_forms_signatures_.end()); 590 autofilled_forms_signatures_.end());
588 } 591 }
589 download_manager_.StartUploadRequest(*(upload_form_structure_.get()), 592 download_manager_.StartUploadRequest(submitted_form, was_autofilled);
590 was_autofilled);
591 } 593 }
592 } 594 }
593 595
594 void AutoFillManager::Reset() { 596 void AutoFillManager::Reset() {
595 upload_form_structure_.reset();
596 form_structures_.reset(); 597 form_structures_.reset();
597 } 598 }
598 599
599 void AutoFillManager::OnInfoBarClosed(bool should_save) { 600 void AutoFillManager::OnInfoBarClosed(bool should_save) {
600 if (should_save) 601 if (should_save)
601 personal_data_->SaveImportedCreditCard(); 602 personal_data_->SaveImportedCreditCard();
602 UploadFormData();
603 } 603 }
604 604
605 AutoFillManager::AutoFillManager() 605 AutoFillManager::AutoFillManager()
606 : tab_contents_(NULL), 606 : tab_contents_(NULL),
607 personal_data_(NULL), 607 personal_data_(NULL),
608 download_manager_(NULL), 608 download_manager_(NULL),
609 disable_download_manager_requests_(true), 609 disable_download_manager_requests_(true),
610 metric_logger_(new AutoFillMetrics), 610 metric_logger_(new AutoFillMetrics),
611 cc_infobar_(NULL) { 611 cc_infobar_(NULL) {
612 } 612 }
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
886 return std::string(); 886 return std::string();
887 887
888 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); 888 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id);
889 if (iter == id_guid_map_.end()) { 889 if (iter == id_guid_map_.end()) {
890 NOTREACHED(); 890 NOTREACHED();
891 return std::string(); 891 return std::string();
892 } 892 }
893 893
894 return iter->second; 894 return iter->second;
895 } 895 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/autofill/personal_data_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698