| 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 return ret_val; \ | 50 return ret_val; \ |
| 51 } | 51 } |
| 52 | 52 |
| 53 void* UserDataKey() { | 53 void* UserDataKey() { |
| 54 // Use the address of a static that COMDAT folding won't ever collide | 54 // Use the address of a static that COMDAT folding won't ever collide |
| 55 // with something else. | 55 // with something else. |
| 56 static int user_data_key = 0; | 56 static int user_data_key = 0; |
| 57 return reinterpret_cast<void*>(&user_data_key); | 57 return reinterpret_cast<void*>(&user_data_key); |
| 58 } | 58 } |
| 59 | 59 |
| 60 std::string EscapeIdentifiers(const AutofillSpecifics& specifics) { |
| 61 return net::EscapePath(specifics.name()) + |
| 62 std::string(kAutocompleteTagDelimiter) + |
| 63 net::EscapePath(specifics.value()); |
| 64 } |
| 65 |
| 60 std::unique_ptr<EntityData> CreateEntityData(const AutofillEntry& entry) { | 66 std::unique_ptr<EntityData> CreateEntityData(const AutofillEntry& entry) { |
| 61 auto entity_data = base::MakeUnique<EntityData>(); | 67 auto entity_data = base::MakeUnique<EntityData>(); |
| 62 entity_data->non_unique_name = base::UTF16ToUTF8(entry.key().name()); | |
| 63 AutofillSpecifics* autofill = entity_data->specifics.mutable_autofill(); | 68 AutofillSpecifics* autofill = entity_data->specifics.mutable_autofill(); |
| 64 autofill->set_name(base::UTF16ToUTF8(entry.key().name())); | 69 autofill->set_name(base::UTF16ToUTF8(entry.key().name())); |
| 65 autofill->set_value(base::UTF16ToUTF8(entry.key().value())); | 70 autofill->set_value(base::UTF16ToUTF8(entry.key().value())); |
| 66 autofill->add_usage_timestamp(entry.date_created().ToInternalValue()); | 71 autofill->add_usage_timestamp(entry.date_created().ToInternalValue()); |
| 67 if (entry.date_created() != entry.date_last_used()) | 72 if (entry.date_created() != entry.date_last_used()) |
| 68 autofill->add_usage_timestamp(entry.date_last_used().ToInternalValue()); | 73 autofill->add_usage_timestamp(entry.date_last_used().ToInternalValue()); |
| 74 entity_data->non_unique_name = EscapeIdentifiers(*autofill); |
| 69 return entity_data; | 75 return entity_data; |
| 70 } | 76 } |
| 71 | 77 |
| 72 std::string BuildSerializedStorageKey(const std::string& name, | 78 std::string BuildSerializedStorageKey(const std::string& name, |
| 73 const std::string& value) { | 79 const std::string& value) { |
| 74 AutofillSyncStorageKey proto; | 80 AutofillSyncStorageKey proto; |
| 75 proto.set_name(name); | 81 proto.set_name(name); |
| 76 proto.set_value(value); | 82 proto.set_value(value); |
| 77 return proto.SerializeAsString(); | 83 return proto.SerializeAsString(); |
| 78 } | 84 } |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 change_processor()->ReportError( | 449 change_processor()->ReportError( |
| 444 FROM_HERE, "Failed reading autofill metadata from WebDatabase."); | 450 FROM_HERE, "Failed reading autofill metadata from WebDatabase."); |
| 445 return; | 451 return; |
| 446 } | 452 } |
| 447 change_processor()->ModelReadyToSync(std::move(batch)); | 453 change_processor()->ModelReadyToSync(std::move(batch)); |
| 448 } | 454 } |
| 449 | 455 |
| 450 std::string AutocompleteSyncBridge::GetClientTag( | 456 std::string AutocompleteSyncBridge::GetClientTag( |
| 451 const EntityData& entity_data) { | 457 const EntityData& entity_data) { |
| 452 DCHECK(entity_data.specifics.has_autofill()); | 458 DCHECK(entity_data.specifics.has_autofill()); |
| 453 const AutofillSpecifics specifics = entity_data.specifics.autofill(); | |
| 454 return std::string(kAutocompleteEntryNamespaceTag) + | 459 return std::string(kAutocompleteEntryNamespaceTag) + |
| 455 net::EscapePath(specifics.name()) + | 460 EscapeIdentifiers(entity_data.specifics.autofill()); |
| 456 std::string(kAutocompleteTagDelimiter) + | |
| 457 net::EscapePath(specifics.value()); | |
| 458 } | 461 } |
| 459 | 462 |
| 460 std::string AutocompleteSyncBridge::GetStorageKey( | 463 std::string AutocompleteSyncBridge::GetStorageKey( |
| 461 const EntityData& entity_data) { | 464 const EntityData& entity_data) { |
| 462 DCHECK(entity_data.specifics.has_autofill()); | 465 DCHECK(entity_data.specifics.has_autofill()); |
| 463 const AutofillSpecifics specifics = entity_data.specifics.autofill(); | 466 const AutofillSpecifics specifics = entity_data.specifics.autofill(); |
| 464 return BuildSerializedStorageKey(specifics.name(), specifics.value()); | 467 return BuildSerializedStorageKey(specifics.name(), specifics.value()); |
| 465 } | 468 } |
| 466 | 469 |
| 467 // AutofillWebDataServiceObserverOnDBThread implementation. | 470 // AutofillWebDataServiceObserverOnDBThread implementation. |
| 468 void AutocompleteSyncBridge::AutofillEntriesChanged( | 471 void AutocompleteSyncBridge::AutofillEntriesChanged( |
| 469 const AutofillChangeList& changes) { | 472 const AutofillChangeList& changes) { |
| 470 DCHECK(thread_checker_.CalledOnValidThread()); | 473 DCHECK(thread_checker_.CalledOnValidThread()); |
| 471 ActOnLocalChanges(changes); | 474 ActOnLocalChanges(changes); |
| 472 } | 475 } |
| 473 | 476 |
| 474 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { | 477 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { |
| 475 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); | 478 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); |
| 476 } | 479 } |
| 477 | 480 |
| 478 } // namespace autofill | 481 } // namespace autofill |
| OLD | NEW |