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

Unified Diff: components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc

Issue 2620783002: [sync] Handle local changes in AutocompleteSyncBridge (Closed)
Patch Set: rebase onto sky's changes 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc
diff --git a/components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc b/components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc
index 12702868ce18b6f1d878ccbdccc6db9bb03d10ec..621fe9e91dc39f56718d03cc8f8ce6605cefa4f2 100644
--- a/components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc
+++ b/components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc
@@ -293,6 +293,8 @@ AutocompleteSyncBridge::AutocompleteSyncBridge(
DCHECK(web_data_backend_);
scoped_observer_.Add(web_data_backend_);
+
+ LoadMetadata();
skym 2017/01/14 00:04:33 As far as I can tell, no unit tests check that thi
Patrick Noland 2017/01/17 22:59:55 Done.
}
AutocompleteSyncBridge::~AutocompleteSyncBridge() {
@@ -390,6 +392,62 @@ void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
callback.Run(std::move(batch));
}
+void AutocompleteSyncBridge::ActOnLocalChanges(
+ const AutofillChangeList& changes) {
+ if (!change_processor()->IsTrackingMetadata()) {
+ return;
+ }
+
+ std::unique_ptr<AutofillMetadataChangeList> change_list =
maxbogue 2017/01/14 00:39:02 auto mcl = base::MakeUnique... auto because MakeU
skym 2017/01/17 17:57:21 I'm not a huge fan of abbreviations. I'd prefer me
Patrick Noland 2017/01/17 22:59:55 Done. I also don't love abbreviations whose meanin
+ base::MakeUnique<AutofillMetadataChangeList>(GetAutofillTable(),
+ syncer::AUTOFILL);
+ for (const auto& change : changes) {
+ const std::string storage_key = GetStorageKeyFromModel(change.key());
+ switch (change.type()) {
+ case AutofillChange::ADD:
+ case AutofillChange::UPDATE: {
+ base::Time date_created, date_last_used;
+ bool success = GetAutofillTable()->GetAutofillTimestamps(
+ change.key().name(), change.key().value(), &date_created,
+ &date_last_used);
+ if (!success) {
+ change_processor()->ReportError(
+ FROM_HERE, "Failed reading autofill entry from WebDatabase.");
+ return;
+ }
+
+ AutofillEntry entry(change.key(), date_created, date_last_used);
skym 2017/01/14 00:04:33 If you're going to const the storage_key, might as
Patrick Noland 2017/01/17 22:59:55 Done.
+ std::unique_ptr<syncer::EntityData> entity_data =
skym 2017/01/14 00:04:33 I'd personally inline this, you're only saving a s
maxbogue 2017/01/14 00:39:02 +1
Patrick Noland 2017/01/17 22:59:55 Done.
+ CreateEntityData(entry);
+ change_processor()->Put(storage_key, std::move(entity_data),
+ change_list.get());
+ break;
+ }
+ case AutofillChange::REMOVE: {
+ change_processor()->Delete(storage_key, change_list.get());
+ break;
+ }
+ }
+ }
+
+ Optional<ModelError> error = change_list->TakeError();
+ if (error) {
+ change_processor()->ReportError(
skym 2017/01/14 00:04:33 You should give |error| (via error.value()) to Rep
maxbogue 2017/01/14 00:39:02 +1
Patrick Noland 2017/01/17 22:59:55 Done.
+ FROM_HERE, "Failed writing autofill metadata to WebDatabase.");
+ }
+}
+
+void AutocompleteSyncBridge::LoadMetadata() {
+ std::unique_ptr<syncer::MetadataBatch> batch =
skym 2017/01/14 00:04:33 auto!
Patrick Noland 2017/01/17 22:59:55 Done.
+ base::MakeUnique<syncer::MetadataBatch>();
+ if (!GetAutofillTable()->GetAllSyncMetadata(syncer::AUTOFILL, batch.get())) {
+ change_processor()->ReportError(
+ FROM_HERE, "Failed reading autofill metadata from WebDatabase.");
+ return;
+ }
+ change_processor()->OnMetadataLoaded(std::move(batch));
+}
+
std::string AutocompleteSyncBridge::GetClientTag(
const EntityData& entity_data) {
DCHECK(entity_data.specifics.has_autofill());
@@ -411,6 +469,7 @@ std::string AutocompleteSyncBridge::GetStorageKey(
void AutocompleteSyncBridge::AutofillEntriesChanged(
const AutofillChangeList& changes) {
DCHECK(thread_checker_.CalledOnValidThread());
+ ActOnLocalChanges(changes);
}
AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const {

Powered by Google App Engine
This is Rietveld 408576698