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

Side by Side Diff: chrome/browser/autofill/phone_number_i18n.cc

Issue 6877130: These changes *are* for review :) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/autofill/phone_number_i18n.h" 5 #include "chrome/browser/autofill/phone_number_i18n.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/utf_string_conversions.h" 11 #include "base/utf_string_conversions.h"
12 #include "third_party/libphonenumber/cpp/src/phonenumberutil.h" 12 #include "third_party/libphonenumber/cpp/src/phonenumberutil.h"
13 #include "unicode/locid.h"
13 14
14 namespace { 15 namespace {
15 16
16 std::string SanitizeLocaleCode(const std::string& locale_code) { 17 std::string SanitizeLocaleCode(const std::string& locale_code) {
17 if (locale_code.length() == 2) 18 if (locale_code.length() == 2)
18 return locale_code; 19 return locale_code;
19 // Use USA for incomplete locales. 20 return std::string(icu::Locale::getDefault().getCountry());
20 return std::string("US");
21 } 21 }
22 22
23 i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat UtilsTypeToPhoneLibType( 23 i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat UtilsTypeToPhoneLibType(
24 autofill_i18n::FullPhoneFormat phone_format) { 24 autofill_i18n::FullPhoneFormat phone_format) {
25 switch (phone_format) { 25 switch (phone_format) {
26 case autofill_i18n::E164: 26 case autofill_i18n::E164:
27 return i18n::phonenumbers::PhoneNumberUtil::E164; 27 return i18n::phonenumbers::PhoneNumberUtil::E164;
28 case autofill_i18n::INTERNATIONAL: 28 case autofill_i18n::INTERNATIONAL:
29 return i18n::phonenumbers::PhoneNumberUtil::INTERNATIONAL; 29 return i18n::phonenumbers::PhoneNumberUtil::INTERNATIONAL;
30 case autofill_i18n::NATIONAL: 30 case autofill_i18n::NATIONAL:
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return false; 155 return false;
156 } 156 }
157 if (country_int) 157 if (country_int)
158 i18n_number.set_country_code(country_int); 158 i18n_number.set_country_code(country_int);
159 159
160 i18n::phonenumbers::PhoneNumberUtil::ValidationResult validation = 160 i18n::phonenumbers::PhoneNumberUtil::ValidationResult validation =
161 phone_util->IsPossibleNumberWithReason(i18n_number); 161 phone_util->IsPossibleNumberWithReason(i18n_number);
162 if (validation != i18n::phonenumbers::PhoneNumberUtil::IS_POSSIBLE) 162 if (validation != i18n::phonenumbers::PhoneNumberUtil::IS_POSSIBLE)
163 return false; 163 return false;
164 164
165 // This verifies that number has a valid area code (that in some cases could
166 // be empty) for parsed country code. Also verifies that this is a valid
167 // number (in US 1234567 is not valid, because numbers do not start with 1).
168 if (!phone_util->IsValidNumber(i18n_number))
169 return false;
170
165 std::string formatted_number; 171 std::string formatted_number;
166 172
167 phone_util->Format(i18n_number, UtilsTypeToPhoneLibType(phone_format), 173 phone_util->Format(i18n_number, UtilsTypeToPhoneLibType(phone_format),
168 &formatted_number); 174 &formatted_number);
169 *whole_number = UTF8ToUTF16(formatted_number); 175 *whole_number = UTF8ToUTF16(formatted_number);
170 return true; 176 return true;
171 } 177 }
172 178
173 string16 FormatPhone(const string16& phone, const std::string& locale, 179 string16 FormatPhone(const string16& phone, const std::string& locale,
174 FullPhoneFormat phone_format) { 180 FullPhoneFormat phone_format) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 239 }
234 240
235 bool PhoneNumbersMatch(const string16& number_a, 241 bool PhoneNumbersMatch(const string16& number_a,
236 const string16& number_b, 242 const string16& number_b,
237 const std::string& country_code) { 243 const std::string& country_code) {
238 return ComparePhones(number_a, number_b, country_code) == PHONES_EQUAL; 244 return ComparePhones(number_a, number_b, country_code) == PHONES_EQUAL;
239 } 245 }
240 246
241 } // namespace autofill_i18n 247 } // namespace autofill_i18n
242 248
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698