| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/webdata/autocomplete_sync_bridge.h" | 5 #include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <unordered_set> | 9 #include <unordered_set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 136 } |
| 137 | 137 |
| 138 const AutofillEntry remote = CreateAutofillEntry(specifics); | 138 const AutofillEntry remote = CreateAutofillEntry(specifics); |
| 139 DCHECK_EQ(storage_key, GetStorageKeyFromModel(remote.key())); | 139 DCHECK_EQ(storage_key, GetStorageKeyFromModel(remote.key())); |
| 140 | 140 |
| 141 Optional<AutofillEntry> local; | 141 Optional<AutofillEntry> local; |
| 142 if (!ReadEntry(remote.key(), &local)) { | 142 if (!ReadEntry(remote.key(), &local)) { |
| 143 return ModelError(FROM_HERE, "Failed reading from WebDatabase."); | 143 return ModelError(FROM_HERE, "Failed reading from WebDatabase."); |
| 144 } else if (!local) { | 144 } else if (!local) { |
| 145 save_to_local_.push_back(remote); | 145 save_to_local_.push_back(remote); |
| 146 } else if (remote != local.value()) { | 146 } else { |
| 147 if (specifics.usage_timestamp().empty()) { | 147 unique_to_local_.erase(local.value()); |
| 148 // Skip merging if there are no timestamps. We don't want to wipe out | 148 if (remote != local.value()) { |
| 149 // a local value of |date_created| if the remote copy is oddly formed. | 149 if (specifics.usage_timestamp().empty()) { |
| 150 save_to_sync_.push_back(local.value()); | 150 // Skip merging if there are no timestamps. We don't want to wipe out |
| 151 } else { | 151 // a local value of |date_created| if the remote copy is oddly formed. |
| 152 const AutofillEntry merged = MergeEntryDates(local.value(), remote); | 152 save_to_sync_.push_back(local.value()); |
| 153 save_to_local_.push_back(merged); | 153 } else { |
| 154 save_to_sync_.push_back(merged); | 154 const AutofillEntry merged = MergeEntryDates(local.value(), remote); |
| 155 save_to_local_.push_back(merged); |
| 156 save_to_sync_.push_back(merged); |
| 157 } |
| 155 } | 158 } |
| 156 unique_to_local_.erase(local.value()); | |
| 157 } | 159 } |
| 158 return {}; | 160 return {}; |
| 159 } | 161 } |
| 160 | 162 |
| 161 Optional<ModelError> IncorporateRemoteDelete(const std::string& storage_key) { | 163 Optional<ModelError> IncorporateRemoteDelete(const std::string& storage_key) { |
| 162 AutofillKey key; | 164 AutofillKey key; |
| 163 if (!ParseStorageKey(storage_key, &key)) { | 165 if (!ParseStorageKey(storage_key, &key)) { |
| 164 return ModelError(FROM_HERE, "Failed parsing storage key."); | 166 return ModelError(FROM_HERE, "Failed parsing storage key."); |
| 165 } | 167 } |
| 166 delete_from_local_.insert(key); | 168 delete_from_local_.insert(key); |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 DCHECK(thread_checker_.CalledOnValidThread()); | 313 DCHECK(thread_checker_.CalledOnValidThread()); |
| 312 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(), | 314 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(), |
| 313 syncer::AUTOFILL); | 315 syncer::AUTOFILL); |
| 314 } | 316 } |
| 315 | 317 |
| 316 Optional<syncer::ModelError> AutocompleteSyncBridge::MergeSyncData( | 318 Optional<syncer::ModelError> AutocompleteSyncBridge::MergeSyncData( |
| 317 std::unique_ptr<MetadataChangeList> metadata_change_list, | 319 std::unique_ptr<MetadataChangeList> metadata_change_list, |
| 318 EntityDataMap entity_data_map) { | 320 EntityDataMap entity_data_map) { |
| 319 DCHECK(thread_checker_.CalledOnValidThread()); | 321 DCHECK(thread_checker_.CalledOnValidThread()); |
| 320 | 322 |
| 321 // TODO(skym, crbug.com/680218): Uncomment and add unit tests. | 323 SyncDifferenceTracker tracker(GetAutofillTable()); |
| 322 /*SyncDifferenceTracker tracker(GetAutofillTable()); | |
| 323 for (auto kv : entity_data_map) { | 324 for (auto kv : entity_data_map) { |
| 324 DCHECK(kv.second->specifics.has_autofill()); | 325 DCHECK(kv.second->specifics.has_autofill()); |
| 325 RETURN_IF_ERROR(tracker.IncorporateRemoteSpecifics( | 326 RETURN_IF_ERROR(tracker.IncorporateRemoteSpecifics( |
| 326 kv.first, kv.second->specifics.autofill())); | 327 kv.first, kv.second->specifics.autofill())); |
| 327 } | 328 } |
| 328 | 329 |
| 329 RETURN_IF_ERROR(tracker.FlushToLocal(web_data_backend_)); | 330 RETURN_IF_ERROR(tracker.FlushToLocal(web_data_backend_)); |
| 330 RETURN_IF_ERROR(tracker.FlushToSync(true, std::move(metadata_change_list), | 331 RETURN_IF_ERROR(tracker.FlushToSync(true, std::move(metadata_change_list), |
| 331 change_processor())); | 332 change_processor())); |
| 332 web_data_backend_->RemoveExpiredFormElements(); | 333 web_data_backend_->RemoveExpiredFormElements(); |
| 333 web_data_backend_->NotifyThatSyncHasStarted(syncer::AUTOFILL);*/ | 334 web_data_backend_->NotifyThatSyncHasStarted(syncer::AUTOFILL); |
| 334 return {}; | 335 return {}; |
| 335 } | 336 } |
| 336 | 337 |
| 337 Optional<ModelError> AutocompleteSyncBridge::ApplySyncChanges( | 338 Optional<ModelError> AutocompleteSyncBridge::ApplySyncChanges( |
| 338 std::unique_ptr<MetadataChangeList> metadata_change_list, | 339 std::unique_ptr<MetadataChangeList> metadata_change_list, |
| 339 EntityChangeList entity_changes) { | 340 EntityChangeList entity_changes) { |
| 340 DCHECK(thread_checker_.CalledOnValidThread()); | 341 DCHECK(thread_checker_.CalledOnValidThread()); |
| 341 | 342 |
| 342 SyncDifferenceTracker tracker(GetAutofillTable()); | 343 SyncDifferenceTracker tracker(GetAutofillTable()); |
| 343 for (const EntityChange& change : entity_changes) { | 344 for (const EntityChange& change : entity_changes) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 const AutofillChangeList& changes) { | 469 const AutofillChangeList& changes) { |
| 469 DCHECK(thread_checker_.CalledOnValidThread()); | 470 DCHECK(thread_checker_.CalledOnValidThread()); |
| 470 ActOnLocalChanges(changes); | 471 ActOnLocalChanges(changes); |
| 471 } | 472 } |
| 472 | 473 |
| 473 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { | 474 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { |
| 474 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); | 475 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); |
| 475 } | 476 } |
| 476 | 477 |
| 477 } // namespace autofill | 478 } // namespace autofill |
| OLD | NEW |