Chromium Code Reviews| Index: components/payments/core/address_normalizer.cc |
| diff --git a/components/payments/core/address_normalizer.cc b/components/payments/core/address_normalizer.cc |
| index 3114c5a89229cfc2a60ca2e02ebaf7f9b13819c1..4850c8c37b11ed6801da29938138309d6cba615c 100644 |
| --- a/components/payments/core/address_normalizer.cc |
| +++ b/components/payments/core/address_normalizer.cc |
| @@ -22,6 +22,7 @@ |
| #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_data.h" |
| #include "third_party/libaddressinput/src/cpp/include/libaddressinput/source.h" |
| #include "third_party/libaddressinput/src/cpp/include/libaddressinput/storage.h" |
| +#include "third_party/libphonenumber/phonenumber_api.h" |
| namespace payments { |
| namespace { |
| @@ -29,6 +30,7 @@ namespace { |
| using ::autofill::AutofillProfile; |
| using ::i18n::addressinput::Source; |
| using ::i18n::addressinput::Storage; |
| +using ::i18n::phonenumbers::PhoneNumberUtil; |
| class AddressNormalizationRequest : public AddressNormalizer::Request { |
| public: |
| @@ -62,6 +64,9 @@ class AddressNormalizationRequest : public AddressNormalizer::Request { |
| return; |
| has_responded_ = true; |
| + // In either case, format the phone number. |
| + FormatPhoneNumber(); |
|
Mathieu
2017/04/11 18:53:31
is there a possibility we early return above and n
sebsg
2017/04/11 21:34:54
It should not, the first time this method is calle
|
| + |
| if (!success) { |
| delegate_->OnCouldNotNormalize(profile_); |
| return; |
| @@ -90,6 +95,23 @@ class AddressNormalizationRequest : public AddressNormalizer::Request { |
| } |
| private: |
| + void FormatPhoneNumber() { |
|
Mathieu
2017/04/11 18:53:31
Add a function comment, mentioning the format and
sebsg
2017/04/11 21:34:55
Done.
|
| + const std::string original_number = base::UTF16ToUTF8( |
| + profile_.GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER)); |
|
Mathieu
2017/04/11 18:53:31
GetRawInfo vs GetInfo? I seem to remember it matte
sebsg
2017/04/11 21:34:55
I changed it to GetInfo to be safe, but it seems l
|
| + i18n::phonenumbers::PhoneNumber parsed_number; |
| + PhoneNumberUtil* phone_number_util = PhoneNumberUtil::GetInstance(); |
| + if (phone_number_util->Parse(original_number, region_code_, |
| + &parsed_number) == |
| + PhoneNumberUtil::NO_PARSING_ERROR) { |
| + std::string formatted_number; |
| + phone_number_util->Format(parsed_number, |
| + PhoneNumberUtil::PhoneNumberFormat::E164, |
| + &formatted_number); |
| + profile_.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER, |
| + base::UTF8ToUTF16(formatted_number)); |
| + } |
| + } |
| + |
| AutofillProfile profile_; |
| std::string region_code_; |
| AddressNormalizer::Delegate* delegate_; |