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

Side by Side Diff: chrome/browser/webdata/autofill_profile_syncable_service.cc

Issue 11360055: [Autofill] Rename GetInfo and SetInfo to GetRawInfo and SetRawInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase harder Created 8 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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
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
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 // Reset all multi-valued fields in the protobuf. 324 // Reset all multi-valued fields in the protobuf.
325 specifics->clear_name_first(); 325 specifics->clear_name_first();
326 specifics->clear_name_middle(); 326 specifics->clear_name_middle();
327 specifics->clear_name_last(); 327 specifics->clear_name_last();
328 specifics->clear_email_address(); 328 specifics->clear_email_address();
329 specifics->clear_phone_home_whole_number(); 329 specifics->clear_phone_home_whole_number();
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 }
337
336 profile.GetMultiInfo(NAME_MIDDLE, &values); 338 profile.GetMultiInfo(NAME_MIDDLE, &values);
337 for (size_t i = 0; i < values.size(); ++i) 339 for (size_t i = 0; i < values.size(); ++i) {
338 specifics->add_name_middle(LimitData(UTF16ToUTF8(values[i]))); 340 specifics->add_name_middle(LimitData(UTF16ToUTF8(values[i])));
341 }
342
339 profile.GetMultiInfo(NAME_LAST, &values); 343 profile.GetMultiInfo(NAME_LAST, &values);
340 for (size_t i = 0; i < values.size(); ++i) 344 for (size_t i = 0; i < values.size(); ++i) {
341 specifics->add_name_last(LimitData(UTF16ToUTF8(values[i]))); 345 specifics->add_name_last(LimitData(UTF16ToUTF8(values[i])));
346 }
347
342 specifics->set_address_home_line1( 348 specifics->set_address_home_line1(
343 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_LINE1)))); 349 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE1))));
344 specifics->set_address_home_line2( 350 specifics->set_address_home_line2(
345 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_LINE2)))); 351 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_LINE2))));
346 specifics->set_address_home_city( 352 specifics->set_address_home_city(
347 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_CITY)))); 353 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_CITY))));
348 specifics->set_address_home_state( 354 specifics->set_address_home_state(
349 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_STATE)))); 355 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_STATE))));
350 specifics->set_address_home_country( 356 specifics->set_address_home_country(
351 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_COUNTRY)))); 357 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY))));
352 specifics->set_address_home_zip( 358 specifics->set_address_home_zip(
353 LimitData(UTF16ToUTF8(profile.GetInfo(ADDRESS_HOME_ZIP)))); 359 LimitData(UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_ZIP))));
360
354 profile.GetMultiInfo(EMAIL_ADDRESS, &values); 361 profile.GetMultiInfo(EMAIL_ADDRESS, &values);
355 for (size_t i = 0; i < values.size(); ++i) 362 for (size_t i = 0; i < values.size(); ++i) {
356 specifics->add_email_address(LimitData(UTF16ToUTF8(values[i]))); 363 specifics->add_email_address(LimitData(UTF16ToUTF8(values[i])));
364 }
365
357 specifics->set_company_name( 366 specifics->set_company_name(
358 LimitData(UTF16ToUTF8(profile.GetInfo(COMPANY_NAME)))); 367 LimitData(UTF16ToUTF8(profile.GetRawInfo(COMPANY_NAME))));
368
359 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values); 369 profile.GetMultiInfo(PHONE_HOME_WHOLE_NUMBER, &values);
360 for (size_t i = 0; i < values.size(); ++i) 370 for (size_t i = 0; i < values.size(); ++i) {
361 specifics->add_phone_home_whole_number(LimitData(UTF16ToUTF8(values[i]))); 371 specifics->add_phone_home_whole_number(LimitData(UTF16ToUTF8(values[i])));
372 }
362 } 373 }
363 374
364 void AutofillProfileSyncableService::CreateGUIDToProfileMap( 375 void AutofillProfileSyncableService::CreateGUIDToProfileMap(
365 const std::vector<AutofillProfile*>& profiles, 376 const std::vector<AutofillProfile*>& profiles,
366 GUIDToProfileMap* profile_map) { 377 GUIDToProfileMap* profile_map) {
367 DCHECK(profile_map); 378 DCHECK(profile_map);
368 profile_map->clear(); 379 profile_map->clear();
369 for (size_t i = 0; i < profiles.size(); ++i) 380 for (size_t i = 0; i < profiles.size(); ++i)
370 (*profile_map)[profiles[i]->guid()] = profiles[i]; 381 (*profile_map)[profiles[i]->guid()] = profiles[i];
371 } 382 }
(...skipping 24 matching lines...) Expand all
396 new AutofillProfile(autofill_specifics.guid())); 407 new AutofillProfile(autofill_specifics.guid()));
397 OverwriteProfileWithServerData(autofill_specifics, new_profile); 408 OverwriteProfileWithServerData(autofill_specifics, new_profile);
398 409
399 // Check if profile appears under a different guid. 410 // Check if profile appears under a different guid.
400 for (GUIDToProfileMap::iterator i = profile_map->begin(); 411 for (GUIDToProfileMap::iterator i = profile_map->begin();
401 i != profile_map->end(); ++i) { 412 i != profile_map->end(); ++i) {
402 if (i->second->Compare(*new_profile) == 0) { 413 if (i->second->Compare(*new_profile) == 0) {
403 bundle->profiles_to_delete.push_back(i->second->guid()); 414 bundle->profiles_to_delete.push_back(i->second->guid());
404 DVLOG(2) << "[AUTOFILL SYNC]" 415 DVLOG(2) << "[AUTOFILL SYNC]"
405 << "Found in sync db but with a different guid: " 416 << "Found in sync db but with a different guid: "
406 << UTF16ToUTF8(i->second->GetInfo(NAME_FIRST)) 417 << UTF16ToUTF8(i->second->GetRawInfo(NAME_FIRST))
407 << UTF16ToUTF8(i->second->GetInfo(NAME_LAST)) 418 << UTF16ToUTF8(i->second->GetRawInfo(NAME_LAST))
408 << "New guid " << new_profile->guid() 419 << "New guid " << new_profile->guid()
409 << ". Profile to be deleted " << i->second->guid(); 420 << ". Profile to be deleted " << i->second->guid();
410 profile_map->erase(i); 421 profile_map->erase(i);
411 break; 422 break;
412 } else if (!i->second->PrimaryValue().empty() && 423 } else if (!i->second->PrimaryValue().empty() &&
413 i->second->PrimaryValue() == new_profile->PrimaryValue()) { 424 i->second->PrimaryValue() == new_profile->PrimaryValue()) {
414 // Add it to candidates for merge - if there is no profile with this 425 // Add it to candidates for merge - if there is no profile with this
415 // guid we will merge them. 426 // guid we will merge them.
416 bundle->candidates_to_merge.insert(std::make_pair(i->second->guid(), 427 bundle->candidates_to_merge.insert(std::make_pair(i->second->guid(),
417 new_profile)); 428 new_profile));
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 WriteAutofillProfile(profile, &specifics); 495 WriteAutofillProfile(profile, &specifics);
485 return 496 return
486 syncer::SyncData::CreateLocalData( 497 syncer::SyncData::CreateLocalData(
487 profile.guid(), profile.guid(), specifics); 498 profile.guid(), profile.guid(), specifics);
488 } 499 }
489 500
490 bool AutofillProfileSyncableService::UpdateField( 501 bool AutofillProfileSyncableService::UpdateField(
491 AutofillFieldType field_type, 502 AutofillFieldType field_type,
492 const std::string& new_value, 503 const std::string& new_value,
493 AutofillProfile* autofill_profile) { 504 AutofillProfile* autofill_profile) {
494 if (UTF16ToUTF8(autofill_profile->GetInfo(field_type)) == new_value) 505 if (UTF16ToUTF8(autofill_profile->GetRawInfo(field_type)) == new_value)
495 return false; 506 return false;
496 autofill_profile->SetInfo(field_type, UTF8ToUTF16(new_value)); 507 autofill_profile->SetRawInfo(field_type, UTF8ToUTF16(new_value));
497 return true; 508 return true;
498 } 509 }
499 510
500 bool AutofillProfileSyncableService::UpdateMultivaluedField( 511 bool AutofillProfileSyncableService::UpdateMultivaluedField(
501 AutofillFieldType field_type, 512 AutofillFieldType field_type,
502 const ::google::protobuf::RepeatedPtrField<std::string>& new_values, 513 const ::google::protobuf::RepeatedPtrField<std::string>& new_values,
503 AutofillProfile* autofill_profile) { 514 AutofillProfile* autofill_profile) {
504 std::vector<string16> values; 515 std::vector<string16> values;
505 autofill_profile->GetMultiInfo(field_type, &values); 516 autofill_profile->GetMultiInfo(field_type, &values);
506 bool changed = false; 517 bool changed = false;
(...skipping 23 matching lines...) Expand all
530 } 541 }
531 542
532 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { 543 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const {
533 return web_data_service_->GetDatabase()->GetAutofillTable(); 544 return web_data_service_->GetDatabase()->GetAutofillTable();
534 } 545 }
535 546
536 AutofillProfileSyncableService::DataBundle::DataBundle() {} 547 AutofillProfileSyncableService::DataBundle::DataBundle() {}
537 548
538 AutofillProfileSyncableService::DataBundle::~DataBundle() { 549 AutofillProfileSyncableService::DataBundle::~DataBundle() {
539 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698