Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: components/autofill/core/browser/personal_data_manager.cc

Issue 2142123002: [Autofill] Run autofill-profile de-dupe after sync starts if sync is enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Perform at most a single merge for new incoming sync data Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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::OnSyncServiceInitialized(
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
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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() {
383 Refresh(); 403 Refresh();
384 } 404 }
385 405
406 void PersonalDataManager::SyncStarted(syncer::ModelType model_type) {
407 if (model_type == syncer::AUTOFILL_PROFILE &&
408 is_autofill_profile_dedupe_pending_) {
409 ApplyDedupingRoutine();
410 }
411 }
412
386 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) { 413 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) {
387 observers_.AddObserver(observer); 414 observers_.AddObserver(observer);
388 } 415 }
389 416
390 void PersonalDataManager::RemoveObserver( 417 void PersonalDataManager::RemoveObserver(
391 PersonalDataManagerObserver* observer) { 418 PersonalDataManagerObserver* observer) {
392 observers_.RemoveObserver(observer); 419 observers_.RemoveObserver(observer);
393 } 420 }
394 421
395 bool PersonalDataManager::ImportFormData( 422 bool PersonalDataManager::ImportFormData(
(...skipping 1203 matching lines...) Expand 10 before | Expand all | Expand 10 after
1599 } 1626 }
1600 1627
1601 // Set the pref so that this fix is never run again. 1628 // Set the pref so that this fix is never run again.
1602 pref_service_->SetBoolean(prefs::kAutofillProfileUseDatesFixed, true); 1629 pref_service_->SetBoolean(prefs::kAutofillProfileUseDatesFixed, true);
1603 1630
1604 if (has_changed_data) 1631 if (has_changed_data)
1605 SetProfiles(&profiles); 1632 SetProfiles(&profiles);
1606 } 1633 }
1607 1634
1608 bool PersonalDataManager::ApplyDedupingRoutine() { 1635 bool PersonalDataManager::ApplyDedupingRoutine() {
1609 if (!IsAutofillProfileCleanupEnabled()) 1636 if (!is_autofill_profile_dedupe_pending_)
Mathieu 2016/07/18 14:53:19 are these two lines necessary? Seems like callers
Roger McFarlane (Chromium) 2016/07/18 15:29:18 there's a slight mismatch between how the tests ex
1610 return false; 1637 return false;
1611 1638
1612 int current_major_version = atoi(version_info::GetVersionNumber().c_str()); 1639 DCHECK(IsAutofillProfileCleanupEnabled());
1640 is_autofill_profile_dedupe_pending_ = false;
1613 1641
1614 // Check if the deduping routine has already been run on this major version. 1642 // Check if the deduping routine has already been run on this major version.
1643 int current_major_version = atoi(version_info::GetVersionNumber().c_str());
1615 if (pref_service_->GetInteger(prefs::kAutofillLastVersionDeduped) >= 1644 if (pref_service_->GetInteger(prefs::kAutofillLastVersionDeduped) >=
1616 current_major_version) 1645 current_major_version) {
1646 DVLOG(1)
1647 << "Autofill profile de-duplication already performed for this version";
1617 return false; 1648 return false;
1649 }
1618 1650
1651 DVLOG(1) << "Starting autofill profile de-duplication.";
1619 std::vector<AutofillProfile*> existing_profiles = web_profiles_.get(); 1652 std::vector<AutofillProfile*> existing_profiles = web_profiles_.get();
1620 std::unordered_set<AutofillProfile*> profiles_to_delete; 1653 std::unordered_set<AutofillProfile*> profiles_to_delete;
1621 profiles_to_delete.reserve(existing_profiles.size()); 1654 profiles_to_delete.reserve(existing_profiles.size());
1622 1655
1623 DedupeProfiles(&existing_profiles, &profiles_to_delete); 1656 DedupeProfiles(&existing_profiles, &profiles_to_delete);
1624 1657
1625 // Apply the changes to the database. 1658 // Apply the changes to the database.
1626 for (AutofillProfile* profile : existing_profiles) { 1659 for (AutofillProfile* profile : existing_profiles) {
1627 // If the profile was set to be deleted, remove it from the database. 1660 // If the profile was set to be deleted, remove it from the database.
1628 if (profiles_to_delete.count(profile)) { 1661 if (profiles_to_delete.count(profile)) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1712 if (profile_to_merge->IsVerified()) 1745 if (profile_to_merge->IsVerified())
1713 break; 1746 break;
1714 } 1747 }
1715 } 1748 }
1716 } 1749 }
1717 AutofillMetrics::LogNumberOfProfilesRemovedDuringDedupe( 1750 AutofillMetrics::LogNumberOfProfilesRemovedDuringDedupe(
1718 profiles_to_delete->size()); 1751 profiles_to_delete->size());
1719 } 1752 }
1720 1753
1721 } // namespace autofill 1754 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698