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

Unified 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 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
new file mode 100644
index 0000000000000000000000000000000000000000..1a8f69a68005d2933ac32412e4f1aa00c44cb1c5
--- /dev/null
+++ b/components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc
@@ -0,0 +1,134 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
maxbogue 2016/11/18 22:22:35 line below
Patrick Noland 2016/11/22 18:51:04 Done.
+#include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h"
+
+#include "base/bind.h"
+#include "base/memory/ptr_util.h"
+#include "components/autofill/core/browser/webdata/autofill_table.h"
+#include "components/autofill/core/browser/webdata/autofill_webdata_backend.h"
+#include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
+#include "components/sync/model/entity_data.h"
+#include "components/sync/model/model_type_change_processor.h"
+#include "components/sync/model/sync_error.h"
+#include "components/sync/model_impl/accumulating_metadata_change_list.h"
+
maxbogue 2016/11/18 22:22:35 no blank line; it's all one section.
Patrick Noland 2016/11/22 18:51:04 Done.
+#include "net/base/escape.h"
+
+namespace {
maxbogue 2016/11/18 22:22:35 Add line below.
Patrick Noland 2016/11/22 18:51:04 Done.
+void* UserDataKey() {
+ // Use the address of a static that COMDAT folding won't ever collide
+ // with something else.
+ static int user_data_key = 0;
+ return reinterpret_cast<void*>(&user_data_key);
+}
+
+const std::string FormatStorageKey(const std::string name,
+ const std::string value) {
+ return net::EscapePath(name) + "|" + net::EscapePath(value);
+}
+} // namespace
maxbogue 2016/11/18 22:22:35 Add line above.
Patrick Noland 2016/11/22 18:51:04 Done.
+
+namespace autofill {
+
+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.
+
+// static
+void AutocompleteSyncBridge::CreateForWebDataServiceAndBackend(
+ AutofillWebDataService* web_data_service,
+ AutofillWebDataBackend* web_data_backend) {
+ web_data_service->GetDBUserData()->SetUserData(
+ UserDataKey(),
+ new AutocompleteSyncBridge(
+ web_data_backend,
+ base::Bind(&syncer::ModelTypeChangeProcessor::Create)));
+}
+
+// static
+AutocompleteSyncBridge* AutocompleteSyncBridge::FromWebDataService(
+ AutofillWebDataService* web_data_service) {
+ return static_cast<AutocompleteSyncBridge*>(
+ web_data_service->GetDBUserData()->GetUserData(UserDataKey()));
+}
+
+AutocompleteSyncBridge::AutocompleteSyncBridge(
+ AutofillWebDataBackend* backend,
+ const ChangeProcessorFactory& change_processor_factory)
+ : ModelTypeSyncBridge(change_processor_factory, syncer::AUTOFILL),
+ web_data_backend_(backend),
+ scoped_observer_(this) {
+ DCHECK(web_data_backend_);
+
+ scoped_observer_.Add(web_data_backend_);
+}
+
+AutocompleteSyncBridge::~AutocompleteSyncBridge() {
+ DCHECK(CalledOnValidThread());
+}
+
+// syncer::ModelTypeService implementation.
+std::unique_ptr<syncer::MetadataChangeList>
+AutocompleteSyncBridge::CreateMetadataChangeList() {
+ NOTIMPLEMENTED();
+ 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.
+}
+
+syncer::SyncError AutocompleteSyncBridge::MergeSyncData(
+ std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
+ syncer::EntityDataMap entity_data_map) {
+ DCHECK(CalledOnValidThread());
+ NOTIMPLEMENTED();
+ return syncer::SyncError();
+}
+
+syncer::SyncError AutocompleteSyncBridge::ApplySyncChanges(
+ std::unique_ptr<syncer::MetadataChangeList> metadata_change_list,
+ syncer::EntityChangeList entity_changes) {
+ NOTIMPLEMENTED();
+ return syncer::SyncError();
+}
+void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData(
+ StorageKeyList storage_keys,
+ DataCallback callback) {
+ NOTIMPLEMENTED();
+}
+
+void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
+ NOTIMPLEMENTED();
+}
+
+std::string AutocompleteSyncBridge::GetClientTag(
+ const syncer::EntityData& entity_data) {
+ DCHECK(entity_data.specifics.has_autofill());
+
+ const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill();
+ std::string storage_key =
+ FormatStorageKey(specifics.name(), specifics.value());
+ 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.
+}
+
+std::string AutocompleteSyncBridge::GetStorageKey(
+ const syncer::EntityData& entity_data) {
+ DCHECK(entity_data.specifics.has_autofill());
+
+ const sync_pb::AutofillSpecifics specifics = entity_data.specifics.autofill();
+ return FormatStorageKey(specifics.name(), specifics.value());
+}
+
+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.
+ const syncer::EntityData& local_data,
+ const syncer::EntityData& remote_data) const {
+ return syncer::ConflictResolution::UseLocal();
+}
+
+// AutofillWebDataServiceObserverOnDBThread implementation.
+void AutocompleteSyncBridge::AutofillEntriesChanged(
+ const AutofillChangeList& changes) {}
+
+// static
+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
+ std::string prefix(kAutocompleteEntryNamespaceTag);
+ return prefix + storage_key;
+}
+
+} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698