OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/autofill_profile.h" | 5 #include "chrome/browser/autofill/autofill_profile.h" |
6 | 6 |
| 7 #include <algorithm> |
7 #include <vector> | 8 #include <vector> |
8 | 9 |
9 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
10 #include "base/stl_util-inl.h" | 11 #include "base/stl_util-inl.h" |
11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
12 #include "chrome/browser/autofill/address.h" | 13 #include "chrome/browser/autofill/address.h" |
13 #include "chrome/browser/autofill/autofill_manager.h" | 14 #include "chrome/browser/autofill/autofill_manager.h" |
14 #include "chrome/browser/autofill/contact_info.h" | 15 #include "chrome/browser/autofill/contact_info.h" |
15 #include "chrome/browser/autofill/fax_number.h" | 16 #include "chrome/browser/autofill/fax_number.h" |
16 #include "chrome/browser/autofill/home_address.h" | 17 #include "chrome/browser/autofill/home_address.h" |
(...skipping 28 matching lines...) Expand all Loading... |
45 } | 46 } |
46 | 47 |
47 AutoFillProfile::~AutoFillProfile() { | 48 AutoFillProfile::~AutoFillProfile() { |
48 STLDeleteContainerPairSecondPointers(personal_info_.begin(), | 49 STLDeleteContainerPairSecondPointers(personal_info_.begin(), |
49 personal_info_.end()); | 50 personal_info_.end()); |
50 } | 51 } |
51 | 52 |
52 void AutoFillProfile::GetPossibleFieldTypes( | 53 void AutoFillProfile::GetPossibleFieldTypes( |
53 const string16& text, | 54 const string16& text, |
54 FieldTypeSet* possible_types) const { | 55 FieldTypeSet* possible_types) const { |
55 FormGroupMap::const_iterator iter; | 56 for (FormGroupMap::const_iterator iter = personal_info_.begin(); |
56 for (iter = personal_info_.begin(); iter != personal_info_.end(); ++iter) { | 57 iter != personal_info_.end(); ++iter) { |
57 FormGroup* data = iter->second; | 58 FormGroup* data = iter->second; |
58 DCHECK(data != NULL); | 59 DCHECK(data != NULL); |
59 if (data != NULL) | 60 data->GetPossibleFieldTypes(text, possible_types); |
60 data->GetPossibleFieldTypes(text, possible_types); | |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
| 64 void AutoFillProfile::GetAvailableFieldTypes( |
| 65 FieldTypeSet* available_types) const { |
| 66 for (FormGroupMap::const_iterator iter = personal_info_.begin(); |
| 67 iter != personal_info_.end(); ++iter) { |
| 68 FormGroup* data = iter->second; |
| 69 DCHECK(data != NULL); |
| 70 data->GetAvailableFieldTypes(available_types); |
| 71 } |
| 72 } |
| 73 |
64 string16 AutoFillProfile::GetFieldText(const AutoFillType& type) const { | 74 string16 AutoFillProfile::GetFieldText(const AutoFillType& type) const { |
65 AutoFillType return_type = type; | 75 AutoFillType return_type = type; |
66 | 76 |
67 // When billing information is requested from the profile we map to the | 77 // When billing information is requested from the profile we map to the |
68 // home address equivalents. This indicates the address information within | 78 // home address equivalents. This indicates the address information within |
69 // this profile is being used to fill billing fields in the form. | 79 // this profile is being used to fill billing fields in the form. |
70 switch (type.field_type()) { | 80 switch (type.field_type()) { |
71 case ADDRESS_BILLING_LINE1: | 81 case ADDRESS_BILLING_LINE1: |
72 return_type = AutoFillType(ADDRESS_HOME_LINE1); | 82 return_type = AutoFillType(ADDRESS_HOME_LINE1); |
73 break; | 83 break; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 FormGroupMap::const_iterator iter; | 151 FormGroupMap::const_iterator iter; |
142 for (iter = personal_info_.begin(); iter != personal_info_.end(); ++iter) { | 152 for (iter = personal_info_.begin(); iter != personal_info_.end(); ++iter) { |
143 if (profile->personal_info_.count(iter->first)) | 153 if (profile->personal_info_.count(iter->first)) |
144 delete profile->personal_info_[iter->first]; | 154 delete profile->personal_info_[iter->first]; |
145 profile->personal_info_[iter->first] = iter->second->Clone(); | 155 profile->personal_info_[iter->first] = iter->second->Clone(); |
146 } | 156 } |
147 | 157 |
148 return profile; | 158 return profile; |
149 } | 159 } |
150 | 160 |
| 161 bool AutoFillProfile::IsSubsetOf(const AutoFillProfile& profile) const { |
| 162 FieldTypeSet types; |
| 163 GetAvailableFieldTypes(&types); |
| 164 |
| 165 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end(); |
| 166 ++iter) { |
| 167 AutoFillType type(*iter); |
| 168 if (GetFieldText(type) != profile.GetFieldText(type)) |
| 169 return false; |
| 170 } |
| 171 |
| 172 return true; |
| 173 } |
| 174 |
| 175 bool AutoFillProfile::IntersectionOfTypesHasEqualValues( |
| 176 const AutoFillProfile& profile) const { |
| 177 FieldTypeSet a, b, intersection; |
| 178 GetAvailableFieldTypes(&a); |
| 179 profile.GetAvailableFieldTypes(&b); |
| 180 std::set_intersection(a.begin(), a.end(), |
| 181 b.begin(), b.end(), |
| 182 std::inserter(intersection, intersection.begin())); |
| 183 |
| 184 // An empty intersection can't have equal values. |
| 185 if (intersection.empty()) |
| 186 return false; |
| 187 |
| 188 for (FieldTypeSet::const_iterator iter = intersection.begin(); |
| 189 iter != intersection.end(); ++iter) { |
| 190 AutoFillType type(*iter); |
| 191 if (GetFieldText(type) != profile.GetFieldText(type)) |
| 192 return false; |
| 193 } |
| 194 |
| 195 return true; |
| 196 } |
| 197 |
| 198 void AutoFillProfile::MergeWith(const AutoFillProfile& profile) { |
| 199 FieldTypeSet a, b, intersection; |
| 200 GetAvailableFieldTypes(&a); |
| 201 profile.GetAvailableFieldTypes(&b); |
| 202 std::set_difference(b.begin(), b.end(), |
| 203 a.begin(), a.end(), |
| 204 std::inserter(intersection, intersection.begin())); |
| 205 |
| 206 for (FieldTypeSet::const_iterator iter = intersection.begin(); |
| 207 iter != intersection.end(); ++iter) { |
| 208 AutoFillType type(*iter); |
| 209 SetInfo(type, profile.GetFieldText(type)); |
| 210 } |
| 211 } |
| 212 |
151 string16 AutoFillProfile::PreviewSummary() const { | 213 string16 AutoFillProfile::PreviewSummary() const { |
152 // Fetch the components of the summary string. Any or all of these | 214 // Fetch the components of the summary string. Any or all of these |
153 // may be an empty string. | 215 // may be an empty string. |
154 string16 first_name = GetFieldText(AutoFillType(NAME_FIRST)); | 216 string16 first_name = GetFieldText(AutoFillType(NAME_FIRST)); |
155 string16 last_name = GetFieldText(AutoFillType(NAME_LAST)); | 217 string16 last_name = GetFieldText(AutoFillType(NAME_LAST)); |
156 string16 address = GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)); | 218 string16 address = GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)); |
157 | 219 |
158 // String separators depend (below) on the existence of the various fields. | 220 // String separators depend (below) on the existence of the various fields. |
159 bool have_first_name = first_name.length() > 0; | 221 bool have_first_name = first_name.length() > 0; |
160 bool have_last_name = last_name.length() > 0; | 222 bool have_last_name = last_name.length() > 0; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))) | 336 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP))) |
275 << " " | 337 << " " |
276 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))) | 338 << UTF16ToUTF8(profile.GetFieldText(AutoFillType(ADDRESS_HOME_COUNTRY))) |
277 << " " | 339 << " " |
278 << UTF16ToUTF8(profile.GetFieldText(AutoFillType( | 340 << UTF16ToUTF8(profile.GetFieldText(AutoFillType( |
279 PHONE_HOME_WHOLE_NUMBER))) | 341 PHONE_HOME_WHOLE_NUMBER))) |
280 << " " | 342 << " " |
281 << UTF16ToUTF8(profile.GetFieldText(AutoFillType( | 343 << UTF16ToUTF8(profile.GetFieldText(AutoFillType( |
282 PHONE_FAX_WHOLE_NUMBER))); | 344 PHONE_FAX_WHOLE_NUMBER))); |
283 } | 345 } |
OLD | NEW |