| OLD | NEW |
| 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 "components/autofill/browser/phone_number.h" | 5 #include "components/autofill/browser/phone_number.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 string16 prefix = number.substr(kPrefixOffset, kPrefixLength); | 162 string16 prefix = number.substr(kPrefixOffset, kPrefixLength); |
| 163 string16 suffix = number.substr(kSuffixOffset, kSuffixLength); | 163 string16 suffix = number.substr(kSuffixOffset, kSuffixLength); |
| 164 if (text == prefix || text == suffix) | 164 if (text == prefix || text == suffix) |
| 165 matching_types->insert(PHONE_HOME_NUMBER); | 165 matching_types->insert(PHONE_HOME_NUMBER); |
| 166 } | 166 } |
| 167 | 167 |
| 168 string16 whole_number = GetInfo(PHONE_HOME_WHOLE_NUMBER, app_locale); | 168 string16 whole_number = GetInfo(PHONE_HOME_WHOLE_NUMBER, app_locale); |
| 169 if (!whole_number.empty()) { | 169 if (!whole_number.empty()) { |
| 170 string16 normalized_number = | 170 string16 normalized_number = |
| 171 autofill_i18n::NormalizePhoneNumber(text, | 171 autofill_i18n::NormalizePhoneNumber(text, |
| 172 GetRegion(*profile_, app_locale)); | 172 GetRegion(*profile_, app_locale), |
| 173 app_locale); |
| 173 if (normalized_number == whole_number) | 174 if (normalized_number == whole_number) |
| 174 matching_types->insert(PHONE_HOME_WHOLE_NUMBER); | 175 matching_types->insert(PHONE_HOME_WHOLE_NUMBER); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 | 178 |
| 178 void PhoneNumber::UpdateCacheIfNeeded(const std::string& app_locale) const { | 179 void PhoneNumber::UpdateCacheIfNeeded(const std::string& app_locale) const { |
| 179 std::string region = GetRegion(*profile_, app_locale); | 180 std::string region = GetRegion(*profile_, app_locale); |
| 180 if (!number_.empty() && cached_parsed_phone_.region() != region) | 181 if (!number_.empty() && cached_parsed_phone_.region() != region) |
| 181 cached_parsed_phone_ = autofill_i18n::PhoneObject(number_, region); | 182 cached_parsed_phone_ = |
| 183 autofill_i18n::PhoneObject(number_, region, app_locale); |
| 182 } | 184 } |
| 183 | 185 |
| 184 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper() { | 186 PhoneNumber::PhoneCombineHelper::PhoneCombineHelper() { |
| 185 } | 187 } |
| 186 | 188 |
| 187 PhoneNumber::PhoneCombineHelper::~PhoneCombineHelper() { | 189 PhoneNumber::PhoneCombineHelper::~PhoneCombineHelper() { |
| 188 } | 190 } |
| 189 | 191 |
| 190 bool PhoneNumber::PhoneCombineHelper::SetInfo(AutofillFieldType field_type, | 192 bool PhoneNumber::PhoneCombineHelper::SetInfo(AutofillFieldType field_type, |
| 191 const string16& value) { | 193 const string16& value) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 string16* value) { | 225 string16* value) { |
| 224 if (IsEmpty()) | 226 if (IsEmpty()) |
| 225 return false; | 227 return false; |
| 226 | 228 |
| 227 if (!whole_number_.empty()) { | 229 if (!whole_number_.empty()) { |
| 228 *value = whole_number_; | 230 *value = whole_number_; |
| 229 return true; | 231 return true; |
| 230 } | 232 } |
| 231 | 233 |
| 232 return autofill_i18n::ConstructPhoneNumber( | 234 return autofill_i18n::ConstructPhoneNumber( |
| 233 country_, city_, phone_, GetRegion(profile, app_locale), value); | 235 country_, city_, phone_, GetRegion(profile, app_locale), app_locale, |
| 236 value); |
| 234 } | 237 } |
| 235 | 238 |
| 236 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { | 239 bool PhoneNumber::PhoneCombineHelper::IsEmpty() const { |
| 237 return phone_.empty() && whole_number_.empty(); | 240 return phone_.empty() && whole_number_.empty(); |
| 238 } | 241 } |
| OLD | NEW |