Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "components/autofill/core/browser/phone_number.h" | 32 #include "components/autofill/core/browser/phone_number.h" |
| 33 #include "components/autofill/core/browser/phone_number_i18n.h" | 33 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 34 #include "components/autofill/core/browser/validation.h" | 34 #include "components/autofill/core/browser/validation.h" |
| 35 #include "components/autofill/core/common/autofill_pref_names.h" | 35 #include "components/autofill/core/common/autofill_pref_names.h" |
| 36 #include "components/autofill/core/common/autofill_switches.h" | 36 #include "components/autofill/core/common/autofill_switches.h" |
| 37 #include "components/autofill/core/common/autofill_util.h" | 37 #include "components/autofill/core/common/autofill_util.h" |
| 38 #include "components/prefs/pref_service.h" | 38 #include "components/prefs/pref_service.h" |
| 39 #include "components/signin/core/browser/account_tracker_service.h" | 39 #include "components/signin/core/browser/account_tracker_service.h" |
| 40 #include "components/signin/core/browser/signin_manager.h" | 40 #include "components/signin/core/browser/signin_manager.h" |
| 41 #include "components/signin/core/common/signin_pref_names.h" | 41 #include "components/signin/core/common/signin_pref_names.h" |
| 42 #include "components/sync_driver/sync_service.h" | |
| 42 #include "components/variations/variations_associated_data.h" | 43 #include "components/variations/variations_associated_data.h" |
| 43 #include "components/version_info/version_info.h" | 44 #include "components/version_info/version_info.h" |
| 44 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" | 45 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da ta.h" |
| 45 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" | 46 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_fo rmatter.h" |
| 46 | 47 |
| 47 namespace autofill { | 48 namespace autofill { |
| 48 namespace { | 49 namespace { |
| 49 | 50 |
| 50 using ::i18n::addressinput::AddressField; | 51 using ::i18n::addressinput::AddressField; |
| 51 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; | 52 using ::i18n::addressinput::GetStreetAddressLinesAsSingleLine; |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 280 AutofillMetrics::LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); | 281 AutofillMetrics::LogIsAutofillEnabledAtStartup(IsAutofillEnabled()); |
| 281 | 282 |
| 282 // WebDataService may not be available in tests. | 283 // WebDataService may not be available in tests. |
| 283 if (!database_.get()) | 284 if (!database_.get()) |
| 284 return; | 285 return; |
| 285 | 286 |
| 286 LoadProfiles(); | 287 LoadProfiles(); |
| 287 LoadCreditCards(); | 288 LoadCreditCards(); |
| 288 | 289 |
| 289 database_->AddObserver(this); | 290 database_->AddObserver(this); |
| 291 is_autofill_profile_dedupe_pending_ = IsAutofillProfileCleanupEnabled(); | |
| 290 } | 292 } |
| 291 | 293 |
| 292 PersonalDataManager::~PersonalDataManager() { | 294 PersonalDataManager::~PersonalDataManager() { |
| 293 CancelPendingQuery(&pending_profiles_query_); | 295 CancelPendingQuery(&pending_profiles_query_); |
| 294 CancelPendingQuery(&pending_server_profiles_query_); | 296 CancelPendingQuery(&pending_server_profiles_query_); |
| 295 CancelPendingQuery(&pending_creditcards_query_); | 297 CancelPendingQuery(&pending_creditcards_query_); |
| 296 CancelPendingQuery(&pending_server_creditcards_query_); | 298 CancelPendingQuery(&pending_server_creditcards_query_); |
| 297 | 299 |
| 298 if (database_.get()) | 300 if (database_.get()) |
| 299 database_->RemoveObserver(this); | 301 database_->RemoveObserver(this); |
| 300 } | 302 } |
| 301 | 303 |
| 304 void PersonalDataManager::OnSyncServiceConfigured( | |
| 305 sync_driver::SyncService* sync_service) { | |
| 306 // We want to know when, if at all, we need to run autofill profile de- | |
| 307 // duplication: now or after waiting until sync has started. | |
| 308 if (!is_autofill_profile_dedupe_pending_) { | |
| 309 // De-duplication isn't enabled. | |
| 310 return; | |
| 311 } | |
| 312 | |
| 313 // If the sync service is configured to start and to sync autofill profiles, | |
| 314 // then we can just let the notification that sync has started trigger the | |
|
Nicolas Zea
2016/07/12 20:04:47
where is the notification that sync has started co
Roger McFarlane (Chromium)
2016/07/12 21:23:26
AutofillProfileSyncableProfile::MergeDataAndStartS
| |
| 315 // de-duplication. | |
| 316 if (sync_service && sync_service->CanSyncStart() && | |
| 317 sync_service->GetPreferredDataTypes().Has(syncer::AUTOFILL_PROFILE)) { | |
| 318 return; | |
| 319 } | |
| 320 | |
| 321 // Otherwise, run the de-duplication now. | |
| 322 ApplyDedupingRoutine(); | |
| 323 } | |
| 324 | |
| 302 void PersonalDataManager::OnWebDataServiceRequestDone( | 325 void PersonalDataManager::OnWebDataServiceRequestDone( |
| 303 WebDataServiceBase::Handle h, | 326 WebDataServiceBase::Handle h, |
| 304 const WDTypedResult* result) { | 327 const WDTypedResult* result) { |
| 305 DCHECK(pending_profiles_query_ || pending_server_profiles_query_ || | 328 DCHECK(pending_profiles_query_ || pending_server_profiles_query_ || |
| 306 pending_creditcards_query_ || pending_server_creditcards_query_); | 329 pending_creditcards_query_ || pending_server_creditcards_query_); |
| 307 | 330 |
| 308 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is | 331 // TODO(robliao): Remove ScopedTracker below once https://crbug.com/422460 is |
| 309 // fixed. | 332 // fixed. |
| 310 tracked_objects::ScopedTracker tracking_profile( | 333 tracked_objects::ScopedTracker tracking_profile( |
| 311 FROM_HERE_WITH_EXPLICIT_FUNCTION( | 334 FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 312 "422460 PersonalDataManager::OnWebDataServiceRequestDone")); | 335 "422460 PersonalDataManager::OnWebDataServiceRequestDone")); |
| 313 | 336 |
| 314 if (!result) { | 337 if (!result) { |
| 315 // Error from the web database. | 338 // Error from the web database. |
| 316 if (h == pending_creditcards_query_) | 339 if (h == pending_creditcards_query_) |
| 317 pending_creditcards_query_ = 0; | 340 pending_creditcards_query_ = 0; |
| 318 else if (h == pending_profiles_query_) | 341 else if (h == pending_profiles_query_) |
| 319 pending_profiles_query_ = 0; | 342 pending_profiles_query_ = 0; |
| 320 return; | 343 return; |
| 321 } | 344 } |
| 322 | 345 |
| 323 switch (result->GetType()) { | 346 switch (result->GetType()) { |
| 324 case AUTOFILL_PROFILES_RESULT: | 347 case AUTOFILL_PROFILES_RESULT: |
| 325 if (h == pending_profiles_query_) { | 348 if (h == pending_profiles_query_) { |
| 326 ReceiveLoadedDbValues(h, result, &pending_profiles_query_, | 349 ReceiveLoadedDbValues(h, result, &pending_profiles_query_, |
| 327 &web_profiles_); | 350 &web_profiles_); |
| 328 LogProfileCount(); // This only logs local profiles. | 351 LogProfileCount(); // This only logs local profiles. |
| 329 // Since these two routines both re-launch the database queries, don't | 352 ApplyProfileUseDatesFix(); |
| 330 // run them on the same query response. | |
| 331 if (!ApplyDedupingRoutine()) | |
| 332 ApplyProfileUseDatesFix(); | |
| 333 } else { | 353 } else { |
| 334 ReceiveLoadedDbValues(h, result, &pending_server_profiles_query_, | 354 ReceiveLoadedDbValues(h, result, &pending_server_profiles_query_, |
| 335 &server_profiles_); | 355 &server_profiles_); |
| 336 | 356 |
| 337 if (!server_profiles_.empty()) { | 357 if (!server_profiles_.empty()) { |
| 338 std::string account_id = signin_manager_->GetAuthenticatedAccountId(); | 358 std::string account_id = signin_manager_->GetAuthenticatedAccountId(); |
| 339 base::string16 email = | 359 base::string16 email = |
| 340 base::UTF8ToUTF16( | 360 base::UTF8ToUTF16( |
| 341 account_tracker_->GetAccountInfo(account_id).email); | 361 account_tracker_->GetAccountInfo(account_id).email); |
| 342 | 362 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 373 if (pending_profiles_query_ == 0 && | 393 if (pending_profiles_query_ == 0 && |
| 374 pending_creditcards_query_ == 0 && | 394 pending_creditcards_query_ == 0 && |
| 375 pending_server_profiles_query_ == 0 && | 395 pending_server_profiles_query_ == 0 && |
| 376 pending_server_creditcards_query_ == 0) { | 396 pending_server_creditcards_query_ == 0) { |
| 377 is_data_loaded_ = true; | 397 is_data_loaded_ = true; |
| 378 NotifyPersonalDataChanged(); | 398 NotifyPersonalDataChanged(); |
| 379 } | 399 } |
| 380 } | 400 } |
| 381 | 401 |
| 382 void PersonalDataManager::AutofillMultipleChanged() { | 402 void PersonalDataManager::AutofillMultipleChanged() { |
| 403 if (is_autofill_profile_dedupe_pending_) | |
| 404 ApplyDedupingRoutine(); | |
| 405 | |
| 383 Refresh(); | 406 Refresh(); |
| 384 } | 407 } |
| 385 | 408 |
| 386 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) { | 409 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) { |
| 387 observers_.AddObserver(observer); | 410 observers_.AddObserver(observer); |
| 388 } | 411 } |
| 389 | 412 |
| 390 void PersonalDataManager::RemoveObserver( | 413 void PersonalDataManager::RemoveObserver( |
| 391 PersonalDataManagerObserver* observer) { | 414 PersonalDataManagerObserver* observer) { |
| 392 observers_.RemoveObserver(observer); | 415 observers_.RemoveObserver(observer); |
| (...skipping 1206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1599 } | 1622 } |
| 1600 | 1623 |
| 1601 // Set the pref so that this fix is never run again. | 1624 // Set the pref so that this fix is never run again. |
| 1602 pref_service_->SetBoolean(prefs::kAutofillProfileUseDatesFixed, true); | 1625 pref_service_->SetBoolean(prefs::kAutofillProfileUseDatesFixed, true); |
| 1603 | 1626 |
| 1604 if (has_changed_data) | 1627 if (has_changed_data) |
| 1605 SetProfiles(&profiles); | 1628 SetProfiles(&profiles); |
| 1606 } | 1629 } |
| 1607 | 1630 |
| 1608 bool PersonalDataManager::ApplyDedupingRoutine() { | 1631 bool PersonalDataManager::ApplyDedupingRoutine() { |
| 1609 if (!IsAutofillProfileCleanupEnabled()) | 1632 if (!is_autofill_profile_dedupe_pending_) |
| 1610 return false; | 1633 return false; |
| 1611 | 1634 |
| 1612 int current_major_version = atoi(version_info::GetVersionNumber().c_str()); | 1635 DCHECK(IsAutofillProfileCleanupEnabled()); |
| 1636 is_autofill_profile_dedupe_pending_ = false; | |
| 1613 | 1637 |
| 1614 // Check if the deduping routine has already been run on this major version. | 1638 // Check if the deduping routine has already been run on this major version. |
| 1639 int current_major_version = atoi(version_info::GetVersionNumber().c_str()); | |
| 1615 if (pref_service_->GetInteger(prefs::kAutofillLastVersionDeduped) >= | 1640 if (pref_service_->GetInteger(prefs::kAutofillLastVersionDeduped) >= |
| 1616 current_major_version) | 1641 current_major_version) { |
| 1642 VLOG(1) | |
| 1643 << "Autofill profile de-duplication already performed for this version"; | |
| 1617 return false; | 1644 return false; |
| 1645 } | |
| 1618 | 1646 |
| 1647 VLOG(1) << "Starting autofill profile de-duplication."; | |
| 1619 std::vector<AutofillProfile*> existing_profiles = web_profiles_.get(); | 1648 std::vector<AutofillProfile*> existing_profiles = web_profiles_.get(); |
| 1620 std::unordered_set<AutofillProfile*> profiles_to_delete; | 1649 std::unordered_set<AutofillProfile*> profiles_to_delete; |
| 1621 profiles_to_delete.reserve(existing_profiles.size()); | 1650 profiles_to_delete.reserve(existing_profiles.size()); |
| 1622 | 1651 |
| 1623 DedupeProfiles(&existing_profiles, &profiles_to_delete); | 1652 DedupeProfiles(&existing_profiles, &profiles_to_delete); |
| 1624 | 1653 |
| 1625 // Apply the changes to the database. | 1654 // Apply the changes to the database. |
| 1626 for (AutofillProfile* profile : existing_profiles) { | 1655 for (AutofillProfile* profile : existing_profiles) { |
| 1627 // If the profile was set to be deleted, remove it from the database. | 1656 // If the profile was set to be deleted, remove it from the database. |
| 1628 if (profiles_to_delete.count(profile)) { | 1657 if (profiles_to_delete.count(profile)) { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1712 if (profile_to_merge->IsVerified()) | 1741 if (profile_to_merge->IsVerified()) |
| 1713 break; | 1742 break; |
| 1714 } | 1743 } |
| 1715 } | 1744 } |
| 1716 } | 1745 } |
| 1717 AutofillMetrics::LogNumberOfProfilesRemovedDuringDedupe( | 1746 AutofillMetrics::LogNumberOfProfilesRemovedDuringDedupe( |
| 1718 profiles_to_delete->size()); | 1747 profiles_to_delete->size()); |
| 1719 } | 1748 } |
| 1720 | 1749 |
| 1721 } // namespace autofill | 1750 } // namespace autofill |
| OLD | NEW |