Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc

Issue 2508263003: [sync] skeleton implementation of AutocompleteSyncBridge (Closed)
Patch Set: [sync] skeleton implementation of autocomplete_sync_bridge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
maxbogue 2016/11/18 22:22:35 line below
Patrick Noland 2016/11/22 18:51:04 Done.
4 #include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h"
5
6 #include "base/bind.h"
7 #include "base/memory/ptr_util.h"
8 #include "components/autofill/core/browser/webdata/autofill_table.h"
9 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h"
10 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
11 #include "components/sync/model/entity_data.h"
12 #include "components/sync/model/model_type_change_processor.h"
13 #include "components/sync/model/sync_error.h"
14 #include "components/sync/model_impl/accumulating_metadata_change_list.h"
15
maxbogue 2016/11/18 22:22:35 no blank line; it's all one section.
Patrick Noland 2016/11/22 18:51:04 Done.
16 #include "net/base/escape.h"
17
18 namespace {
maxbogue 2016/11/18 22:22:35 Add line below.
Patrick Noland 2016/11/22 18:51:04 Done.
19 void* UserDataKey() {
20 // Use the address of a static that COMDAT folding won't ever collide
21 // with something else.
22 static int user_data_key = 0;
23 return reinterpret_cast<void*>(&user_data_key);
24 }
25
26 const std::string FormatStorageKey(const std::string name,
27 const std::string value) {
28 return net::EscapePath(name) + "|" + net::EscapePath(value);
29 }
30 } // namespace
maxbogue 2016/11/18 22:22:35 Add line above.
Patrick Noland 2016/11/22 18:51:04 Done.
31
32 namespace autofill {
33
34 const char kAutocompleteEntryNamespaceTag[] = "autofill_entry|";
maxbogue 2016/11/18 22:22:35 The whole anonymous namespace can be inside the au
Patrick Noland 2016/11/22 18:51:04 Done.
35
36 // static
37 void AutocompleteSyncBridge::CreateForWebDataServiceAndBackend(
38 AutofillWebDataService* web_data_service,
39 AutofillWebDataBackend* web_data_backend) {
40 web_data_service->GetDBUserData()->SetUserData(
41 UserDataKey(),
42 new AutocompleteSyncBridge(
43 web_data_backend,
44 base::Bind(&syncer::ModelTypeChangeProcessor::Create)));
45 }
46
47 // static
48 AutocompleteSyncBridge* AutocompleteSyncBridge::FromWebDataService(
49 AutofillWebDataService* web_data_service) {
50 return static_cast<AutocompleteSyncBridge*>(
51 web_data_service->GetDBUserData()->GetUserData(UserDataKey()));
52 }
53
54 AutocompleteSyncBridge::AutocompleteSyncBridge(
55 AutofillWebDataBackend* backend,
56 const ChangeProcessorFactory& change_processor_factory)
57 : ModelTypeSyncBridge(change_processor_factory, syncer::AUTOFILL),
58 web_data_backend_(backend),
59 scoped_observer_(this) {
60 DCHECK(web_data_backend_);
61
62 scoped_observer_.Add(web_data_backend_);
63 }
64
65 AutocompleteSyncBridge::~AutocompleteSyncBridge() {
66 DCHECK(CalledOnValidThread());
67 }
68
69 // syncer::ModelTypeService implementation.
70 std::unique_ptr<syncer::MetadataChangeList>
71 AutocompleteSyncBridge::CreateMetadataChangeList() {
72 NOTIMPLEMENTED();
73 return base::MakeUnique<syncer::AccumulatingMetadataChangeList>();
maxbogue 2016/11/18 22:22:36 You want to make your own subclass of InMemoryMeta
Patrick Noland 2016/11/22 18:51:04 Done.
74 }
75
76 syncer::SyncError AutocompleteSyncBridge::MergeSyncData(
77 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
78 syncer::EntityDataMap entity_data_map) {
79 DCHECK(CalledOnValidThread());
80 NOTIMPLEMENTED();
81 return syncer::SyncError();
82 }
83
84 syncer::SyncError AutocompleteSyncBridge::ApplySyncChanges(
85 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
86 syncer::EntityChangeList entity_changes) {
87 NOTIMPLEMENTED();
88 return syncer::SyncError();
89 }
90 void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData(
91 StorageKeyList storage_keys,
92 DataCallback callback) {
93 NOTIMPLEMENTED();
94 }
95
96 void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
97 NOTIMPLEMENTED();
98 }
99
100 std::string AutocompleteSyncBridge::GetClientTag(
101 const syncer::EntityData& entity_data) {
102 DCHECK(entity_data.specifics.has_autofill());
103
104 const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill();
105 std::string storage_key =
106 FormatStorageKey(specifics.name(), specifics.value());
107 return KeyToTag(storage_key);
pavely 2016/11/21 22:54:19 KeyToTag is just prepending storage_key with prefi
Patrick Noland 2016/11/22 18:51:04 Done.
108 }
109
110 std::string AutocompleteSyncBridge::GetStorageKey(
111 const syncer::EntityData& entity_data) {
112 DCHECK(entity_data.specifics.has_autofill());
113
114 const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill();
115 return FormatStorageKey(specifics.name(), specifics.value());
116 }
117
118 syncer::ConflictResolution AutocompleteSyncBridge::ResolveConflict(
maxbogue 2016/11/18 22:22:35 This one is optional to override and should probab
Patrick Noland 2016/11/22 18:51:04 Done.
119 const syncer::EntityData& local_data,
120 const syncer::EntityData& remote_data) const {
121 return syncer::ConflictResolution::UseLocal();
122 }
123
124 // AutofillWebDataServiceObserverOnDBThread implementation.
125 void AutocompleteSyncBridge::AutofillEntriesChanged(
126 const AutofillChangeList& changes) {}
127
128 // static
129 std::string AutocompleteSyncBridge::KeyToTag(std::string storage_key) {
pavely 2016/11/21 22:54:19 Could you pass parameter as const std::string&.
Patrick Noland 2016/11/22 18:51:04 Not necessary since I'm removing KeyToTag entirely
130 std::string prefix(kAutocompleteEntryNamespaceTag);
131 return prefix + storage_key;
132 }
133
134 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698