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

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

Issue 6259017: Fix crash in autofill metrics logging. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitespace 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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 FieldTypeSet field_types; 491 FieldTypeSet field_types;
492 personal_data_->GetPossibleFieldTypes(field->value(), &field_types); 492 personal_data_->GetPossibleFieldTypes(field->value(), &field_types);
493 DCHECK(!field_types.empty()); 493 DCHECK(!field_types.empty());
494 submitted_form->set_possible_types(i, field_types); 494 submitted_form->set_possible_types(i, field_types);
495 } 495 }
496 } 496 }
497 497
498 void AutoFillManager::LogMetricsAboutSubmittedForm( 498 void AutoFillManager::LogMetricsAboutSubmittedForm(
499 const FormData& form, 499 const FormData& form,
500 const FormStructure* submitted_form) { 500 const FormStructure* submitted_form) {
501 FormStructure* cached_submitted_form = NULL; 501 FormStructure* cached_submitted_form;
502 AutoFillField* ignored; 502 if (!FindCachedForm(form, &cached_submitted_form)) {
503 if (!FindCachedFormAndField(form, form.fields.front(), 503 NOTREACHED();
504 &cached_submitted_form, &ignored)) { 504 return;
505 cached_submitted_form = NULL;
506 } 505 }
507 506
508 for (size_t i = 0; i < submitted_form->field_count(); i++) { 507 // Map from field signatures to cached fields.
508 std::map<std::string, const AutoFillField*> cached_fields;
509 for (size_t i = 0; i < cached_submitted_form->field_count(); ++i) {
510 const AutoFillField* field = cached_submitted_form->field(i);
511 cached_fields[field->FieldSignature()] = field;
512 }
513
514 for (size_t i = 0; i < submitted_form->field_count(); ++i) {
509 const AutoFillField* field = submitted_form->field(i); 515 const AutoFillField* field = submitted_form->field(i);
510 FieldTypeSet field_types; 516 FieldTypeSet field_types;
511 personal_data_->GetPossibleFieldTypes(field->value(), &field_types); 517 personal_data_->GetPossibleFieldTypes(field->value(), &field_types);
512 DCHECK(!field_types.empty()); 518 DCHECK(!field_types.empty());
513 519
514 if (field->form_control_type() == ASCIIToUTF16("select-one")) { 520 if (field->form_control_type() == ASCIIToUTF16("select-one")) {
515 // TODO(isherman): <select> fields don't support |is_autofilled()|. Since 521 // TODO(isherman): <select> fields don't support |is_autofilled()|. Since
516 // this is heavily relied upon by our metrics, we just don't log anything 522 // this is heavily relied upon by our metrics, we just don't log anything
517 // for all <select> fields. Better to have less data than misleading data. 523 // for all <select> fields. Better to have less data than misleading data.
518 continue; 524 continue;
519 } 525 }
520 526
521 // Log various quality metrics. 527 // Log various quality metrics.
522 metric_logger_->Log(AutoFillMetrics::FIELD_SUBMITTED); 528 metric_logger_->Log(AutoFillMetrics::FIELD_SUBMITTED);
523 if (field_types.find(EMPTY_TYPE) == field_types.end() && 529 if (field_types.find(EMPTY_TYPE) == field_types.end() &&
524 field_types.find(UNKNOWN_TYPE) == field_types.end()) { 530 field_types.find(UNKNOWN_TYPE) == field_types.end()) {
525 if (field->is_autofilled()) { 531 if (field->is_autofilled()) {
526 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILLED); 532 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILLED);
527 } else { 533 } else {
528 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED); 534 metric_logger_->Log(AutoFillMetrics::FIELD_AUTOFILL_FAILED);
529 535
530 AutoFillFieldType heuristic_type = cached_submitted_form? 536 AutoFillFieldType heuristic_type = UNKNOWN_TYPE;
531 cached_submitted_form->field(i)->heuristic_type() : 537 AutoFillFieldType server_type = NO_SERVER_DATA;
532 UNKNOWN_TYPE; 538 std::map<std::string, const AutoFillField*>::const_iterator
539 cached_field = cached_fields.find(field->FieldSignature());
540 if (cached_field != cached_fields.end()) {
541 heuristic_type = cached_field->second->heuristic_type();
542 server_type = cached_field->second->server_type();
543 }
544
533 if (heuristic_type == UNKNOWN_TYPE) 545 if (heuristic_type == UNKNOWN_TYPE)
534 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN); 546 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_UNKNOWN);
535 else if (field_types.count(heuristic_type)) 547 else if (field_types.count(heuristic_type))
536 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MATCH); 548 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MATCH);
537 else 549 else
538 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH); 550 metric_logger_->Log(AutoFillMetrics::FIELD_HEURISTIC_TYPE_MISMATCH);
539 551
540 AutoFillFieldType server_type = cached_submitted_form?
541 cached_submitted_form->field(i)->server_type() :
542 NO_SERVER_DATA;
543 if (server_type == NO_SERVER_DATA) 552 if (server_type == NO_SERVER_DATA)
544 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_UNKNOWN); 553 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_UNKNOWN);
545 else if (field_types.count(server_type)) 554 else if (field_types.count(server_type))
546 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MATCH); 555 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MATCH);
547 else 556 else
548 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH); 557 metric_logger_->Log(AutoFillMetrics::FIELD_SERVER_TYPE_MISMATCH);
549 } 558 }
550 559
551 // TODO(isherman): Other things we might want to log here: 560 // TODO(isherman): Other things we might want to log here:
552 // * Per Vadim's email, a combination of (1) whether heuristics fired, 561 // * Per Vadim's email, a combination of (1) whether heuristics fired,
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 if (profiles.empty() && credit_cards.empty()) 652 if (profiles.empty() && credit_cards.empty())
644 return false; 653 return false;
645 654
646 *host = tab_contents_->render_view_host(); 655 *host = tab_contents_->render_view_host();
647 if (!*host) 656 if (!*host)
648 return false; 657 return false;
649 658
650 return true; 659 return true;
651 } 660 }
652 661
653 bool AutoFillManager::FindCachedFormAndField(const FormData& form, 662 bool AutoFillManager::FindCachedForm(const FormData& form,
654 const FormField& field, 663 FormStructure** form_structure) {
655 FormStructure** form_structure,
656 AutoFillField** autofill_field) {
657 // Find the FormStructure that corresponds to |form|. 664 // Find the FormStructure that corresponds to |form|.
658 *form_structure = NULL; 665 *form_structure = NULL;
659 for (std::vector<FormStructure*>::const_iterator iter = 666 for (std::vector<FormStructure*>::const_iterator iter =
660 form_structures_.begin(); 667 form_structures_.begin();
661 iter != form_structures_.end(); ++iter) { 668 iter != form_structures_.end(); ++iter) {
662 if (**iter == form) { 669 if (**iter == form) {
663 *form_structure = *iter; 670 *form_structure = *iter;
664 break; 671 break;
665 } 672 }
666 } 673 }
667 674
668 if (!(*form_structure)) 675 if (!(*form_structure))
669 return false; 676 return false;
670 677
678 return true;
679 }
680
681 bool AutoFillManager::FindCachedFormAndField(const FormData& form,
682 const FormField& field,
683 FormStructure** form_structure,
684 AutoFillField** autofill_field) {
685 // Find the FormStructure that corresponds to |form|.
686 if (!FindCachedForm(form, form_structure))
687 return false;
688
671 // No data to return if there are no auto-fillable fields. 689 // No data to return if there are no auto-fillable fields.
672 if (!(*form_structure)->autofill_count()) 690 if (!(*form_structure)->autofill_count())
673 return false; 691 return false;
674 692
675 // Find the AutoFillField that corresponds to |field|. 693 // Find the AutoFillField that corresponds to |field|.
676 *autofill_field = NULL; 694 *autofill_field = NULL;
677 for (std::vector<AutoFillField*>::const_iterator iter = 695 for (std::vector<AutoFillField*>::const_iterator iter =
678 (*form_structure)->begin(); 696 (*form_structure)->begin();
679 iter != (*form_structure)->end(); ++iter) { 697 iter != (*form_structure)->end(); ++iter) {
680 // The field list is terminated with a NULL AutoFillField, so don't try to 698 // The field list is terminated with a NULL AutoFillField, so don't try to
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 return std::string(); 910 return std::string();
893 911
894 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id); 912 std::map<int, std::string>::const_iterator iter = id_guid_map_.find(id);
895 if (iter == id_guid_map_.end()) { 913 if (iter == id_guid_map_.end()) {
896 NOTREACHED(); 914 NOTREACHED();
897 return std::string(); 915 return std::string();
898 } 916 }
899 917
900 return iter->second; 918 return iter->second;
901 } 919 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/autofill/autofill_metrics_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698