Commit c7806c5d authored by Oscar Johansson's avatar Oscar Johansson Committed by Commit Bot

Move TruncateUTF8 to util (components/autofill)

When building using jumbo, files gets merged and
functions with the same name may end up in the
same namespace and conflict. This happens for
the function TruncateUTF8.

This commit solves the issue by moving the function
to a shared util file.

Bug: 869381
Change-Id: Ia9f754138fb18aa9af575f7cd2f92bca4e8ea0c2
Reviewed-on: https://chromium-review.googlesource.com/1168497Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Commit-Queue: Oscar Johansson <oscarj@opera.com>
Cr-Commit-Position: refs/heads/master@{#581866}
parent f3e02276
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "components/autofill/core/browser/autofill_profile.h" #include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/field_types.h" #include "components/autofill/core/browser/field_types.h"
#include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/grit/components_scaled_resources.h" #include "components/grit/components_scaled_resources.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "third_party/icu/source/common/unicode/uscript.h" #include "third_party/icu/source/common/unicode/uscript.h"
...@@ -240,6 +241,13 @@ bool SplitCJKName(const std::vector<base::StringPiece16>& name_tokens, ...@@ -240,6 +241,13 @@ bool SplitCJKName(const std::vector<base::StringPiece16>& name_tokens,
} // namespace } // namespace
std::string TruncateUTF8(const std::string& data) {
std::string trimmed_value;
base::TruncateUTF8ToByteSize(data, AutofillTable::kMaxDataLength,
&trimmed_value);
return trimmed_value;
}
bool IsCreditCardExpirationType(ServerFieldType type) { bool IsCreditCardExpirationType(ServerFieldType type) {
return type == CREDIT_CARD_EXP_MONTH || return type == CREDIT_CARD_EXP_MONTH ||
type == CREDIT_CARD_EXP_2_DIGIT_YEAR || type == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
......
...@@ -23,6 +23,10 @@ struct NameParts { ...@@ -23,6 +23,10 @@ struct NameParts {
base::string16 family; base::string16 family;
}; };
// Truncates a string to the nearest UTF-8 character that will leave
// the string less than or equal to the specified byte size.
std::string TruncateUTF8(const std::string& data);
bool IsCreditCardExpirationType(ServerFieldType type); bool IsCreditCardExpirationType(ServerFieldType type);
// Used to map Chrome card issuer networks to Payment Request API basic card // Used to map Chrome card issuer networks to Payment Request API basic card
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/guid.h" #include "base/guid.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_profile.h" #include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/country_names.h" #include "components/autofill/core/browser/country_names.h"
#include "components/autofill/core/browser/field_types.h" #include "components/autofill/core/browser/field_types.h"
...@@ -16,19 +17,13 @@ ...@@ -16,19 +17,13 @@
using base::UTF16ToUTF8; using base::UTF16ToUTF8;
using base::UTF8ToUTF16; using base::UTF8ToUTF16;
using autofill::data_util::TruncateUTF8;
using sync_pb::AutofillProfileSpecifics; using sync_pb::AutofillProfileSpecifics;
using syncer::EntityData; using syncer::EntityData;
namespace autofill { namespace autofill {
namespace { namespace {
std::string TruncateUTF8(const std::string& data) {
std::string trimmed_value;
base::TruncateUTF8ToByteSize(data, AutofillTable::kMaxDataLength,
&trimmed_value);
return trimmed_value;
}
bool IsAutofillProfileSpecificsValid( bool IsAutofillProfileSpecificsValid(
const AutofillProfileSpecifics& specifics) { const AutofillProfileSpecifics& specifics) {
return base::IsValidGUID(specifics.guid()); return base::IsValidGUID(specifics.guid());
......
...@@ -7,24 +7,19 @@ ...@@ -7,24 +7,19 @@
#include "base/base64.h" #include "base/base64.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/autofill/core/browser/autofill_data_util.h"
#include "components/autofill/core/browser/autofill_profile.h" #include "components/autofill/core/browser/autofill_profile.h"
#include "components/autofill/core/browser/credit_card.h" #include "components/autofill/core/browser/credit_card.h"
#include "components/autofill/core/browser/webdata/autofill_table.h" #include "components/autofill/core/browser/webdata/autofill_table.h"
#include "components/autofill/core/common/autofill_util.h" #include "components/autofill/core/common/autofill_util.h"
#include "components/sync/model/entity_data.h" #include "components/sync/model/entity_data.h"
using autofill::data_util::TruncateUTF8;
using sync_pb::AutofillWalletSpecifics; using sync_pb::AutofillWalletSpecifics;
using syncer::EntityData; using syncer::EntityData;
namespace autofill { namespace autofill {
namespace { namespace {
std::string TruncateUTF8(const std::string& data) {
std::string trimmed_value;
base::TruncateUTF8ToByteSize(data, AutofillTable::kMaxDataLength,
&trimmed_value);
return trimmed_value;
}
sync_pb::WalletMaskedCreditCard::WalletCardStatus LocalToServerStatus( sync_pb::WalletMaskedCreditCard::WalletCardStatus LocalToServerStatus(
const CreditCard& card) { const CreditCard& card) {
switch (card.GetServerStatus()) { switch (card.GetServerStatus()) {
......
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