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

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: Fix other iOS test file that I thought was the first one. 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_error.h"
20 #include "components/sync/model/model_type_change_processor.h" 21 #include "components/sync/model/model_type_change_processor.h"
21 #include "components/sync/model/mutable_data_batch.h" 22 #include "components/sync/model/mutable_data_batch.h"
22 #include "components/sync/model/sync_error.h"
23 #include "net/base/escape.h" 23 #include "net/base/escape.h"
24 24
25 namespace autofill { 25 namespace autofill {
26 26
27 namespace { 27 namespace {
28 28
29 const char kAutocompleteEntryNamespaceTag[] = "autofill_entry|"; 29 const char kAutocompleteEntryNamespaceTag[] = "autofill_entry|";
30 const char kAutocompleteTagDelimiter[] = "|"; 30 const char kAutocompleteTagDelimiter[] = "|";
31 31
32 void* UserDataKey() { 32 void* UserDataKey() {
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 DCHECK(thread_checker_.CalledOnValidThread()); 98 DCHECK(thread_checker_.CalledOnValidThread());
99 } 99 }
100 100
101 std::unique_ptr<syncer::MetadataChangeList> 101 std::unique_ptr<syncer::MetadataChangeList>
102 AutocompleteSyncBridge::CreateMetadataChangeList() { 102 AutocompleteSyncBridge::CreateMetadataChangeList() {
103 DCHECK(thread_checker_.CalledOnValidThread()); 103 DCHECK(thread_checker_.CalledOnValidThread());
104 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(), 104 return base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(),
105 syncer::AUTOFILL); 105 syncer::AUTOFILL);
106 } 106 }
107 107
108 syncer::SyncError AutocompleteSyncBridge::MergeSyncData( 108 syncer::ModelError AutocompleteSyncBridge::MergeSyncData(
109 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, 109 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
110 syncer::EntityDataMap entity_data_map) { 110 syncer::EntityDataMap entity_data_map) {
111 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
112 NOTIMPLEMENTED(); 112 NOTIMPLEMENTED();
113 return syncer::SyncError(); 113 return syncer::ModelError();
114 } 114 }
115 115
116 syncer::SyncError AutocompleteSyncBridge::ApplySyncChanges( 116 syncer::ModelError AutocompleteSyncBridge::ApplySyncChanges(
117 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list, 117 std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
118 syncer::EntityChangeList entity_changes) { 118 syncer::EntityChangeList entity_changes) {
119 DCHECK(thread_checker_.CalledOnValidThread()); 119 DCHECK(thread_checker_.CalledOnValidThread());
120 NOTIMPLEMENTED(); 120 NOTIMPLEMENTED();
121 return syncer::SyncError(); 121 return syncer::ModelError();
122 } 122 }
123 123
124 void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData( 124 void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData(
125 StorageKeyList storage_keys, 125 StorageKeyList storage_keys,
126 DataCallback callback) { 126 DataCallback callback) {
127 DCHECK(thread_checker_.CalledOnValidThread()); 127 DCHECK(thread_checker_.CalledOnValidThread());
128 std::unordered_set<std::string> keys_set; 128 std::unordered_set<std::string> keys_set;
129 for (const auto& key : storage_keys) { 129 for (const auto& key : storage_keys) {
skym 2017/01/09 18:20:28 Might as well only make this after we avoid the er
maxbogue 2017/01/09 21:29:33 Done.
130 keys_set.insert(key); 130 keys_set.insert(key);
131 } 131 }
132 132
133 std::vector<AutofillEntry> entries;
134 if (!GetAutofillTable()->GetAllAutofillEntries(&entries)) {
skym 2017/01/09 18:20:27 I see you added the logic here but not the unit te
maxbogue 2017/01/09 21:29:33 Taking you up on your offline offer to add them yo
135 change_processor()->ReportError(FROM_HERE,
136 "Failed to load entries from table.");
137 return;
138 }
139
133 auto batch = base::MakeUnique<syncer::MutableDataBatch>(); 140 auto batch = base::MakeUnique<syncer::MutableDataBatch>();
134 std::vector<AutofillEntry> entries;
135 GetAutofillTable()->GetAllAutofillEntries(&entries);
136 for (const AutofillEntry& entry : entries) { 141 for (const AutofillEntry& entry : entries) {
137 std::string key = GetStorageKeyFromModel(entry.key()); 142 std::string key = GetStorageKeyFromModel(entry.key());
138 if (keys_set.find(key) != keys_set.end()) { 143 if (keys_set.find(key) != keys_set.end()) {
139 batch->Put(key, CreateEntityData(entry)); 144 batch->Put(key, CreateEntityData(entry));
140 } 145 }
141 } 146 }
142 callback.Run(syncer::SyncError(), std::move(batch)); 147 callback.Run(std::move(batch));
143 } 148 }
144 149
145 void AutocompleteSyncBridge::GetAllData(DataCallback callback) { 150 void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
146 DCHECK(thread_checker_.CalledOnValidThread()); 151 DCHECK(thread_checker_.CalledOnValidThread());
152
153 std::vector<AutofillEntry> entries;
154 if (!GetAutofillTable()->GetAllAutofillEntries(&entries)) {
skym 2017/01/09 18:20:27 This is looking very repeated to above. You could
maxbogue 2017/01/09 21:29:33 Passing on this for now.
155 change_processor()->ReportError(FROM_HERE,
156 "Failed to load entries from table.");
157 return;
158 }
159
147 auto batch = base::MakeUnique<syncer::MutableDataBatch>(); 160 auto batch = base::MakeUnique<syncer::MutableDataBatch>();
148 std::vector<AutofillEntry> entries;
149 GetAutofillTable()->GetAllAutofillEntries(&entries);
150 for (const AutofillEntry& entry : entries) { 161 for (const AutofillEntry& entry : entries) {
151 batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry)); 162 batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry));
152 } 163 }
153 callback.Run(syncer::SyncError(), std::move(batch)); 164 callback.Run(std::move(batch));
154 } 165 }
155 166
156 std::string AutocompleteSyncBridge::GetClientTag( 167 std::string AutocompleteSyncBridge::GetClientTag(
157 const syncer::EntityData& entity_data) { 168 const syncer::EntityData& entity_data) {
158 DCHECK(entity_data.specifics.has_autofill()); 169 DCHECK(entity_data.specifics.has_autofill());
159 const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill(); 170 const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill();
160 return std::string(kAutocompleteEntryNamespaceTag) + 171 return std::string(kAutocompleteEntryNamespaceTag) +
161 net::EscapePath(specifics.name()) + 172 net::EscapePath(specifics.name()) +
162 std::string(kAutocompleteTagDelimiter) + 173 std::string(kAutocompleteTagDelimiter) +
163 net::EscapePath(specifics.value()); 174 net::EscapePath(specifics.value());
(...skipping 25 matching lines...) Expand all
189 date_last_used = base::Time::FromInternalValue(*timestamps.rbegin()); 200 date_last_used = base::Time::FromInternalValue(*timestamps.rbegin());
190 } 201 }
191 return AutofillEntry(key, date_created, date_last_used); 202 return AutofillEntry(key, date_created, date_last_used);
192 } 203 }
193 204
194 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const { 205 AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const {
195 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase()); 206 return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase());
196 } 207 }
197 208
198 } // namespace autofill 209 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698