| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/browser/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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 PersonalDataManager::PersonalDataManager(const std::string& app_locale) | 150 PersonalDataManager::PersonalDataManager(const std::string& app_locale) |
| 151 : browser_context_(NULL), | 151 : browser_context_(NULL), |
| 152 is_data_loaded_(false), | 152 is_data_loaded_(false), |
| 153 pending_profiles_query_(0), | 153 pending_profiles_query_(0), |
| 154 pending_creditcards_query_(0), | 154 pending_creditcards_query_(0), |
| 155 app_locale_(app_locale), | 155 app_locale_(app_locale), |
| 156 metric_logger_(new AutofillMetrics), | 156 metric_logger_(new AutofillMetrics), |
| 157 has_logged_profile_count_(false) {} | 157 has_logged_profile_count_(false) {} |
| 158 | 158 |
| 159 void PersonalDataManager::Init(content::BrowserContext* browser_context) { | 159 void PersonalDataManager::Init(content::BrowserContext* browser_context, |
| 160 PrefService* pref_service) { |
| 160 browser_context_ = browser_context; | 161 browser_context_ = browser_context; |
| 162 pref_service_ = pref_service; |
| 161 | 163 |
| 162 if (!browser_context_->IsOffTheRecord()) | 164 if (!browser_context_->IsOffTheRecord()) |
| 163 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 165 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
| 164 | 166 |
| 165 scoped_refptr<AutofillWebDataService> autofill_data( | 167 scoped_refptr<AutofillWebDataService> autofill_data( |
| 166 AutofillWebDataService::FromBrowserContext(browser_context_)); | 168 AutofillWebDataService::FromBrowserContext(browser_context_)); |
| 167 | 169 |
| 168 // WebDataService may not be available in tests. | 170 // WebDataService may not be available in tests. |
| 169 if (!autofill_data.get()) | 171 if (!autofill_data.get()) |
| 170 return; | 172 return; |
| (...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 iter != credit_cards_.end(); ++iter) { | 544 iter != credit_cards_.end(); ++iter) { |
| 543 (*iter)->GetNonEmptyTypes(app_locale_, non_empty_types); | 545 (*iter)->GetNonEmptyTypes(app_locale_, non_empty_types); |
| 544 } | 546 } |
| 545 } | 547 } |
| 546 | 548 |
| 547 bool PersonalDataManager::IsDataLoaded() const { | 549 bool PersonalDataManager::IsDataLoaded() const { |
| 548 return is_data_loaded_; | 550 return is_data_loaded_; |
| 549 } | 551 } |
| 550 | 552 |
| 551 const std::vector<AutofillProfile*>& PersonalDataManager::GetProfiles() const { | 553 const std::vector<AutofillProfile*>& PersonalDataManager::GetProfiles() const { |
| 552 if (!user_prefs::UserPrefs::Get(browser_context_)->GetBoolean( | 554 if (!pref_service_->GetBoolean(prefs::kAutofillAuxiliaryProfilesEnabled)) { |
| 553 prefs::kAutofillAuxiliaryProfilesEnabled)) { | |
| 554 return web_profiles(); | 555 return web_profiles(); |
| 555 } | 556 } |
| 556 | 557 |
| 557 profiles_.clear(); | 558 profiles_.clear(); |
| 558 | 559 |
| 559 // Populates |auxiliary_profiles_|. | 560 // Populates |auxiliary_profiles_|. |
| 560 LoadAuxiliaryProfiles(); | 561 LoadAuxiliaryProfiles(); |
| 561 | 562 |
| 562 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); | 563 profiles_.insert(profiles_.end(), web_profiles_.begin(), web_profiles_.end()); |
| 563 profiles_.insert(profiles_.end(), | 564 profiles_.insert(profiles_.end(), |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 698 |
| 698 values->push_back(creditcard_field_value); | 699 values->push_back(creditcard_field_value); |
| 699 labels->push_back(label); | 700 labels->push_back(label); |
| 700 icons->push_back(UTF8ToUTF16(credit_card->type())); | 701 icons->push_back(UTF8ToUTF16(credit_card->type())); |
| 701 guid_pairs->push_back(GUIDPair(credit_card->guid(), 0)); | 702 guid_pairs->push_back(GUIDPair(credit_card->guid(), 0)); |
| 702 } | 703 } |
| 703 } | 704 } |
| 704 } | 705 } |
| 705 | 706 |
| 706 bool PersonalDataManager::IsAutofillEnabled() const { | 707 bool PersonalDataManager::IsAutofillEnabled() const { |
| 707 return user_prefs::UserPrefs::Get(browser_context_)->GetBoolean( | 708 return pref_service_->GetBoolean(prefs::kAutofillEnabled); |
| 708 prefs::kAutofillEnabled); | |
| 709 } | 709 } |
| 710 | 710 |
| 711 // static | 711 // static |
| 712 bool PersonalDataManager::IsValidLearnableProfile( | 712 bool PersonalDataManager::IsValidLearnableProfile( |
| 713 const AutofillProfile& profile, | 713 const AutofillProfile& profile, |
| 714 const std::string& app_locale) { | 714 const std::string& app_locale) { |
| 715 if (!IsMinimumAddress(profile, app_locale)) | 715 if (!IsMinimumAddress(profile, app_locale)) |
| 716 return false; | 716 return false; |
| 717 | 717 |
| 718 base::string16 email = profile.GetRawInfo(EMAIL_ADDRESS); | 718 base::string16 email = profile.GetRawInfo(EMAIL_ADDRESS); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 if (!votes.empty()) { | 1073 if (!votes.empty()) { |
| 1074 std::map<std::string, int>::iterator iter = | 1074 std::map<std::string, int>::iterator iter = |
| 1075 std::max_element(votes.begin(), votes.end(), CompareVotes); | 1075 std::max_element(votes.begin(), votes.end(), CompareVotes); |
| 1076 return iter->first; | 1076 return iter->first; |
| 1077 } | 1077 } |
| 1078 | 1078 |
| 1079 return std::string(); | 1079 return std::string(); |
| 1080 } | 1080 } |
| 1081 | 1081 |
| 1082 } // namespace autofill | 1082 } // namespace autofill |
| OLD | NEW |