Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 "components/autofill/browser/personal_data_manager.h" | 5 #include "components/autofill/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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 scoped_ptr<AutofillWebDataService> autofill_data( | 124 scoped_ptr<AutofillWebDataService> autofill_data( | 
| 125 AutofillWebDataService::FromBrowserContext(browser_context_)); | 125 AutofillWebDataService::FromBrowserContext(browser_context_)); | 
| 126 | 126 | 
| 127 // WebDataService may not be available in tests. | 127 // WebDataService may not be available in tests. | 
| 128 if (!autofill_data.get()) | 128 if (!autofill_data.get()) | 
| 129 return; | 129 return; | 
| 130 | 130 | 
| 131 LoadProfiles(); | 131 LoadProfiles(); | 
| 132 LoadCreditCards(); | 132 LoadCreditCards(); | 
| 133 | 133 | 
| 134 notification_registrar_.Add( | 134 autofill_data->AddObserver(this); | 
| 
 
dhollowa
2013/03/12 22:22:28
Please use ScopedObserver.
 
kaiwang
2013/03/13 04:57:20
Can not do it here.. AutofillWebDataService is a w
 
dhollowa
2013/03/13 16:15:28
This should work:
  scoped_observer_.Add(autofill_
 
kaiwang
2013/03/13 17:27:40
AutofillWebDataService is a thin wrapper. Every ti
 
dhollowa
2013/03/14 00:35:17
Got it.  Ok.
 
 | |
| 135 this, | |
| 136 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, | |
| 137 autofill_data->GetNotificationSource()); | |
| 138 } | 135 } | 
| 139 | 136 | 
| 140 PersonalDataManager::~PersonalDataManager() { | 137 PersonalDataManager::~PersonalDataManager() { | 
| 141 CancelPendingQuery(&pending_profiles_query_); | 138 CancelPendingQuery(&pending_profiles_query_); | 
| 142 CancelPendingQuery(&pending_creditcards_query_); | 139 CancelPendingQuery(&pending_creditcards_query_); | 
| 140 | |
| 141 scoped_ptr<AutofillWebDataService> autofill_data( | |
| 142 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
| 143 if (autofill_data.get()) | |
| 144 autofill_data->RemoveObserver(this); | |
| 143 } | 145 } | 
| 144 | 146 | 
| 145 void PersonalDataManager::OnWebDataServiceRequestDone( | 147 void PersonalDataManager::OnWebDataServiceRequestDone( | 
| 146 WebDataServiceBase::Handle h, | 148 WebDataServiceBase::Handle h, | 
| 147 const WDTypedResult* result) { | 149 const WDTypedResult* result) { | 
| 148 DCHECK(pending_profiles_query_ || pending_creditcards_query_); | 150 DCHECK(pending_profiles_query_ || pending_creditcards_query_); | 
| 149 | 151 | 
| 150 if (!result) { | 152 if (!result) { | 
| 151 // Error from the web database. | 153 // Error from the web database. | 
| 152 if (h == pending_creditcards_query_) | 154 if (h == pending_creditcards_query_) | 
| (...skipping 22 matching lines...) Expand all Loading... | |
| 175 is_data_loaded_ = true; | 177 is_data_loaded_ = true; | 
| 176 std::vector<AutofillProfile*> profile_pointers(web_profiles_.size()); | 178 std::vector<AutofillProfile*> profile_pointers(web_profiles_.size()); | 
| 177 std::copy(web_profiles_.begin(), web_profiles_.end(), | 179 std::copy(web_profiles_.begin(), web_profiles_.end(), | 
| 178 profile_pointers.begin()); | 180 profile_pointers.begin()); | 
| 179 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 181 AutofillProfile::AdjustInferredLabels(&profile_pointers); | 
| 180 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, | 182 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, | 
| 181 OnPersonalDataChanged()); | 183 OnPersonalDataChanged()); | 
| 182 } | 184 } | 
| 183 } | 185 } | 
| 184 | 186 | 
| 187 void PersonalDataManager::AutofillMultipleChanged() { | |
| 188 Refresh(); | |
| 189 } | |
| 190 | |
| 185 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) { | 191 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) { | 
| 186 observers_.AddObserver(observer); | 192 observers_.AddObserver(observer); | 
| 187 } | 193 } | 
| 188 | 194 | 
| 189 void PersonalDataManager::RemoveObserver( | 195 void PersonalDataManager::RemoveObserver( | 
| 190 PersonalDataManagerObserver* observer) { | 196 PersonalDataManagerObserver* observer) { | 
| 191 observers_.RemoveObserver(observer); | 197 observers_.RemoveObserver(observer); | 
| 192 } | 198 } | 
| 193 | 199 | 
| 194 void PersonalDataManager::Observe(int type, | |
| 195 const content::NotificationSource& source, | |
| 196 const content::NotificationDetails& details) { | |
| 197 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); | |
| 198 | |
| 199 if (DCHECK_IS_ON()) { | |
| 200 scoped_ptr<AutofillWebDataService> autofill_data( | |
| 201 AutofillWebDataService::FromBrowserContext(browser_context_)); | |
| 202 | |
| 203 DCHECK(autofill_data.get() && | |
| 204 autofill_data->GetNotificationSource() == source); | |
| 205 } | |
| 206 | |
| 207 Refresh(); | |
| 208 } | |
| 209 | |
| 210 bool PersonalDataManager::ImportFormData( | 200 bool PersonalDataManager::ImportFormData( | 
| 211 const FormStructure& form, | 201 const FormStructure& form, | 
| 212 const CreditCard** imported_credit_card) { | 202 const CreditCard** imported_credit_card) { | 
| 213 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); | 203 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); | 
| 214 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); | 204 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); | 
| 215 | 205 | 
| 216 // Parse the form and construct a profile based on the information that is | 206 // Parse the form and construct a profile based on the information that is | 
| 217 // possible to import. | 207 // possible to import. | 
| 218 int importable_credit_card_fields = 0; | 208 int importable_credit_card_fields = 0; | 
| 219 | 209 | 
| (...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 | 953 | 
| 964 void PersonalDataManager::set_metric_logger( | 954 void PersonalDataManager::set_metric_logger( | 
| 965 const AutofillMetrics* metric_logger) { | 955 const AutofillMetrics* metric_logger) { | 
| 966 metric_logger_.reset(metric_logger); | 956 metric_logger_.reset(metric_logger); | 
| 967 } | 957 } | 
| 968 | 958 | 
| 969 void PersonalDataManager::set_browser_context( | 959 void PersonalDataManager::set_browser_context( | 
| 970 content::BrowserContext* context) { | 960 content::BrowserContext* context) { | 
| 971 browser_context_ = context; | 961 browser_context_ = context; | 
| 972 } | 962 } | 
| OLD | NEW |