| 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 <algorithm> | 5 #include <algorithm> |
| 6 | 6 |
| 7 #include "chrome/browser/autofill/form_group.h" | 7 #include "chrome/browser/autofill/form_group.h" |
| 8 | 8 |
| 9 #include <iterator> | 9 #include <iterator> |
| 10 | 10 |
| 11 string16 FormGroup::GetPreviewText(const AutofillType& type) const { | 11 string16 FormGroup::GetPreviewText(AutofillFieldType type) const { |
| 12 return GetFieldText(type); | 12 return GetFieldText(type); |
| 13 } | 13 } |
| 14 | 14 |
| 15 const string16 FormGroup::Label() const { return string16(); } | 15 const string16 FormGroup::Label() const { return string16(); } |
| 16 | 16 |
| 17 bool FormGroup::operator!=(const FormGroup& form_group) const { | 17 bool FormGroup::operator!=(const FormGroup& form_group) const { |
| 18 FieldTypeSet a, b, symmetric_difference; | 18 FieldTypeSet a, b, symmetric_difference; |
| 19 GetAvailableFieldTypes(&a); | 19 GetAvailableFieldTypes(&a); |
| 20 form_group.GetAvailableFieldTypes(&b); | 20 form_group.GetAvailableFieldTypes(&b); |
| 21 std::set_symmetric_difference( | 21 std::set_symmetric_difference( |
| 22 a.begin(), a.end(), | 22 a.begin(), a.end(), |
| 23 b.begin(), b.end(), | 23 b.begin(), b.end(), |
| 24 std::inserter(symmetric_difference, symmetric_difference.begin())); | 24 std::inserter(symmetric_difference, symmetric_difference.begin())); |
| 25 | 25 |
| 26 if (!symmetric_difference.empty()) | 26 if (!symmetric_difference.empty()) |
| 27 return true; | 27 return true; |
| 28 | 28 |
| 29 return (!IntersectionOfTypesHasEqualValues(form_group)); | 29 return (!IntersectionOfTypesHasEqualValues(form_group)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 bool FormGroup::IsSubsetOf(const FormGroup& form_group) const { | 32 bool FormGroup::IsSubsetOf(const FormGroup& form_group) const { |
| 33 FieldTypeSet types; | 33 FieldTypeSet types; |
| 34 GetAvailableFieldTypes(&types); | 34 GetAvailableFieldTypes(&types); |
| 35 | 35 |
| 36 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end(); | 36 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end(); |
| 37 ++iter) { | 37 ++iter) { |
| 38 AutofillType type(*iter); | 38 if (GetFieldText(*iter) != form_group.GetFieldText(*iter)) |
| 39 if (GetFieldText(type) != form_group.GetFieldText(type)) | |
| 40 return false; | 39 return false; |
| 41 } | 40 } |
| 42 | 41 |
| 43 return true; | 42 return true; |
| 44 } | 43 } |
| 45 | 44 |
| 46 bool FormGroup::IntersectionOfTypesHasEqualValues( | 45 bool FormGroup::IntersectionOfTypesHasEqualValues( |
| 47 const FormGroup& form_group) const { | 46 const FormGroup& form_group) const { |
| 48 FieldTypeSet a, b, intersection; | 47 FieldTypeSet a, b, intersection; |
| 49 GetAvailableFieldTypes(&a); | 48 GetAvailableFieldTypes(&a); |
| 50 form_group.GetAvailableFieldTypes(&b); | 49 form_group.GetAvailableFieldTypes(&b); |
| 51 std::set_intersection(a.begin(), a.end(), | 50 std::set_intersection(a.begin(), a.end(), |
| 52 b.begin(), b.end(), | 51 b.begin(), b.end(), |
| 53 std::inserter(intersection, intersection.begin())); | 52 std::inserter(intersection, intersection.begin())); |
| 54 | 53 |
| 55 // An empty intersection can't have equal values. | 54 // An empty intersection can't have equal values. |
| 56 if (intersection.empty()) | 55 if (intersection.empty()) |
| 57 return false; | 56 return false; |
| 58 | 57 |
| 59 for (FieldTypeSet::const_iterator iter = intersection.begin(); | 58 for (FieldTypeSet::const_iterator iter = intersection.begin(); |
| 60 iter != intersection.end(); ++iter) { | 59 iter != intersection.end(); ++iter) { |
| 61 AutofillType type(*iter); | 60 if (GetFieldText(*iter) != form_group.GetFieldText(*iter)) |
| 62 if (GetFieldText(type) != form_group.GetFieldText(type)) | |
| 63 return false; | 61 return false; |
| 64 } | 62 } |
| 65 | 63 |
| 66 return true; | 64 return true; |
| 67 } | 65 } |
| 68 | 66 |
| 69 void FormGroup::MergeWith(const FormGroup& form_group) { | 67 void FormGroup::MergeWith(const FormGroup& form_group) { |
| 70 FieldTypeSet a, b, intersection; | 68 FieldTypeSet a, b, intersection; |
| 71 GetAvailableFieldTypes(&a); | 69 GetAvailableFieldTypes(&a); |
| 72 form_group.GetAvailableFieldTypes(&b); | 70 form_group.GetAvailableFieldTypes(&b); |
| 73 std::set_difference(b.begin(), b.end(), | 71 std::set_difference(b.begin(), b.end(), |
| 74 a.begin(), a.end(), | 72 a.begin(), a.end(), |
| 75 std::inserter(intersection, intersection.begin())); | 73 std::inserter(intersection, intersection.begin())); |
| 76 | 74 |
| 77 for (FieldTypeSet::const_iterator iter = intersection.begin(); | 75 for (FieldTypeSet::const_iterator iter = intersection.begin(); |
| 78 iter != intersection.end(); ++iter) { | 76 iter != intersection.end(); ++iter) { |
| 79 AutofillType type(*iter); | 77 SetInfo(*iter, form_group.GetFieldText(*iter)); |
| 80 SetInfo(type, form_group.GetFieldText(type)); | |
| 81 } | 78 } |
| 82 } | 79 } |
| 83 | 80 |
| 84 void FormGroup::OverwriteWith(const FormGroup& form_group) { | 81 void FormGroup::OverwriteWith(const FormGroup& form_group) { |
| 85 FieldTypeSet a;; | 82 FieldTypeSet a;; |
| 86 form_group.GetAvailableFieldTypes(&a); | 83 form_group.GetAvailableFieldTypes(&a); |
| 87 | 84 |
| 88 for (FieldTypeSet::const_iterator iter = a.begin(); iter != a.end(); ++iter) { | 85 for (FieldTypeSet::const_iterator iter = a.begin(); iter != a.end(); ++iter) { |
| 89 AutofillType type(*iter); | 86 SetInfo(*iter, form_group.GetFieldText(*iter)); |
| 90 SetInfo(type, form_group.GetFieldText(type)); | |
| 91 } | 87 } |
| 92 } | 88 } |
| OLD | NEW |