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/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 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
635 LoadCreditCards(); | 635 LoadCreditCards(); |
636 } | 636 } |
637 | 637 |
638 PersonalDataManager::PersonalDataManager() | 638 PersonalDataManager::PersonalDataManager() |
639 : profile_(NULL), | 639 : profile_(NULL), |
640 is_data_loaded_(false), | 640 is_data_loaded_(false), |
641 pending_profiles_query_(0), | 641 pending_profiles_query_(0), |
642 pending_creditcards_query_(0) { | 642 pending_creditcards_query_(0) { |
643 } | 643 } |
644 | 644 |
645 std::string PersonalDataManager::PresentData(const std::string& profile_guid, | |
646 const std::string& cc_guid) { | |
647 size_t data_size = (MAX_VALID_FIELD_TYPE + 7) >> 3; | |
648 scoped_array<uint8> binary_data_mask(new uint8[data_size]); | |
649 memset(binary_data_mask.get(), 0, data_size); | |
650 for (std::vector<AutoFillProfile*>::const_iterator it = profiles().begin(); | |
651 it != profiles().end(); ++it) { | |
652 if ((*it)->guid() == profile_guid) | |
653 SetDataPresenseBits(*it, binary_data_mask.get()); | |
654 } | |
655 for (std::vector<CreditCard*>::const_iterator it = | |
656 credit_cards().begin(); it != credit_cards().end(); ++it) { | |
657 if ((*it)->guid() == cc_guid) | |
658 SetDataPresenseBits(*it, binary_data_mask.get()); | |
659 } | |
660 std::string present_data; | |
661 present_data.reserve(data_size * 2 + 1); | |
662 // Skip leading zeroes. If all mask is 0 - return empty string. | |
663 size_t data_end = data_size; | |
664 for (; data_end > 0 && !binary_data_mask[data_end - 1]; --data_end); | |
dhollowa
2011/01/11 23:29:29
Use of ";" as loop body causes compiler warning on
GeorgeY
2011/01/13 23:22:28
Code moved and fixed in the process :)
| |
665 for (size_t i = 0; i < data_end; ++i) { | |
666 base::StringAppendF(&present_data, "%02x", binary_data_mask[i]); | |
667 } | |
668 return present_data; | |
669 } | |
670 | |
645 void PersonalDataManager::Init(Profile* profile) { | 671 void PersonalDataManager::Init(Profile* profile) { |
646 profile_ = profile; | 672 profile_ = profile; |
647 LoadProfiles(); | 673 LoadProfiles(); |
648 LoadCreditCards(); | 674 LoadCreditCards(); |
649 } | 675 } |
650 | 676 |
651 void PersonalDataManager::LoadProfiles() { | 677 void PersonalDataManager::LoadProfiles() { |
652 WebDataService* web_data_service = | 678 WebDataService* web_data_service = |
653 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 679 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
654 if (!web_data_service) { | 680 if (!web_data_service) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
792 } | 818 } |
793 | 819 |
794 creditcards.push_back(**iter); | 820 creditcards.push_back(**iter); |
795 } | 821 } |
796 | 822 |
797 if (!merged) | 823 if (!merged) |
798 creditcards.push_back(*imported_credit_card_); | 824 creditcards.push_back(*imported_credit_card_); |
799 | 825 |
800 SetCreditCards(&creditcards); | 826 SetCreditCards(&creditcards); |
801 } | 827 } |
828 | |
829 void PersonalDataManager::SetDataPresenseBits( | |
830 FormGroup const* profile, uint8* binary_data_mask) { | |
831 DCHECK(profile); | |
832 DCHECK(binary_data_mask); | |
833 for (uint32 i = EMPTY_TYPE; i < MAX_VALID_FIELD_TYPE; ++i) { | |
834 if (CREDIT_CARD_VERIFICATION_CODE == i) | |
835 continue; // We do not support CREDIT_CARD_VERIFICATION_CODE | |
836 if (!profile->GetFieldText( | |
837 AutoFillType(static_cast<AutoFillFieldType>(i))).empty()) | |
838 binary_data_mask[i >> 3] |= (0x80 >> (i & 7)); | |
839 } | |
840 } | |
841 | |
OLD | NEW |