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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, |
136 "Failed to update webdata."); | 136 "Failed to update webdata."); |
137 } | 137 } |
138 | 138 |
139 syncer::SyncChangeList new_changes; | 139 syncer::SyncChangeList new_changes; |
140 for (GUIDToProfileMap::iterator i = remaining_profiles.begin(); | 140 for (GUIDToProfileMap::iterator i = remaining_profiles.begin(); |
141 i != remaining_profiles.end(); ++i) { | 141 i != remaining_profiles.end(); ++i) { |
142 new_changes.push_back( | 142 new_changes.push_back( |
143 syncer::SyncChange(FROM_HERE, | 143 syncer::SyncChange( |
144 syncer::SyncChange::ACTION_ADD, | 144 syncer::SyncChange::ACTION_ADD, CreateData(*(i->second)))); |
145 CreateData(*(i->second)))); | |
146 profiles_map_[i->first] = i->second; | 145 profiles_map_[i->first] = i->second; |
147 } | 146 } |
148 | 147 |
149 for (size_t i = 0; i < bundle.profiles_to_sync_back.size(); ++i) { | 148 for (size_t i = 0; i < bundle.profiles_to_sync_back.size(); ++i) { |
150 new_changes.push_back( | 149 new_changes.push_back( |
151 syncer::SyncChange(FROM_HERE, | 150 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, |
152 syncer::SyncChange::ACTION_UPDATE, | 151 CreateData(*(bundle.profiles_to_sync_back[i])))); |
153 CreateData(*(bundle.profiles_to_sync_back[i])))); | |
154 } | 152 } |
155 | 153 |
156 syncer::SyncError error; | 154 syncer::SyncError error; |
157 if (!new_changes.empty()) | 155 if (!new_changes.empty()) |
158 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); | 156 error = sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); |
159 | 157 |
160 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); | 158 WebDataService::NotifyOfMultipleAutofillChanges(web_data_service_); |
161 | 159 |
162 return error; | 160 return error; |
163 } | 161 } |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 const AutofillProfileChange& change) { | 427 const AutofillProfileChange& change) { |
430 DCHECK((change.type() == AutofillProfileChange::REMOVE && | 428 DCHECK((change.type() == AutofillProfileChange::REMOVE && |
431 !change.profile()) || | 429 !change.profile()) || |
432 (change.type() != AutofillProfileChange::REMOVE && change.profile())); | 430 (change.type() != AutofillProfileChange::REMOVE && change.profile())); |
433 DCHECK(sync_processor_.get()); | 431 DCHECK(sync_processor_.get()); |
434 syncer::SyncChangeList new_changes; | 432 syncer::SyncChangeList new_changes; |
435 DataBundle bundle; | 433 DataBundle bundle; |
436 switch (change.type()) { | 434 switch (change.type()) { |
437 case AutofillProfileChange::ADD: | 435 case AutofillProfileChange::ADD: |
438 new_changes.push_back( | 436 new_changes.push_back( |
439 syncer::SyncChange(FROM_HERE, | 437 syncer::SyncChange( |
440 syncer::SyncChange::ACTION_ADD, | 438 syncer::SyncChange::ACTION_ADD, CreateData(*(change.profile())))); |
441 CreateData(*(change.profile())))); | |
442 DCHECK(profiles_map_.find(change.profile()->guid()) == | 439 DCHECK(profiles_map_.find(change.profile()->guid()) == |
443 profiles_map_.end()); | 440 profiles_map_.end()); |
444 profiles_.push_back(new AutofillProfile(*(change.profile()))); | 441 profiles_.push_back(new AutofillProfile(*(change.profile()))); |
445 profiles_map_[change.profile()->guid()] = profiles_.get().back(); | 442 profiles_map_[change.profile()->guid()] = profiles_.get().back(); |
446 break; | 443 break; |
447 case AutofillProfileChange::UPDATE: { | 444 case AutofillProfileChange::UPDATE: { |
448 GUIDToProfileMap::iterator it = profiles_map_.find( | 445 GUIDToProfileMap::iterator it = profiles_map_.find( |
449 change.profile()->guid()); | 446 change.profile()->guid()); |
450 DCHECK(it != profiles_map_.end()); | 447 DCHECK(it != profiles_map_.end()); |
451 *(it->second) = *(change.profile()); | 448 *(it->second) = *(change.profile()); |
452 new_changes.push_back( | 449 new_changes.push_back( |
453 syncer::SyncChange(FROM_HERE, | 450 syncer::SyncChange(syncer::SyncChange::ACTION_UPDATE, |
454 syncer::SyncChange::ACTION_UPDATE, | 451 CreateData(*(change.profile())))); |
455 CreateData(*(change.profile())))); | |
456 break; | 452 break; |
457 } | 453 } |
458 case AutofillProfileChange::REMOVE: { | 454 case AutofillProfileChange::REMOVE: { |
459 AutofillProfile empty_profile(change.key()); | 455 AutofillProfile empty_profile(change.key()); |
460 new_changes.push_back( | 456 new_changes.push_back( |
461 syncer::SyncChange(FROM_HERE, | 457 syncer::SyncChange(syncer::SyncChange::ACTION_DELETE, |
462 syncer::SyncChange::ACTION_DELETE, | |
463 CreateData(empty_profile))); | 458 CreateData(empty_profile))); |
464 profiles_map_.erase(change.key()); | 459 profiles_map_.erase(change.key()); |
465 break; | 460 break; |
466 } | 461 } |
467 default: | 462 default: |
468 NOTREACHED(); | 463 NOTREACHED(); |
469 } | 464 } |
470 syncer::SyncError error = | 465 syncer::SyncError error = |
471 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); | 466 sync_processor_->ProcessSyncChanges(FROM_HERE, new_changes); |
472 if (error.IsSet()) { | 467 if (error.IsSet()) { |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 } | 525 } |
531 | 526 |
532 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { | 527 AutofillTable* AutofillProfileSyncableService::GetAutofillTable() const { |
533 return web_data_service_->GetDatabase()->GetAutofillTable(); | 528 return web_data_service_->GetDatabase()->GetAutofillTable(); |
534 } | 529 } |
535 | 530 |
536 AutofillProfileSyncableService::DataBundle::DataBundle() {} | 531 AutofillProfileSyncableService::DataBundle::DataBundle() {} |
537 | 532 |
538 AutofillProfileSyncableService::DataBundle::~DataBundle() { | 533 AutofillProfileSyncableService::DataBundle::~DataBundle() { |
539 } | 534 } |
OLD | NEW |