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

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

Issue 2598113002: [Sync] Use a proto to generate AutofillSyncStorageKey's storage keys. (Closed)
Patch Set: Rebased and updated for 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 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 9b8e201d66b8f6db43b0ee61bcb5b259d692d5a2..37ce4094973f0e451238e6d824796d9e410c9aa3 100644
--- a/components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc
+++ b/components/autofill/core/browser/webdata/autocomplete_sync_bridge.cc
@@ -5,10 +5,13 @@
#include "components/autofill/core/browser/webdata/autocomplete_sync_bridge.h"
#include <unordered_set>
+#include <utility>
+#include <vector>
#include "base/bind.h"
#include "base/memory/ptr_util.h"
#include "base/strings/utf_string_conversions.h"
+#include "components/autofill/core/browser/proto/autofill_sync.pb.h"
#include "components/autofill/core/browser/webdata/autofill_metadata_change_list.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/browser/webdata/autofill_webdata_backend.h"
@@ -19,9 +22,12 @@
#include "components/sync/model/sync_error.h"
#include "net/base/escape.h"
+namespace autofill {
+
namespace {
const char kAutocompleteEntryNamespaceTag[] = "autofill_entry|";
+const char kAutocompleteTagDelimiter[] = "|";
void* UserDataKey() {
// Use the address of a static that COMDAT folding won't ever collide
@@ -31,7 +37,7 @@ void* UserDataKey() {
}
std::unique_ptr<syncer::EntityData> CreateEntityData(
- const autofill::AutofillEntry& entry) {
+ const AutofillEntry& entry) {
auto entity_data = base::MakeUnique<syncer::EntityData>();
entity_data->non_unique_name = base::UTF16ToUTF8(entry.key().name());
sync_pb::AutofillSpecifics* autofill =
@@ -44,9 +50,20 @@ std::unique_ptr<syncer::EntityData> CreateEntityData(
return entity_data;
}
-} // namespace
+std::string GetStorageKeyFromStrings(const std::string& name,
Mathieu 2017/01/06 01:51:29 How about BuildSerializedStorageKey?
skym 2017/01/06 18:29:04 Done.
+ const std::string& value) {
+ AutofillSyncStorageKey proto;
+ proto.set_name(name);
+ proto.set_value(value);
+ return proto.SerializeAsString();
+}
-namespace autofill {
+std::string GetStorageKeyFromModel(const AutofillKey& key) {
+ return GetStorageKeyFromStrings(base::UTF16ToUTF8(key.name()),
+ base::UTF16ToUTF8(key.value()));
+}
+
+} // namespace
// static
void AutocompleteSyncBridge::CreateForWebDataServiceAndBackend(
@@ -117,7 +134,7 @@ void AutocompleteSyncBridge::AutocompleteSyncBridge::GetData(
std::vector<AutofillEntry> entries;
GetAutofillTable()->GetAllAutofillEntries(&entries);
for (const AutofillEntry& entry : entries) {
- std::string key = GetStorageKeyFromAutofillEntry(entry);
+ std::string key = GetStorageKeyFromModel(entry.key());
if (keys_set.find(key) != keys_set.end()) {
batch->Put(key, CreateEntityData(entry));
}
@@ -131,7 +148,7 @@ void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
std::vector<AutofillEntry> entries;
GetAutofillTable()->GetAllAutofillEntries(&entries);
for (const AutofillEntry& entry : entries) {
- batch->Put(GetStorageKeyFromAutofillEntry(entry), CreateEntityData(entry));
+ batch->Put(GetStorageKeyFromModel(entry.key()), CreateEntityData(entry));
}
callback.Run(syncer::SyncError(), std::move(batch));
}
@@ -139,18 +156,18 @@ void AutocompleteSyncBridge::GetAllData(DataCallback callback) {
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());
- std::string prefix(kAutocompleteEntryNamespaceTag);
- return prefix + storage_key;
+ return std::string(kAutocompleteEntryNamespaceTag) +
+ net::EscapePath(specifics.name()) +
+ std::string(kAutocompleteTagDelimiter) +
+ net::EscapePath(specifics.value());
}
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());
+ return GetStorageKeyFromStrings(specifics.name(), specifics.value());
}
// AutofillWebDataServiceObserverOnDBThread implementation.
@@ -178,16 +195,4 @@ AutofillTable* AutocompleteSyncBridge::GetAutofillTable() const {
return AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase());
}
-std::string AutocompleteSyncBridge::GetStorageKeyFromAutofillEntry(
- const autofill::AutofillEntry& entry) {
- return FormatStorageKey(base::UTF16ToUTF8(entry.key().name()),
- base::UTF16ToUTF8(entry.key().value()));
-}
-
-// static
-std::string AutocompleteSyncBridge::FormatStorageKey(const std::string& name,
- const std::string& value) {
- return net::EscapePath(name) + "|" + net::EscapePath(value);
-}
-
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698