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

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 "chrome/browser/autofill/autofill_country.h"
12 #include "third_party/libphonenumber/cpp/src/phonenumberutil.h" 13 #include "third_party/libphonenumber/cpp/src/phonenumberutil.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 AutofillCountry::CountryCodeForLocale(
20 return std::string("US"); 21 AutofillCountry::ApplicationLocale());
21 } 22 }
22 23
23 i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat UtilsTypeToPhoneLibType( 24 i18n::phonenumbers::PhoneNumberUtil::PhoneNumberFormat UtilsTypeToPhoneLibType(
24 autofill_i18n::FullPhoneFormat phone_format) { 25 autofill_i18n::FullPhoneFormat phone_format) {
25 switch (phone_format) { 26 switch (phone_format) {
26 case autofill_i18n::E164: 27 case autofill_i18n::E164:
27 return i18n::phonenumbers::PhoneNumberUtil::E164; 28 return i18n::phonenumbers::PhoneNumberUtil::E164;
28 case autofill_i18n::INTERNATIONAL: 29 case autofill_i18n::INTERNATIONAL:
29 return i18n::phonenumbers::PhoneNumberUtil::INTERNATIONAL; 30 return i18n::phonenumbers::PhoneNumberUtil::INTERNATIONAL;
30 case autofill_i18n::NATIONAL: 31 case autofill_i18n::NATIONAL:
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 return false; 156 return false;
156 } 157 }
157 if (country_int) 158 if (country_int)
158 i18n_number.set_country_code(country_int); 159 i18n_number.set_country_code(country_int);
159 160
160 i18n::phonenumbers::PhoneNumberUtil::ValidationResult validation = 161 i18n::phonenumbers::PhoneNumberUtil::ValidationResult validation =
161 phone_util->IsPossibleNumberWithReason(i18n_number); 162 phone_util->IsPossibleNumberWithReason(i18n_number);
162 if (validation != i18n::phonenumbers::PhoneNumberUtil::IS_POSSIBLE) 163 if (validation != i18n::phonenumbers::PhoneNumberUtil::IS_POSSIBLE)
163 return false; 164 return false;
164 165
166 // This verifies that number has a valid area code (that in some cases could
167 // be empty) for parsed country code. Also verifies that this is a valid
168 // number (in US 1234567 is not valid, because numbers do not start with 1).
169 if (!phone_util->IsValidNumber(i18n_number))
170 return false;
171
165 std::string formatted_number; 172 std::string formatted_number;
166 173
167 phone_util->Format(i18n_number, UtilsTypeToPhoneLibType(phone_format), 174 phone_util->Format(i18n_number, UtilsTypeToPhoneLibType(phone_format),
168 &formatted_number); 175 &formatted_number);
169 *whole_number = UTF8ToUTF16(formatted_number); 176 *whole_number = UTF8ToUTF16(formatted_number);
170 return true; 177 return true;
171 } 178 }
172 179
173 string16 FormatPhone(const string16& phone, const std::string& locale, 180 string16 FormatPhone(const string16& phone, const std::string& locale,
174 FullPhoneFormat phone_format) { 181 FullPhoneFormat phone_format) {
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 } 240 }
234 241
235 bool PhoneNumbersMatch(const string16& number_a, 242 bool PhoneNumbersMatch(const string16& number_a,
236 const string16& number_b, 243 const string16& number_b,
237 const std::string& country_code) { 244 const std::string& country_code) {
238 return ComparePhones(number_a, number_b, country_code) == PHONES_EQUAL; 245 return ComparePhones(number_a, number_b, country_code) == PHONES_EQUAL;
239 } 246 }
240 247
241 } // namespace autofill_i18n 248 } // namespace autofill_i18n
242 249
OLDNEW
« no previous file with comments | « chrome/browser/autofill/phone_number.cc ('k') | chrome/browser/autofill/phone_number_i18n_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698