| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 558 |
| 559 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { | 559 CreditCard* PersonalDataManager::GetCreditCardByGUID(const std::string& guid) { |
| 560 for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin(); | 560 for (std::vector<CreditCard*>::iterator iter = credit_cards_.begin(); |
| 561 iter != credit_cards_.end(); ++iter) { | 561 iter != credit_cards_.end(); ++iter) { |
| 562 if ((*iter)->guid() == guid) | 562 if ((*iter)->guid() == guid) |
| 563 return *iter; | 563 return *iter; |
| 564 } | 564 } |
| 565 return NULL; | 565 return NULL; |
| 566 } | 566 } |
| 567 | 567 |
| 568 void PersonalDataManager::GetPossibleFieldTypes(const string16& text, | 568 void PersonalDataManager::GetPossibleFieldTypes( |
| 569 FieldTypeSet* possible_types) { | 569 const string16& text, |
| 570 FieldTypeSet* possible_types) const { |
| 570 string16 clean_info = StringToLowerASCII(CollapseWhitespace(text, false)); | 571 string16 clean_info = StringToLowerASCII(CollapseWhitespace(text, false)); |
| 571 if (clean_info.empty()) { | 572 if (clean_info.empty()) { |
| 572 possible_types->insert(EMPTY_TYPE); | 573 possible_types->insert(EMPTY_TYPE); |
| 573 return; | 574 return; |
| 574 } | 575 } |
| 575 | 576 |
| 576 const std::vector<AutofillProfile*>& profiles = this->profiles(); | 577 const std::vector<AutofillProfile*>& profiles = this->profiles(); |
| 577 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); | 578 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); |
| 578 iter != profiles.end(); ++iter) { | 579 iter != profiles.end(); ++iter) { |
| 579 const FormGroup* profile = *iter; | 580 const FormGroup* profile = *iter; |
| 580 if (!profile) { | 581 if (!profile) { |
| 581 DLOG(ERROR) << "NULL information in profiles list"; | 582 DLOG(ERROR) << "NULL information in profiles list"; |
| 582 continue; | 583 continue; |
| 583 } | 584 } |
| 584 | 585 |
| 585 profile->GetPossibleFieldTypes(clean_info, possible_types); | 586 profile->GetPossibleFieldTypes(clean_info, possible_types); |
| 586 } | 587 } |
| 587 | 588 |
| 588 for (ScopedVector<CreditCard>::iterator iter = credit_cards_.begin(); | 589 for (ScopedVector<CreditCard>::const_iterator iter = credit_cards_.begin(); |
| 589 iter != credit_cards_.end(); ++iter) { | 590 iter != credit_cards_.end(); ++iter) { |
| 590 const FormGroup* credit_card = *iter; | 591 const FormGroup* credit_card = *iter; |
| 591 if (!credit_card) { | 592 if (!credit_card) { |
| 592 DLOG(ERROR) << "NULL information in credit cards list"; | 593 DLOG(ERROR) << "NULL information in credit cards list"; |
| 593 continue; | 594 continue; |
| 594 } | 595 } |
| 595 | 596 |
| 596 credit_card->GetPossibleFieldTypes(clean_info, possible_types); | 597 credit_card->GetPossibleFieldTypes(clean_info, possible_types); |
| 597 } | 598 } |
| 598 | 599 |
| 599 if (possible_types->empty()) | 600 if (possible_types->empty()) |
| 600 possible_types->insert(UNKNOWN_TYPE); | 601 possible_types->insert(UNKNOWN_TYPE); |
| 601 } | 602 } |
| 602 | 603 |
| 604 void PersonalDataManager::GetAvailableFieldTypes( |
| 605 FieldTypeSet* available_types) const { |
| 606 const std::vector<AutofillProfile*>& profiles = this->profiles(); |
| 607 for (std::vector<AutofillProfile*>::const_iterator iter = profiles.begin(); |
| 608 iter != profiles.end(); ++iter) { |
| 609 (*iter)->GetAvailableFieldTypes(available_types); |
| 610 } |
| 611 |
| 612 for (ScopedVector<CreditCard>::const_iterator iter = credit_cards_.begin(); |
| 613 iter != credit_cards_.end(); ++iter) { |
| 614 (*iter)->GetAvailableFieldTypes(available_types); |
| 615 } |
| 616 } |
| 617 |
| 603 bool PersonalDataManager::HasPassword() { | 618 bool PersonalDataManager::HasPassword() { |
| 604 return !password_hash_.empty(); | 619 return !password_hash_.empty(); |
| 605 } | 620 } |
| 606 | 621 |
| 607 bool PersonalDataManager::IsDataLoaded() const { | 622 bool PersonalDataManager::IsDataLoaded() const { |
| 608 return is_data_loaded_; | 623 return is_data_loaded_; |
| 609 } | 624 } |
| 610 | 625 |
| 611 const std::vector<AutofillProfile*>& PersonalDataManager::profiles() { | 626 const std::vector<AutofillProfile*>& PersonalDataManager::profiles() const { |
| 612 // |profile_| is NULL in AutofillManagerTest. | 627 // |profile_| is NULL in AutofillManagerTest. |
| 613 bool auxiliary_profiles_enabled = profile_ ? profile_->GetPrefs()->GetBoolean( | 628 bool auxiliary_profiles_enabled = profile_ ? profile_->GetPrefs()->GetBoolean( |
| 614 prefs::kAutofillAuxiliaryProfilesEnabled) : false; | 629 prefs::kAutofillAuxiliaryProfilesEnabled) : false; |
| 615 if (!auxiliary_profiles_enabled) | 630 if (!auxiliary_profiles_enabled) |
| 616 return web_profiles(); | 631 return web_profiles(); |
| 617 | 632 |
| 618 #if !defined(OS_MACOSX) | 633 #if !defined(OS_MACOSX) |
| 619 NOTREACHED() << "Auxiliary profiles supported on Mac only"; | 634 NOTREACHED() << "Auxiliary profiles supported on Mac only"; |
| 620 #endif | 635 #endif |
| 621 | 636 |
| 622 profiles_.clear(); | 637 profiles_.clear(); |
| 623 | 638 |
| 624 // Populates |auxiliary_profiles_|. | 639 // Populates |auxiliary_profiles_|. |
| 625 LoadAuxiliaryProfiles(); | 640 LoadAuxiliaryProfiles(); |
| 626 | 641 |
| 627 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); | 642 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); |
| 628 profiles_.insert(profiles_.end(), | 643 profiles_.insert(profiles_.end(), |
| 629 auxiliary_profiles_.begin(), auxiliary_profiles_.end()); | 644 auxiliary_profiles_.begin(), auxiliary_profiles_.end()); |
| 630 return profiles_; | 645 return profiles_; |
| 631 } | 646 } |
| 632 | 647 |
| 633 const std::vector<AutofillProfile*>& PersonalDataManager::web_profiles() { | 648 const std::vector<AutofillProfile*>& PersonalDataManager::web_profiles() const { |
| 634 return web_profiles_.get(); | 649 return web_profiles_.get(); |
| 635 } | 650 } |
| 636 | 651 |
| 637 const std::vector<CreditCard*>& PersonalDataManager::credit_cards() { | 652 const std::vector<CreditCard*>& PersonalDataManager::credit_cards() const { |
| 638 return credit_cards_.get(); | 653 return credit_cards_.get(); |
| 639 } | 654 } |
| 640 | 655 |
| 641 void PersonalDataManager::Refresh() { | 656 void PersonalDataManager::Refresh() { |
| 642 LoadProfiles(); | 657 LoadProfiles(); |
| 643 LoadCreditCards(); | 658 LoadCreditCards(); |
| 644 } | 659 } |
| 645 | 660 |
| 646 PersonalDataManager::PersonalDataManager() | 661 PersonalDataManager::PersonalDataManager() |
| 647 : profile_(NULL), | 662 : profile_(NULL), |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 } | 771 } |
| 757 | 772 |
| 758 CancelPendingQuery(&pending_profiles_query_); | 773 CancelPendingQuery(&pending_profiles_query_); |
| 759 | 774 |
| 760 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); | 775 pending_profiles_query_ = web_data_service->GetAutofillProfiles(this); |
| 761 } | 776 } |
| 762 | 777 |
| 763 // Win and Linux implementations do nothing. Mac implementation fills in the | 778 // Win and Linux implementations do nothing. Mac implementation fills in the |
| 764 // contents of |auxiliary_profiles_|. | 779 // contents of |auxiliary_profiles_|. |
| 765 #if !defined(OS_MACOSX) | 780 #if !defined(OS_MACOSX) |
| 766 void PersonalDataManager::LoadAuxiliaryProfiles() { | 781 void PersonalDataManager::LoadAuxiliaryProfiles() const { |
| 767 } | 782 } |
| 768 #endif | 783 #endif |
| 769 | 784 |
| 770 void PersonalDataManager::LoadCreditCards() { | 785 void PersonalDataManager::LoadCreditCards() { |
| 771 WebDataService* web_data_service = | 786 WebDataService* web_data_service = |
| 772 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 787 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 773 if (!web_data_service) { | 788 if (!web_data_service) { |
| 774 NOTREACHED(); | 789 NOTREACHED(); |
| 775 return; | 790 return; |
| 776 } | 791 } |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 } | 938 } |
| 924 | 939 |
| 925 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 940 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
| 926 return metric_logger_.get(); | 941 return metric_logger_.get(); |
| 927 } | 942 } |
| 928 | 943 |
| 929 void PersonalDataManager::set_metric_logger( | 944 void PersonalDataManager::set_metric_logger( |
| 930 const AutofillMetrics* metric_logger) { | 945 const AutofillMetrics* metric_logger) { |
| 931 metric_logger_.reset(metric_logger); | 946 metric_logger_.reset(metric_logger); |
| 932 } | 947 } |
| OLD | NEW |