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 "chrome/browser/webdata/autofill_profile_syncable_service.h" | 5 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 } | 75 } |
| 76 | 76 |
| 77 if (DLOG_IS_ON(INFO)) { | 77 if (DLOG_IS_ON(INFO)) { |
| 78 DVLOG(2) << "[AUTOFILL MIGRATION]" | 78 DVLOG(2) << "[AUTOFILL MIGRATION]" |
| 79 << "Printing profiles from web db"; | 79 << "Printing profiles from web db"; |
| 80 | 80 |
| 81 for (ScopedVector<AutofillProfile>::const_iterator ix = | 81 for (ScopedVector<AutofillProfile>::const_iterator ix = |
| 82 profiles_.begin(); ix != profiles_.end(); ++ix) { | 82 profiles_.begin(); ix != profiles_.end(); ++ix) { |
| 83 AutofillProfile* p = *ix; | 83 AutofillProfile* p = *ix; |
| 84 DVLOG(2) << "[AUTOFILL MIGRATION] " | 84 DVLOG(2) << "[AUTOFILL MIGRATION] " |
| 85 << p->GetInfo(NAME_FIRST) | 85 << p->GetRawInfo(NAME_FIRST) |
| 86 << p->GetInfo(NAME_LAST) | 86 << p->GetRawInfo(NAME_LAST) |
| 87 << p->guid(); | 87 << p->guid(); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 sync_processor_ = sync_processor.Pass(); | 91 sync_processor_ = sync_processor.Pass(); |
| 92 | 92 |
| 93 GUIDToProfileMap remaining_profiles; | 93 GUIDToProfileMap remaining_profiles; |
| 94 CreateGUIDToProfileMap(profiles_.get(), &remaining_profiles); | 94 CreateGUIDToProfileMap(profiles_.get(), &remaining_profiles); |
| 95 | 95 |
| 96 DataBundle bundle; | 96 DataBundle bundle; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 114 for (GUIDToProfileMap::iterator it = bundle.candidates_to_merge.begin(); | 114 for (GUIDToProfileMap::iterator it = bundle.candidates_to_merge.begin(); |
| 115 it != bundle.candidates_to_merge.end(); ++it) { | 115 it != bundle.candidates_to_merge.end(); ++it) { |
| 116 GUIDToProfileMap::iterator profile_to_merge = | 116 GUIDToProfileMap::iterator profile_to_merge = |
| 117 remaining_profiles.find(it->first); | 117 remaining_profiles.find(it->first); |
| 118 if (profile_to_merge != remaining_profiles.end()) { | 118 if (profile_to_merge != remaining_profiles.end()) { |
| 119 bundle.profiles_to_delete.push_back(profile_to_merge->second->guid()); | 119 bundle.profiles_to_delete.push_back(profile_to_merge->second->guid()); |
| 120 if (MergeProfile(*(profile_to_merge->second), it->second)) | 120 if (MergeProfile(*(profile_to_merge->second), it->second)) |
| 121 bundle.profiles_to_sync_back.push_back(it->second); | 121 bundle.profiles_to_sync_back.push_back(it->second); |
| 122 DVLOG(2) << "[AUTOFILL SYNC]" | 122 DVLOG(2) << "[AUTOFILL SYNC]" |
| 123 << "Found similar profile in sync db but with a different guid: " | 123 << "Found similar profile in sync db but with a different guid: " |
| 124 << UTF16ToUTF8(it->second->GetInfo(NAME_FIRST)) | 124 << UTF16ToUTF8(it->second->GetRawInfo(NAME_FIRST)) |
| 125 << UTF16ToUTF8(it->second->GetInfo(NAME_LAST)) | 125 << UTF16ToUTF8(it->second->GetRawInfo(NAME_LAST)) |
| 126 << "New guid " << it->second->guid() | 126 << "New guid " << it->second->guid() |
| 127 << ". Profile to be deleted " | 127 << ". Profile to be deleted " |
| 128 << profile_to_merge->second->guid(); | 128 << profile_to_merge->second->guid(); |
| 129 remaining_profiles.erase(profile_to_merge); | 129 remaining_profiles.erase(profile_to_merge); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 | 132 |
| 133 if (!SaveChangesToWebData(bundle)) { | 133 if (!SaveChangesToWebData(bundle)) { |
| 134 return sync_error_factory_->CreateAndUploadError( | 134 return sync_error_factory_->CreateAndUploadError( |
| 135 FROM_HERE, | 135 FROM_HERE, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 330 | 330 |
| 331 specifics->set_guid(profile.guid()); | 331 specifics->set_guid(profile.guid()); |
| 332 std::vector<string16> values; | 332 std::vector<string16> values; |
| 333 profile.GetMultiInfo(NAME_FIRST, &values); | 333 profile.GetMultiInfo(NAME_FIRST, &values); |
| 334 for (size_t i = 0; i < values.size(); ++i) | 334 for (size_t i = 0; i < values.size(); ++i) |
| 335 specifics->add_name_first(LimitData(UTF16ToUTF8(values[i]))); | 335 specifics->add_name_first(LimitData(UTF16ToUTF8(values[i]))); |
| 336 profile.GetMultiInfo(NAME_MIDDLE, &values); | 336 profile.GetMultiInfo(NAME_MIDDLE, &values); |
| 337 for (size_t i = 0; i < values.size(); ++i) | 337 for (size_t i = 0; i < values.size(); ++i) |
| 338 specifics->add_name_middle(LimitData(UTF16ToUTF8(values[i]))); | 338 specifics->add_name_middle(LimitData(UTF16ToUTF8(values[i]))); |
| 339 profile.GetMultiInfo(NAME_LAST, &values); | 339 profile.GetMultiInfo(NAME_LAST, &values); |
| 340 for (size_t i = 0; i < values.size(); ++i) | 340 for (size_t i = 0; i < values.size(); ++i) |
|
Dan Beam
2012/11/09 18:46:30
nit: curlies, IMO, and/or at least a \n under thes
Ilya Sherman
2012/11/10 03:21:33
Done.
| |
| 341 specifics->add_name_last(LimitData(UTF16ToUTF8(values[i]))); | 341 specifics->add_name_last(LimitData(UTF16ToUTF8(values[i]))); |
| 342 specifics->set_address_home_line1( | 342 specifics->set_address_home_line1( |
| 343 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_LINE1)))); | 343 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE1)))); |
| 344 specifics->set_address_home_line2( | 344 specifics->set_address_home_line2( |
| 345 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_LINE2)))); | 345 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE2)))); |
| 346 specifics->set_address_home_city( | 346 specifics->set_address_home_city( |
| 347 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_CITY)))); | 347 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY)))); |
| 348 specifics->set_address_home_state( | 348 specifics->set_address_home_state( |
| 349 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)))); | 349 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE)))); |
| 350 specifics->set_address_home_country( | 350 specifics->set_address_home_country( |
| 351 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)))); | 351 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)))); |
| 352 specifics->set_address_home_zip( | 352 specifics->set_address_home_zip( |
| 353 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)))); | 353 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP)))); |
| 354 profile.GetMultiInfo(EMAIL_ADDRESS, &values); | 354 profile.GetMultiInfo(EMAIL_ADDRESS, &values); |
| 355 for (size_t i = 0; i < values.size(); ++i) | 355 for (size_t i = 0; i < values.size(); ++i) |
| 356 specifics->add_email_address(LimitData(UTF16ToUTF8(values[i]))); | 356 specifics->add_email_address(LimitData(UTF16ToUTF8(values[i]))); |
| 357 specifics->set_company_name( | 357 specifics->set_company_name( |
| 358 LimitData(UTF16ToUTF8(profile.GetInfo(COMPANY_NAME)))); | 358 LimitData(UTF16ToUTF8(profile.GetRawInfo(COMPANY_NAME)))); |
| 359 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); | 359 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); |
| 360 for (size_t i = 0; i < values.size(); ++i) | 360 for (size_t i = 0; i < values.size(); ++i) |
| 361 specifics->add_phone_home_whole_number(LimitData(UTF16ToUTF8(values[i]))); | 361 specifics->add_phone_home_whole_number(LimitData(UTF16ToUTF8(values[i]))); |
| 362 } | 362 } |
| 363 | 363 |
| 364 void AutofillProfileSyncableService::CreateGUIDToProfileMap( | 364 void AutofillProfileSyncableService::CreateGUIDToProfileMap( |
| 365 const std::vector<AutofillProfile*>& profiles, | 365 const std::vector<AutofillProfile*>& profiles, |
| 366 GUIDToProfileMap* profile_map) { | 366 GUIDToProfileMap* profile_map) { |
| 367 DCHECK(profile_map); | 367 DCHECK(profile_map); |
| 368 profile_map->clear(); | 368 profile_map->clear(); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 396 new AutofillProfile(autofill_specifics.guid())); | 396 new AutofillProfile(autofill_specifics.guid())); |
| 397 OverwriteProfileWithServerData(autofill_specifics, new_profile); | 397 OverwriteProfileWithServerData(autofill_specifics, new_profile); |
| 398 | 398 |
| 399 // Check if profile appears under a different guid. | 399 // Check if profile appears under a different guid. |
| 400 for (GUIDToProfileMap::iterator i = profile_map->begin(); | 400 for (GUIDToProfileMap::iterator i = profile_map->begin(); |
| 401 i != profile_map->end(); ++i) { | 401 i != profile_map->end(); ++i) { |
| 402 if (i->second->Compare(*new_profile) == 0) { | 402 if (i->second->Compare(*new_profile) == 0) { |
| 403 bundle->profiles_to_delete.push_back(i->second->guid()); | 403 bundle->profiles_to_delete.push_back(i->second->guid()); |
| 404 DVLOG(2) << "[AUTOFILL SYNC]" | 404 DVLOG(2) << "[AUTOFILL SYNC]" |
| 405 << "Found in sync db but with a different guid: " | 405 << "Found in sync db but with a different guid: " |
| 406 << UTF16ToUTF8(i->second->GetInfo(NAME_FIRST)) | 406 << UTF16ToUTF8(i->second->GetRawInfo(NAME_FIRST)) |
| 407 << UTF16ToUTF8(i->second->GetInfo(NAME_LAST)) | 407 << UTF16ToUTF8(i->second->GetRawInfo(NAME_LAST)) |
| 408 << "New guid " << new_profile->guid() | 408 << "New guid " << new_profile->guid() |
| 409 << ". Profile to be deleted " << i->second->guid(); | 409 << ". Profile to be deleted " << i->second->guid(); |
| 410 profile_map->erase(i); | 410 profile_map->erase(i); |
| 411 break; | 411 break; |
| 412 } else if (!i->second->PrimaryValue().empty() && | 412 } else if (!i->second->PrimaryValue().empty() && |
| 413 i->second->PrimaryValue() == new_profile->PrimaryValue()) { | 413 i->second->PrimaryValue() == new_profile->PrimaryValue()) { |
| 414 // Add it to candidates for merge - if there is no profile with this | 414 // Add it to candidates for merge - if there is no profile with this |
| 415 // guid we will merge them. | 415 // guid we will merge them. |
| 416 bundle->candidates_to_merge.insert(std::make_pair(i->second->guid(), | 416 bundle->candidates_to_merge.insert(std::make_pair(i->second->guid(), |
| 417 new_profile)); | 417 new_profile)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 WriteAutofillProfile(profile, &specifics); | 484 WriteAutofillProfile(profile, &specifics); |
| 485 return | 485 return |
| 486 syncer::SyncData::CreateLocalData( | 486 syncer::SyncData::CreateLocalData( |
| 487 profile.guid(), profile.guid(), specifics); | 487 profile.guid(), profile.guid(), specifics); |
| 488 } | 488 } |
| 489 | 489 |
| 490 bool AutofillProfileSyncableService::UpdateField( | 490 bool AutofillProfileSyncableService::UpdateField( |
| 491 AutofillFieldType field_type, | 491 AutofillFieldType field_type, |
| 492 const std::string& new_value, | 492 const std::string& new_value, |
| 493 AutofillProfile* autofill_profile) { | 493 AutofillProfile* autofill_profile) { |
| 494 if (UTF16ToUTF8(autofill_profile->GetInfo(field_type)) == new_value) | 494 if (UTF16ToUTF8(autofill_profile->GetRawInfo(field_type)) == new_value) |
| 495 return false; | 495 return false; |
| 496 autofill_profile->SetInfo(field_type, UTF8ToUTF16(new_value)); | 496 autofill_profile->SetRawInfo(field_type, UTF8ToUTF16(new_value)); |
| 497 return true; | 497 return true; |
| 498 } | 498 } |
| 499 | 499 |
| 500 bool AutofillProfileSyncableService::UpdateMultivaluedField( | 500 bool AutofillProfileSyncableService::UpdateMultivaluedField( |
| 501 AutofillFieldType field_type, | 501 AutofillFieldType field_type, |
| 502 const ::google::protobuf::RepeatedPtrField<std::string>& new_values, | 502 const ::google::protobuf::RepeatedPtrField<std::string>& new_values, |
| 503 AutofillProfile* autofill_profile) { | 503 AutofillProfile* autofill_profile) { |
| 504 std::vector<string16> values; | 504 std::vector<string16> values; |
| 505 autofill_profile->GetMultiInfo(field_type, &values); | 505 autofill_profile->GetMultiInfo(field_type, &values); |
| 506 bool changed = false; | 506 bool changed = false; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 530 } | 530 } |
| 531 | 531 |
| 532 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { | 532 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { |
| 533 return web_data_service_->GetDatabase()->GetAutofillTable(); | 533 return web_data_service_->GetDatabase()->GetAutofillTable(); |
| 534 } | 534 } |
| 535 | 535 |
| 536 AutofillProfileSyncableService::DataBundle::DataBundle() {} | 536 AutofillProfileSyncableService::DataBundle::DataBundle() {} |
| 537 | 537 |
| 538 AutofillProfileSyncableService::DataBundle::~DataBundle() { | 538 AutofillProfileSyncableService::DataBundle::~DataBundle() { |
| 539 } | 539 } |
| OLD | NEW |