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

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

Issue 11636040: AutofillPopupController clarifications + simplifications. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ilya review Created 8 years 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/personal_data_manager.h" 5 #include "chrome/browser/autofill/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <iterator> 9 #include <iterator>
10 10
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 534
535 const std::vector<CreditCard*>& PersonalDataManager::credit_cards() const { 535 const std::vector<CreditCard*>& PersonalDataManager::credit_cards() const {
536 return credit_cards_.get(); 536 return credit_cards_.get();
537 } 537 }
538 538
539 void PersonalDataManager::Refresh() { 539 void PersonalDataManager::Refresh() {
540 LoadProfiles(); 540 LoadProfiles();
541 LoadCreditCards(); 541 LoadCreditCards();
542 } 542 }
543 543
544 void PersonalDataManager::GetProfileSuggestions(
545 AutofillFieldType type,
546 const string16& field_contents,
547 bool field_is_autofilled,
548 std::vector<AutofillFieldType> other_field_types,
549 std::vector<string16>* labels,
550 std::vector<string16>* sub_labels,
551 std::vector<string16>* icons,
552 std::vector<GUIDPair>* guid_pairs) {
553 labels->clear();
554 sub_labels->clear();
555 icons->clear();
556 guid_pairs->clear();
557
558 const std::vector<AutofillProfile*>& profiles = GetProfiles();
559 const std::string app_locale = AutofillCountry::ApplicationLocale();
560 std::vector<AutofillProfile*> matched_profiles;
561 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin();
562 iter != profiles.end(); ++iter) {
563 AutofillProfile* profile = *iter;
564
565 // The value of the stored data for this field type in the |profile|.
566 std::vector<string16> multi_values;
567 profile->GetMultiInfo(type, app_locale, &multi_values);
568
569 for (size_t i = 0; i < multi_values.size(); ++i) {
570 if (!field_is_autofilled) {
571 // Suggest data that starts with what the user has typed.
572 if (!multi_values[i].empty() &&
573 StartsWith(multi_values[i], field_contents, false)) {
574 matched_profiles.push_back(profile);
575 labels->push_back(multi_values[i]);
576 guid_pairs->push_back(GUIDPair(profile->guid(), i));
577 }
578 } else {
579 if (multi_values[i].empty())
580 continue;
581
582 string16 profile_value_lower_case(
583 StringToLowerASCII(multi_values[i]));
584 string16 field_value_lower_case(StringToLowerASCII(field_contents));
585 // Phone numbers could be split in US forms, so field value could be
586 // either prefix or suffix of the phone.
587 bool matched_phones = false;
588 if (type == PHONE_HOME_NUMBER && !field_value_lower_case.empty() &&
589 (profile_value_lower_case.find(field_value_lower_case) !=
590 string16::npos)) {
591 matched_phones = true;
592 }
593
594 // Suggest variants of the profile that's already been filled in.
595 if (matched_phones ||
596 profile_value_lower_case == field_value_lower_case) {
597 for (size_t j = 0; j < multi_values.size(); ++j) {
598 if (!multi_values[j].empty()) {
599 labels->push_back(multi_values[j]);
600 guid_pairs->push_back(GUIDPair(profile->guid(), j));
601 }
602 }
603
604 // We've added all the values for this profile so move on to the
605 // next.
606 break;
607 }
608 }
609 }
610 }
611
612 if (!field_is_autofilled) {
613 AutofillProfile::CreateInferredLabels(
614 &matched_profiles, &other_field_types,
615 type, 1, sub_labels);
616 } else {
617 // No sub-labels for previously filled fields.
618 sub_labels->resize(labels->size());
619 }
620
621 // No icons for profile suggestions.
622 icons->resize(labels->size());
623 }
624
544 PersonalDataManager::PersonalDataManager() 625 PersonalDataManager::PersonalDataManager()
545 : browser_context_(NULL), 626 : browser_context_(NULL),
546 is_data_loaded_(false), 627 is_data_loaded_(false),
547 pending_profiles_query_(0), 628 pending_profiles_query_(0),
548 pending_creditcards_query_(0), 629 pending_creditcards_query_(0),
549 metric_logger_(new AutofillMetrics), 630 metric_logger_(new AutofillMetrics),
550 has_logged_profile_count_(false) { 631 has_logged_profile_count_(false) {
551 } 632 }
552 633
553 void PersonalDataManager::Init(BrowserContext* browser_context) { 634 void PersonalDataManager::Init(BrowserContext* browser_context) {
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
922 1003
923 void PersonalDataManager::set_metric_logger( 1004 void PersonalDataManager::set_metric_logger(
924 const AutofillMetrics* metric_logger) { 1005 const AutofillMetrics* metric_logger) {
925 metric_logger_.reset(metric_logger); 1006 metric_logger_.reset(metric_logger);
926 } 1007 }
927 1008
928 void PersonalDataManager::set_browser_context( 1009 void PersonalDataManager::set_browser_context(
929 content::BrowserContext* context) { 1010 content::BrowserContext* context) {
930 browser_context_ = context; 1011 browser_context_ = context;
931 } 1012 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698