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

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

Issue 2618483003: [Sync] Introduce ModelError for USS error handling. (Closed)
Patch Set: Address comments. Created 3 years, 11 months 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
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 <unordered_set> 7 #include <unordered_set>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "components/autofill/core/browser/proto/autofill_sync.pb.h" 14 #include "components/autofill/core/browser/proto/autofill_sync.pb.h"
15 #include "components/autofill/core/browser/webdata/autofill_metadata_change_list .h" 15 #include "components/autofill/core/browser/webdata/autofill_metadata_change_list .h"
16 #include "components/autofill/core/browser/webdata/autofill_table.h" 16 #include "components/autofill/core/browser/webdata/autofill_table.h"
17 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h" 17 #include "components/autofill/core/browser/webdata/autofill_webdata_backend.h"
18 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 18 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
19 #include "components/sync/model/entity_data.h" 19 #include "components/sync/model/entity_data.h"
20 #include "components/sync/model/model_type_change_processor.h" 20 #include "components/sync/model/model_type_change_processor.h"
21 #include "components/sync/model/mutable_data_batch.h" 21 #include "components/sync/model/mutable_data_batch.h"
22 #include "components/sync/model/sync_error.h"
23 #include "net/base/escape.h" 22 #include "net/base/escape.h"
24 23
25 namespace autofill { 24 namespace autofill {
26 25
27 namespace { 26 namespace {
28 27
29 const char kAutocompleteEntryNamespaceTag[] = "autofill_entry|"; 28 const char kAutocompleteEntryNamespaceTag[] = "autofill_entry|";
30 const char kAutocompleteTagDelimiter[] = "|"; 29 const char kAutocompleteTagDelimiter[] = "|";
31 30
32 void* UserDataKey() { 31 void* UserDataKey() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 DCHECK(thread_checker_.CalledOnValidThread()); 97 DCHECK(thread_checker_.CalledOnValidThread());
99 } 98 }
100 99
101 std::unique_ptr<syncer::MetadataChangeList> 100 std::unique_ptr<syncer::MetadataChangeList>
102 AutocompleteSyncBridge::CreateMetadataChangeList() { 101 AutocompleteSyncBridge::CreateMetadataChangeList() {
103 DCHECK(thread_checker_.CalledOnValidThread()); 102 DCHECK(thread_checker_.CalledOnValidThread());
104 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(), 103 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(),
105 syncer::AUTOFILL); 104 syncer::AUTOFILL);
106 } 105 }
107 106
108 syncer::SyncError AutocompleteSyncBridge::MergeSyncData( 107 syncer::ModelError AutocompleteSyncBridge::MergeSyncData(
109 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, 108 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
110 syncer::EntityDataMap entity_data_map) { 109 syncer::EntityDataMap entity_data_map) {
111 DCHECK(thread_checker_.CalledOnValidThread()); 110 DCHECK(thread_checker_.CalledOnValidThread());
112 NOTIMPLEMENTED(); 111 NOTIMPLEMENTED();
113 return syncer::SyncError(); 112 return syncer::ModelError();
114 } 113 }
115 114
116 syncer::SyncError AutocompleteSyncBridge::ApplySyncChanges( 115 syncer::ModelError AutocompleteSyncBridge::ApplySyncChanges(
117 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, 116 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
118 syncer::EntityChangeList entity_changes) { 117 syncer::EntityChangeList entity_changes) {
119 DCHECK(thread_checker_.CalledOnValidThread()); 118 DCHECK(thread_checker_.CalledOnValidThread());
120 NOTIMPLEMENTED(); 119 NOTIMPLEMENTED();
121 return syncer::SyncError(); 120 return syncer::ModelError();
122 } 121 }
123 122
124 void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData( 123 void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData(
125 StorageKeyList storage_keys, 124 StorageKeyList storage_keys,
126 DataCallback callback) { 125 DataCallback callback) {
127 DCHECK(thread_checker_.CalledOnValidThread()); 126 DCHECK(thread_checker_.CalledOnValidThread());
127 std::vector<AutofillEntry> entries;
128 if (!GetAutofillTable()->GetAllAutofillEntries(&entries)) {
129 change_processor()->ReportError(FROM_HERE,
130 "Failed to load entries from table.");
131 return;
132 }
133
128 std::unordered_set<std::string> keys_set; 134 std::unordered_set<std::string> keys_set;
129 for (const auto& key : storage_keys) { 135 for (const auto& key : storage_keys) {
130 keys_set.insert(key); 136 keys_set.insert(key);
131 } 137 }
132 138
133 auto batch = base::MakeUnique<syncer::MutableDataBatch>(); 139 auto batch = base::MakeUnique<syncer::MutableDataBatch>();
134 std::vector<AutofillEntry> entries;
135 GetAutofillTable()->GetAllAutofillEntries(&entries);
136 for (const AutofillEntry& entry : entries) { 140 for (const AutofillEntry& entry : entries) {
137 std::string key = GetStorageKeyFromModel(entry.key()); 141 std::string key = GetStorageKeyFromModel(entry.key());
138 if (keys_set.find(key) != keys_set.end()) { 142 if (keys_set.find(key) != keys_set.end()) {
139 batch->Put(key, CreateEntityData(entry)); 143 batch->Put(key, CreateEntityData(entry));
140 } 144 }
141 } 145 }
142 callback.Run(syncer::SyncError(), std::move(batch)); 146 callback.Run(std::move(batch));
143 } 147 }
144 148
145 void AutocompleteSyncBridge::GetAllData(DataCallback callback) { 149 void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
146 DCHECK(thread_checker_.CalledOnValidThread()); 150 DCHECK(thread_checker_.CalledOnValidThread());
151
152 std::vector<AutofillEntry> entries;
153 if (!GetAutofillTable()->GetAllAutofillEntries(&entries)) {
154 change_processor()->ReportError(FROM_HERE,
155 "Failed to load entries from table.");
156 return;
157 }
158
147 auto batch = base::MakeUnique<syncer::MutableDataBatch>(); 159 auto batch = base::MakeUnique<syncer::MutableDataBatch>();
148 std::vector<AutofillEntry> entries;
149 GetAutofillTable()->GetAllAutofillEntries(&entries);
150 for (const AutofillEntry& entry : entries) { 160 for (const AutofillEntry& entry : entries) {
151 batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry)); 161 batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry));
152 } 162 }
153 callback.Run(syncer::SyncError(), std::move(batch)); 163 callback.Run(std::move(batch));
154 } 164 }
155 165
156 std::string AutocompleteSyncBridge::GetClientTag( 166 std::string AutocompleteSyncBridge::GetClientTag(
157 const syncer::EntityData& entity_data) { 167 const syncer::EntityData& entity_data) {
158 DCHECK(entity_data.specifics.has_autofill()); 168 DCHECK(entity_data.specifics.has_autofill());
159 const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill(); 169 const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill();
160 return std::string(kAutocompleteEntryNamespaceTag) + 170 return std::string(kAutocompleteEntryNamespaceTag) +
161 net::EscapePath(specifics.name()) + 171 net::EscapePath(specifics.name()) +
162 std::string(kAutocompleteTagDelimiter) + 172 std::string(kAutocompleteTagDelimiter) +
163 net::EscapePath(specifics.value()); 173 net::EscapePath(specifics.value());
(...skipping 25 matching lines...) Expand all
189 date_last_used = base::Time::FromInternalValue(*timestamps.rbegin()); 199 date_last_used = base::Time::FromInternalValue(*timestamps.rbegin());
190 } 200 }
191 return AutofillEntry(key, date_created, date_last_used); 201 return AutofillEntry(key, date_created, date_last_used);
192 } 202 }
193 203
194 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { 204 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const {
195 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); 205 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase());
196 } 206 }
197 207
198 } // namespace autofill 208 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698