| 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" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/autofill/autofill_manager.h" | 12 #include "chrome/browser/autofill/autofill_manager.h" |
| 13 #include "chrome/browser/autofill/autofill_field.h" | 13 #include "chrome/browser/autofill/autofill_field.h" |
| 14 #include "chrome/browser/autofill/form_structure.h" | 14 #include "chrome/browser/autofill/form_structure.h" |
| 15 #include "chrome/browser/autofill/phone_number.h" | 15 #include "chrome/browser/autofill/phone_number.h" |
| 16 #include "chrome/browser/chrome_thread.h" | 16 #include "chrome/browser/chrome_thread.h" |
| 17 #include "chrome/browser/profile.h" | 17 #include "chrome/browser/profile.h" |
| 18 #include "chrome/browser/webdata/web_data_service.h" | 18 #include "chrome/browser/webdata/web_data_service.h" |
| 19 #include "chrome/browser/pref_service.h" | 19 #include "chrome/browser/pref_service.h" |
| 20 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // The minimum number of fields that must contain user data and have known types | 24 // The minimum number of fields that must contain user data and have known types |
| 25 // before AutoFill will attempt to import the data into a profile. | 25 // before AutoFill will attempt to import the data into a profile. |
| 26 const int kMinImportSize = 3; | 26 const int kMinImportSize = 3; |
| 27 | 27 |
| 28 const char kUnlabeled[] = "Unlabeled"; | 28 const char kUnlabeled[] = "Unlabeled"; |
| 29 | 29 |
| 30 bool IsEmptyProfile(const AutoFillProfile& profile) { | |
| 31 FieldTypeSet types; | |
| 32 profile.GetAvailableFieldTypes(&types); | |
| 33 return types.empty(); | |
| 34 } | |
| 35 | |
| 36 bool IsEmptyCreditCard(const CreditCard& credit_card) { | |
| 37 FieldTypeSet types; | |
| 38 credit_card.GetAvailableFieldTypes(&types); | |
| 39 return types.empty() && credit_card.billing_address().empty(); | |
| 40 } | |
| 41 | |
| 42 } // namespace | 30 } // namespace |
| 43 | 31 |
| 44 PersonalDataManager::~PersonalDataManager() { | 32 PersonalDataManager::~PersonalDataManager() { |
| 45 CancelPendingQuery(&pending_profiles_query_); | 33 CancelPendingQuery(&pending_profiles_query_); |
| 46 CancelPendingQuery(&pending_creditcards_query_); | 34 CancelPendingQuery(&pending_creditcards_query_); |
| 47 } | 35 } |
| 48 | 36 |
| 49 void PersonalDataManager::OnWebDataServiceRequestDone( | 37 void PersonalDataManager::OnWebDataServiceRequestDone( |
| 50 WebDataService::Handle h, | 38 WebDataService::Handle h, |
| 51 const WDTypedResult* result) { | 39 const WDTypedResult* result) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 } | 212 } |
| 225 *credit_card = imported_credit_card_.get(); | 213 *credit_card = imported_credit_card_.get(); |
| 226 } | 214 } |
| 227 | 215 |
| 228 void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) { | 216 void PersonalDataManager::SetProfiles(std::vector<AutoFillProfile>* profiles) { |
| 229 if (profile_->IsOffTheRecord()) | 217 if (profile_->IsOffTheRecord()) |
| 230 return; | 218 return; |
| 231 | 219 |
| 232 // Remove empty profiles from input. | 220 // Remove empty profiles from input. |
| 233 profiles->erase( | 221 profiles->erase( |
| 234 std::remove_if(profiles->begin(), profiles->end(), IsEmptyProfile), | 222 std::remove_if(profiles->begin(), profiles->end(), |
| 223 std::mem_fun_ref(&AutoFillProfile::IsEmpty)), |
| 235 profiles->end()); | 224 profiles->end()); |
| 236 | 225 |
| 237 SetUniqueProfileLabels(profiles); | 226 SetUniqueProfileLabels(profiles); |
| 238 | 227 |
| 239 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 228 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 240 if (!wds) | 229 if (!wds) |
| 241 return; | 230 return; |
| 242 | 231 |
| 243 AutoLock lock(unique_ids_lock_); | 232 AutoLock lock(unique_ids_lock_); |
| 244 | 233 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 } | 292 } |
| 304 | 293 |
| 305 void PersonalDataManager::SetCreditCards( | 294 void PersonalDataManager::SetCreditCards( |
| 306 std::vector<CreditCard>* credit_cards) { | 295 std::vector<CreditCard>* credit_cards) { |
| 307 if (profile_->IsOffTheRecord()) | 296 if (profile_->IsOffTheRecord()) |
| 308 return; | 297 return; |
| 309 | 298 |
| 310 // Remove empty credit cards from input. | 299 // Remove empty credit cards from input. |
| 311 credit_cards->erase( | 300 credit_cards->erase( |
| 312 std::remove_if( | 301 std::remove_if( |
| 313 credit_cards->begin(), credit_cards->end(), IsEmptyCreditCard), | 302 credit_cards->begin(), credit_cards->end(), |
| 303 std::mem_fun_ref(&CreditCard::IsEmpty)), |
| 314 credit_cards->end()); | 304 credit_cards->end()); |
| 315 | 305 |
| 316 SetUniqueCreditCardLabels(credit_cards); | 306 SetUniqueCreditCardLabels(credit_cards); |
| 317 | 307 |
| 318 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | 308 WebDataService* wds = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); |
| 319 if (!wds) | 309 if (!wds) |
| 320 return; | 310 return; |
| 321 | 311 |
| 322 AutoLock lock(unique_ids_lock_); | 312 AutoLock lock(unique_ids_lock_); |
| 323 | 313 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 } | 688 } |
| 699 | 689 |
| 700 creditcards.push_back(**iter); | 690 creditcards.push_back(**iter); |
| 701 } | 691 } |
| 702 | 692 |
| 703 if (!merged) | 693 if (!merged) |
| 704 creditcards.push_back(*imported_credit_card_); | 694 creditcards.push_back(*imported_credit_card_); |
| 705 | 695 |
| 706 SetCreditCards(&creditcards); | 696 SetCreditCards(&creditcards); |
| 707 } | 697 } |
| OLD | NEW |