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