Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/memory/ptr_util.h" | |
| 9 #include "components/autofill/core/browser/webdata/autofill_table.h" | |
| 10 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h" | |
| 11 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | |
| 12 #include "components/sync/model/entity_data.h" | |
| 13 #include "components/sync/model/model_type_change_processor.h" | |
| 14 #include "components/sync/model/sync_error.h" | |
| 15 #include "net/base/escape.h" | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 const char kAutocompleteEntryNamespaceTag[] = "autofill_entry|"; | |
| 20 | |
| 21 // static | |
|
maxbogue
2016/11/22 19:07:23
remove; not needed (it's obviously not a method si
Patrick Noland
2016/11/29 00:09:50
Done.
| |
| 22 void* UserDataKey() { | |
| 23 // Use the address of a static that COMDAT folding won't ever collide | |
| 24 // with something else. | |
| 25 static int user_data_key = 0; | |
| 26 return reinterpret_cast<void*>(&user_data_key); | |
| 27 } | |
| 28 | |
| 29 // static | |
|
maxbogue
2016/11/22 19:07:23
same
Patrick Noland
2016/11/29 00:09:50
Done.
| |
| 30 const std::string FormatStorageKey(const std::string name, | |
| 31 const std::string value) { | |
| 32 return net::EscapePath(name) + "|" + net::EscapePath(value); | |
| 33 } | |
| 34 } // namespace | |
|
maxbogue
2016/11/22 19:07:23
line above
Patrick Noland
2016/11/29 00:09:50
Done.
| |
| 35 | |
| 36 namespace autofill { | |
| 37 | |
| 38 // static | |
| 39 void AutocompleteSyncBridge::CreateForWebDataServiceAndBackend( | |
| 40 AutofillWebDataService* web_data_service, | |
| 41 AutofillWebDataBackend* web_data_backend) { | |
| 42 web_data_service->GetDBUserData()->SetUserData( | |
| 43 UserDataKey(), | |
| 44 new AutocompleteSyncBridge( | |
| 45 web_data_backend, | |
| 46 base::Bind(&syncer::ModelTypeChangeProcessor::Create))); | |
| 47 } | |
| 48 | |
| 49 // static | |
| 50 AutocompleteSyncBridge* AutocompleteSyncBridge::FromWebDataService( | |
| 51 AutofillWebDataService* web_data_service) { | |
| 52 return static_cast<AutocompleteSyncBridge*>( | |
| 53 web_data_service->GetDBUserData()->GetUserData(UserDataKey())); | |
| 54 } | |
| 55 | |
| 56 AutocompleteSyncBridge::AutocompleteSyncBridge( | |
| 57 AutofillWebDataBackend* backend, | |
| 58 const ChangeProcessorFactory& change_processor_factory) | |
| 59 : ModelTypeSyncBridge(change_processor_factory, syncer::AUTOFILL), | |
| 60 web_data_backend_(backend), | |
| 61 scoped_observer_(this) { | |
| 62 DCHECK(web_data_backend_); | |
| 63 | |
| 64 scoped_observer_.Add(web_data_backend_); | |
| 65 } | |
| 66 | |
| 67 AutocompleteSyncBridge::~AutocompleteSyncBridge() { | |
| 68 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 69 } | |
| 70 | |
| 71 // syncer::ModelTypeService implementation. | |
| 72 std::unique_ptr<syncer::MetadataChangeList> | |
| 73 AutocompleteSyncBridge::CreateMetadataChangeList() { | |
| 74 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 75 NOTIMPLEMENTED(); | |
| 76 return nullptr; | |
| 77 } | |
| 78 | |
| 79 syncer::SyncError AutocompleteSyncBridge::MergeSyncData( | |
| 80 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, | |
| 81 syncer::EntityDataMap entity_data_map) { | |
| 82 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 83 NOTIMPLEMENTED(); | |
| 84 return syncer::SyncError(); | |
| 85 } | |
| 86 | |
| 87 syncer::SyncError AutocompleteSyncBridge::ApplySyncChanges( | |
| 88 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, | |
| 89 syncer::EntityChangeList entity_changes) { | |
| 90 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 91 NOTIMPLEMENTED(); | |
| 92 return syncer::SyncError(); | |
| 93 } | |
| 94 void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData( | |
| 95 StorageKeyList storage_keys, | |
| 96 DataCallback callback) { | |
| 97 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 98 NOTIMPLEMENTED(); | |
| 99 } | |
| 100 | |
| 101 void AutocompleteSyncBridge::GetAllData(DataCallback callback) { | |
| 102 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 103 NOTIMPLEMENTED(); | |
| 104 } | |
| 105 | |
| 106 std::string AutocompleteSyncBridge::GetClientTag( | |
| 107 const syncer::EntityData& entity_data) { | |
| 108 DCHECK(entity_data.specifics.has_autofill()); | |
| 109 | |
| 110 const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill(); | |
| 111 std::string storage_key = | |
| 112 FormatStorageKey(specifics.name(), specifics.value()); | |
| 113 std::string prefix(kAutocompleteEntryNamespaceTag); | |
| 114 return prefix + storage_key; | |
| 115 } | |
| 116 | |
| 117 std::string AutocompleteSyncBridge::GetStorageKey( | |
| 118 const syncer::EntityData& entity_data) { | |
| 119 const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill(); | |
| 120 return FormatStorageKey(specifics.name(), specifics.value()); | |
| 121 } | |
| 122 | |
| 123 // AutofillWebDataServiceObserverOnDBThread implementation. | |
| 124 void AutocompleteSyncBridge::AutofillEntriesChanged( | |
| 125 const AutofillChangeList& changes) { | |
| 126 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 127 } | |
| 128 | |
| 129 } // namespace autofill | |
| OLD | NEW |