Chromium Code Reviews| 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" |
| 11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/autofill/autofill-inl.h" | 13 #include "chrome/browser/autofill/autofill-inl.h" |
| 14 #include "chrome/browser/autofill/autofill_field.h" | 14 #include "chrome/browser/autofill/autofill_field.h" |
| 15 #include "chrome/browser/autofill/autofill_metrics.h" | 15 #include "chrome/browser/autofill/autofill_metrics.h" |
| 16 #include "chrome/browser/autofill/autofill_regexes.h" | 16 #include "chrome/browser/autofill/autofill_regexes.h" |
| 17 #include "chrome/browser/autofill/form_structure.h" | 17 #include "chrome/browser/autofill/form_structure.h" |
| 18 #include "chrome/browser/autofill/personal_data_manager_observer.h" | 18 #include "chrome/browser/autofill/personal_data_manager_observer.h" |
| 19 #include "chrome/browser/autofill/phone_number.h" | 19 #include "chrome/browser/autofill/phone_number.h" |
| 20 #include "chrome/browser/autofill/phone_number_i18n.h" | 20 #include "chrome/browser/autofill/phone_number_i18n.h" |
| 21 #include "chrome/browser/autofill/select_control_handler.h" | 21 #include "chrome/browser/autofill/select_control_handler.h" |
| 22 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/sync/profile_sync_service.h" | 24 #include "chrome/browser/sync/profile_sync_service.h" |
| 25 #include "chrome/browser/webdata/web_data_service.h" | 25 #include "chrome/browser/webdata/web_data_service.h" |
| 26 #include "chrome/common/chrome_notification_types.h" | |
| 26 #include "chrome/common/pref_names.h" | 27 #include "chrome/common/pref_names.h" |
| 27 #include "content/browser/browser_thread.h" | 28 #include "content/browser/browser_thread.h" |
| 29 #include "content/common/notification_source.h" | |
| 28 | 30 |
| 29 namespace { | 31 namespace { |
| 30 | 32 |
| 31 template<typename T> | 33 template<typename T> |
| 32 class FormGroupMatchesByGUIDFunctor { | 34 class FormGroupMatchesByGUIDFunctor { |
| 33 public: | 35 public: |
| 34 explicit FormGroupMatchesByGUIDFunctor(const std::string& guid) | 36 explicit FormGroupMatchesByGUIDFunctor(const std::string& guid) |
| 35 : guid_(guid) { | 37 : guid_(guid) { |
| 36 } | 38 } |
| 37 | 39 |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 191 ProfileSyncService* sync_service = profile_->GetProfileSyncService(); | 193 ProfileSyncService* sync_service = profile_->GetProfileSyncService(); |
| 192 if (!sync_service) | 194 if (!sync_service) |
| 193 return; | 195 return; |
| 194 | 196 |
| 195 if (sync_service->ShouldPushChanges()) { | 197 if (sync_service->ShouldPushChanges()) { |
| 196 web_data_service->EmptyMigrationTrash(true); | 198 web_data_service->EmptyMigrationTrash(true); |
| 197 sync_service->RemoveObserver(this); | 199 sync_service->RemoveObserver(this); |
| 198 } | 200 } |
| 199 } | 201 } |
| 200 | 202 |
| 203 void PersonalDataManager::Shutdown() { | |
| 204 CancelPendingQuery(&pending_profiles_query_); | |
| 205 CancelPendingQuery(&pending_creditcards_query_); | |
| 206 notification_registrar_.RemoveAll(); | |
| 207 } | |
| 208 | |
| 209 void PersonalDataManager::Observe(int type, | |
| 210 const NotificationSource& source, | |
| 211 const NotificationDetails& details) { | |
| 212 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED); | |
| 213 WebDataService* web_data_service = Source<WebDataService>(source).ptr(); | |
| 214 | |
| 215 DCHECK(web_data_service && | |
| 216 web_data_service == | |
| 217 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS)); | |
| 218 Refresh(); | |
|
Ilya Sherman
2011/09/23 03:56:34
Why does sync need to inform the PDM to refresh, b
dhollowa
2011/09/23 16:30:03
The WDS notifications are not seen by the UI threa
| |
| 219 } | |
| 220 | |
| 201 bool PersonalDataManager::ImportFormData( | 221 bool PersonalDataManager::ImportFormData( |
| 202 const FormStructure& form, | 222 const FormStructure& form, |
| 203 const CreditCard** imported_credit_card) { | 223 const CreditCard** imported_credit_card) { |
| 204 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); | 224 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); |
| 205 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); | 225 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); |
| 206 | 226 |
| 207 // Parse the form and construct a profile based on the information that is | 227 // Parse the form and construct a profile based on the information that is |
| 208 // possible to import. | 228 // possible to import. |
| 209 int importable_credit_card_fields = 0; | 229 int importable_credit_card_fields = 0; |
| 210 std::vector<const FormStructure*>::const_iterator iter; | 230 std::vector<const FormStructure*>::const_iterator iter; |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 524 pending_profiles_query_(0), | 544 pending_profiles_query_(0), |
| 525 pending_creditcards_query_(0), | 545 pending_creditcards_query_(0), |
| 526 metric_logger_(new AutofillMetrics), | 546 metric_logger_(new AutofillMetrics), |
| 527 has_logged_profile_count_(false) { | 547 has_logged_profile_count_(false) { |
| 528 } | 548 } |
| 529 | 549 |
| 530 void PersonalDataManager::Init(Profile* profile) { | 550 void PersonalDataManager::Init(Profile* profile) { |
| 531 profile_ = profile; | 551 profile_ = profile; |
| 532 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 552 metric_logger_->LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
| 533 | 553 |
| 554 // WebDataService may not be available in tests. | |
| 555 WebDataService* web_data_service = | |
| 556 profile_->GetWebDataService(Profile::EXPLICIT_ACCESS); | |
| 557 if (!web_data_service) | |
| 558 return; | |
| 559 | |
| 534 LoadProfiles(); | 560 LoadProfiles(); |
| 535 LoadCreditCards(); | 561 LoadCreditCards(); |
| 562 | |
| 563 notification_registrar_.Add(this, | |
| 564 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, | |
| 565 Source<WebDataService>(web_data_service)); | |
| 536 } | 566 } |
| 537 | 567 |
| 538 bool PersonalDataManager::IsAutofillEnabled() const { | 568 bool PersonalDataManager::IsAutofillEnabled() const { |
| 539 return profile_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 569 return profile_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
| 540 } | 570 } |
| 541 | 571 |
| 542 // static | 572 // static |
| 543 bool PersonalDataManager::IsValidLearnableProfile( | 573 bool PersonalDataManager::IsValidLearnableProfile( |
| 544 const AutofillProfile& profile) { | 574 const AutofillProfile& profile) { |
| 545 if (!IsMinimumAddress(profile)) | 575 if (!IsMinimumAddress(profile)) |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 } | 936 } |
| 907 | 937 |
| 908 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 938 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
| 909 return metric_logger_.get(); | 939 return metric_logger_.get(); |
| 910 } | 940 } |
| 911 | 941 |
| 912 void PersonalDataManager::set_metric_logger( | 942 void PersonalDataManager::set_metric_logger( |
| 913 const AutofillMetrics* metric_logger) { | 943 const AutofillMetrics* metric_logger) { |
| 914 metric_logger_.reset(metric_logger); | 944 metric_logger_.reset(metric_logger); |
| 915 } | 945 } |
| OLD | NEW |