OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/browser/autofill_profile.h" | 5 #include "components/autofill/core/browser/autofill_profile.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 #include <ostream> | 10 #include <ostream> |
11 #include <set> | 11 #include <set> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/guid.h" | 14 #include "base/guid.h" |
15 #include "base/i18n/case_conversion.h" | 15 #include "base/i18n/case_conversion.h" |
16 #include "base/i18n/char_iterator.h" | 16 #include "base/i18n/char_iterator.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/sha1.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversion_utils.h" | 20 #include "base/strings/utf_string_conversion_utils.h" |
20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
21 #include "components/autofill/core/browser/address.h" | 22 #include "components/autofill/core/browser/address.h" |
22 #include "components/autofill/core/browser/address_i18n.h" | 23 #include "components/autofill/core/browser/address_i18n.h" |
23 #include "components/autofill/core/browser/autofill_country.h" | 24 #include "components/autofill/core/browser/autofill_country.h" |
24 #include "components/autofill/core/browser/autofill_field.h" | 25 #include "components/autofill/core/browser/autofill_field.h" |
25 #include "components/autofill/core/browser/autofill_type.h" | 26 #include "components/autofill/core/browser/autofill_type.h" |
26 #include "components/autofill/core/browser/contact_info.h" | 27 #include "components/autofill/core/browser/contact_info.h" |
27 #include "components/autofill/core/browser/phone_number.h" | 28 #include "components/autofill/core/browser/phone_number.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 name_(1), | 261 name_(1), |
261 email_(1), | 262 email_(1), |
262 phone_number_(1, PhoneNumber(this)) { | 263 phone_number_(1, PhoneNumber(this)) { |
263 } | 264 } |
264 | 265 |
265 AutofillProfile::AutofillProfile(RecordType type, const std::string& server_id) | 266 AutofillProfile::AutofillProfile(RecordType type, const std::string& server_id) |
266 : AutofillDataModel(base::GenerateGUID(), std::string()), | 267 : AutofillDataModel(base::GenerateGUID(), std::string()), |
267 record_type_(type), | 268 record_type_(type), |
268 name_(1), | 269 name_(1), |
269 email_(1), | 270 email_(1), |
270 phone_number_(1, PhoneNumber(this)) { | 271 phone_number_(1, PhoneNumber(this)), |
| 272 server_id_(server_id) { |
271 DCHECK(type == SERVER_PROFILE); | 273 DCHECK(type == SERVER_PROFILE); |
272 } | 274 } |
273 | 275 |
274 AutofillProfile::AutofillProfile() | 276 AutofillProfile::AutofillProfile() |
275 : AutofillDataModel(base::GenerateGUID(), std::string()), | 277 : AutofillDataModel(base::GenerateGUID(), std::string()), |
276 record_type_(LOCAL_PROFILE), | 278 record_type_(LOCAL_PROFILE), |
277 name_(1), | 279 name_(1), |
278 email_(1), | 280 email_(1), |
279 phone_number_(1, PhoneNumber(this)) { | 281 phone_number_(1, PhoneNumber(this)) { |
280 } | 282 } |
(...skipping 23 matching lines...) Expand all Loading... |
304 email_ = profile.email_; | 306 email_ = profile.email_; |
305 company_ = profile.company_; | 307 company_ = profile.company_; |
306 phone_number_ = profile.phone_number_; | 308 phone_number_ = profile.phone_number_; |
307 | 309 |
308 for (size_t i = 0; i < phone_number_.size(); ++i) | 310 for (size_t i = 0; i < phone_number_.size(); ++i) |
309 phone_number_[i].set_profile(this); | 311 phone_number_[i].set_profile(this); |
310 | 312 |
311 address_ = profile.address_; | 313 address_ = profile.address_; |
312 set_language_code(profile.language_code()); | 314 set_language_code(profile.language_code()); |
313 | 315 |
| 316 server_id_ = profile.server_id(); |
| 317 |
314 return *this; | 318 return *this; |
315 } | 319 } |
316 | 320 |
317 void AutofillProfile::GetMatchingTypes( | 321 void AutofillProfile::GetMatchingTypes( |
318 const base::string16& text, | 322 const base::string16& text, |
319 const std::string& app_locale, | 323 const std::string& app_locale, |
320 ServerFieldTypeSet* matching_types) const { | 324 ServerFieldTypeSet* matching_types) const { |
321 FormGroupList info = FormGroups(); | 325 FormGroupList info = FormGroups(); |
322 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it) | 326 for (FormGroupList::const_iterator it = info.begin(); it != info.end(); ++it) |
323 (*it)->GetMatchingTypes(text, app_locale, matching_types); | 327 (*it)->GetMatchingTypes(text, app_locale, matching_types); |
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
817 (*labels)[profile_index] = label; | 821 (*labels)[profile_index] = label; |
818 } else { | 822 } else { |
819 // We have more than one profile with the same label, so add | 823 // We have more than one profile with the same label, so add |
820 // differentiating fields. | 824 // differentiating fields. |
821 CreateInferredLabelsHelper(profiles, it->second, fields_to_use, | 825 CreateInferredLabelsHelper(profiles, it->second, fields_to_use, |
822 minimal_fields_shown, app_locale, labels); | 826 minimal_fields_shown, app_locale, labels); |
823 } | 827 } |
824 } | 828 } |
825 } | 829 } |
826 | 830 |
| 831 void AutofillProfile::GenerateServerProfileIdentifier() { |
| 832 DCHECK_EQ(SERVER_PROFILE, record_type()); |
| 833 base::string16 contents = MultiString(*this, NAME_FIRST); |
| 834 contents.append(MultiString(*this, NAME_MIDDLE)); |
| 835 contents.append(MultiString(*this, NAME_LAST)); |
| 836 contents.append(MultiString(*this, EMAIL_ADDRESS)); |
| 837 contents.append(GetRawInfo(COMPANY_NAME)); |
| 838 contents.append(GetRawInfo(ADDRESS_HOME_STREET_ADDRESS)); |
| 839 contents.append(GetRawInfo(ADDRESS_HOME_DEPENDENT_LOCALITY)); |
| 840 contents.append(GetRawInfo(ADDRESS_HOME_CITY)); |
| 841 contents.append(GetRawInfo(ADDRESS_HOME_STATE)); |
| 842 contents.append(GetRawInfo(ADDRESS_HOME_ZIP)); |
| 843 contents.append(GetRawInfo(ADDRESS_HOME_SORTING_CODE)); |
| 844 contents.append(GetRawInfo(ADDRESS_HOME_COUNTRY)); |
| 845 contents.append(MultiString(*this, PHONE_HOME_WHOLE_NUMBER)); |
| 846 std::string contents_utf8 = UTF16ToUTF8(contents); |
| 847 contents_utf8.append(language_code()); |
| 848 server_id_ = base::SHA1HashString(contents_utf8); |
| 849 } |
| 850 |
827 // static | 851 // static |
828 base::string16 AutofillProfile::CanonicalizeProfileString( | 852 base::string16 AutofillProfile::CanonicalizeProfileString( |
829 const base::string16& str) { | 853 const base::string16& str) { |
830 base::string16 ret; | 854 base::string16 ret; |
831 ret.reserve(str.size()); | 855 ret.reserve(str.size()); |
832 | 856 |
833 bool previous_was_whitespace = false; | 857 bool previous_was_whitespace = false; |
834 | 858 |
835 // This algorithm isn't designed to be perfect, we could get arbitrarily | 859 // This algorithm isn't designed to be perfect, we could get arbitrarily |
836 // fancy here trying to canonicalize address lines. Instead, this is designed | 860 // fancy here trying to canonicalize address lines. Instead, this is designed |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) | 1179 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_SORTING_CODE)) |
1156 << " " | 1180 << " " |
1157 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) | 1181 << UTF16ToUTF8(profile.GetRawInfo(ADDRESS_HOME_COUNTRY)) |
1158 << " " | 1182 << " " |
1159 << profile.language_code() | 1183 << profile.language_code() |
1160 << " " | 1184 << " " |
1161 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); | 1185 << UTF16ToUTF8(MultiString(profile, PHONE_HOME_WHOLE_NUMBER)); |
1162 } | 1186 } |
1163 | 1187 |
1164 } // namespace autofill | 1188 } // namespace autofill |
OLD | NEW |