Commit 117ee8b5 authored by rouslan's avatar rouslan Committed by Commit bot

Only UTF-8 sync tags and server ID for Wallet metadata.

Wallet address server ID is not valid UTF-8, so it cannot be used as a
sync tag or as metadata server ID. This patch base64 encodes the sync
tags and the server ID.

BUG=481595

Review URL: https://codereview.chromium.org/1220093003

Cr-Commit-Position: refs/heads/master@{#338407}
parent 0ffe2c1f
......@@ -160,7 +160,8 @@ class AutofillProfile : public AutofillDataModel {
language_code_ = language_code;
}
// Nonempty only when type() == SERVER_PROFILE.
// Nonempty only when type() == SERVER_PROFILE. base::kSHA1Length bytes long.
// Not necessarily valid UTF-8.
const std::string& server_id() const { return server_id_; }
// Creates an identifier and saves it as |server_id_|. Only used for
......
......@@ -4,6 +4,7 @@
#include "components/autofill/core/browser/webdata/autofill_wallet_metadata_syncable_service.h"
#include "base/base64.h"
#include "base/bind.h"
#include "base/containers/scoped_ptr_hash_map.h"
#include "base/location.h"
......@@ -74,8 +75,7 @@ void UndeleteMetadataIfExisting(
scoped_ptr<DataType> local_metadata = locals->take_and_erase(it);
changes_to_sync->push_back(syncer::SyncChange(
FROM_HERE, syncer::SyncChange::ACTION_ADD,
BuildSyncData(metadata_type, local_metadata->server_id(),
*local_metadata)));
BuildSyncData(metadata_type, server_id, *local_metadata)));
}
}
......@@ -192,6 +192,13 @@ bool MergeRemote(
return true;
}
template <typename DataType>
std::string GetServerId(const DataType& data) {
std::string server_id;
base::Base64Encode(data.server_id(), &server_id);
return server_id;
}
} // namespace
AutofillWalletMetadataSyncableService::
......@@ -333,7 +340,7 @@ void AutofillWalletMetadataSyncableService::AutofillProfileChanged(
if (sync_processor_ && change.data_model() &&
change.data_model()->record_type() != AutofillProfile::LOCAL_PROFILE) {
AutofillDataModelChanged(change.data_model()->server_id(),
AutofillDataModelChanged(GetServerId(*change.data_model()),
sync_pb::WalletMetadataSpecifics::ADDRESS,
*change.data_model());
}
......@@ -345,7 +352,7 @@ void AutofillWalletMetadataSyncableService::CreditCardChanged(
if (sync_processor_ && change.data_model() &&
change.data_model()->record_type() != CreditCard::LOCAL_CARD) {
AutofillDataModelChanged(change.data_model()->server_id(),
AutofillDataModelChanged(GetServerId(*change.data_model()),
sync_pb::WalletMetadataSpecifics::CARD,
*change.data_model());
}
......@@ -389,7 +396,7 @@ bool AutofillWalletMetadataSyncableService::GetLocalData(
AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase())
->GetServerProfiles(&profile_list.get());
while (!profile_list.empty()) {
profiles->add(profile_list.front()->server_id(),
profiles->add(GetServerId(*profile_list.front()),
make_scoped_ptr(profile_list.front()));
profile_list.weak_erase(profile_list.begin());
}
......@@ -398,7 +405,7 @@ bool AutofillWalletMetadataSyncableService::GetLocalData(
success &= AutofillTable::FromWebDatabase(web_data_backend_->GetDatabase())
->GetServerCreditCards(&card_list.get());
while (!card_list.empty()) {
cards->add(card_list.front()->server_id(),
cards->add(GetServerId(*card_list.front()),
make_scoped_ptr(card_list.front()));
card_list.weak_erase(card_list.begin());
}
......
......@@ -183,7 +183,7 @@ message WalletMetadataSpecifics {
// The type of the Wallet metadata.
optional Type type = 1;
// Unique ID string of the corresponding Wallet data.
// Base64 encoding of the unique ID string of the corresponding Wallet data.
// For Wallet cards, this value is server generated and opaque to Chrome.
// For Wallet addresses, this is a SHA1 hash of the following fields:
//
......@@ -198,9 +198,8 @@ message WalletMetadataSpecifics {
// - Zip code
// - Sorting code
// - Country
// - Phone numbers
//
// Finally, Chrome appends the address language code to the end of the hash.
// - Phone number
// - Language code
optional string id = 2;
// The number of times that this Wallet card or address was used.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment