blob: 6c53303744238475309530cd808b3bf14953c51c [file] [log] [blame]
[email protected]a7b29dd2010-07-12 22:40:061// 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
3// found in the LICENSE file.
4
[email protected]39a749c2011-01-28 02:40:465#include <algorithm>
6
[email protected]a7b29dd2010-07-12 22:40:067#include "chrome/browser/autofill/form_group.h"
8
[email protected]8e383412010-10-19 16:57:039string16 FormGroup::GetPreviewText(const AutoFillType& type) const {
10 return GetFieldText(type);
11}
12
[email protected]e94f1862010-10-27 15:25:5713const string16 FormGroup::Label() const { return string16(); }
[email protected]8e383412010-10-19 16:57:0314
[email protected]a7b29dd2010-07-12 22:40:0615bool FormGroup::operator!=(const FormGroup& form_group) const {
16 FieldTypeSet a, b, symmetric_difference;
17 GetAvailableFieldTypes(&a);
18 form_group.GetAvailableFieldTypes(&b);
19 std::set_symmetric_difference(
20 a.begin(), a.end(),
21 b.begin(), b.end(),
22 std::inserter(symmetric_difference, symmetric_difference.begin()));
23
24 if (!symmetric_difference.empty())
25 return true;
26
27 return (!IntersectionOfTypesHasEqualValues(form_group));
28}
29
30bool FormGroup::IsSubsetOf(const FormGroup& form_group) const {
31 FieldTypeSet types;
32 GetAvailableFieldTypes(&types);
33
34 for (FieldTypeSet::const_iterator iter = types.begin(); iter != types.end();
35 ++iter) {
36 AutoFillType type(*iter);
37 if (GetFieldText(type) != form_group.GetFieldText(type))
38 return false;
39 }
40
41 return true;
42}
43
44bool FormGroup::IntersectionOfTypesHasEqualValues(
45 const FormGroup& form_group) const {
46 FieldTypeSet a, b, intersection;
47 GetAvailableFieldTypes(&a);
48 form_group.GetAvailableFieldTypes(&b);
49 std::set_intersection(a.begin(), a.end(),
50 b.begin(), b.end(),
51 std::inserter(intersection, intersection.begin()));
52
53 // An empty intersection can't have equal values.
54 if (intersection.empty())
55 return false;
56
57 for (FieldTypeSet::const_iterator iter = intersection.begin();
58 iter != intersection.end(); ++iter) {
59 AutoFillType type(*iter);
60 if (GetFieldText(type) != form_group.GetFieldText(type))
61 return false;
62 }
63
64 return true;
65}
66
67void FormGroup::MergeWith(const FormGroup& form_group) {
68 FieldTypeSet a, b, intersection;
69 GetAvailableFieldTypes(&a);
70 form_group.GetAvailableFieldTypes(&b);
71 std::set_difference(b.begin(), b.end(),
72 a.begin(), a.end(),
73 std::inserter(intersection, intersection.begin()));
74
75 for (FieldTypeSet::const_iterator iter = intersection.begin();
76 iter != intersection.end(); ++iter) {
77 AutoFillType type(*iter);
78 SetInfo(type, form_group.GetFieldText(type));
79 }
80}
[email protected]d7da65d2010-11-11 19:26:0581
82void FormGroup::OverwriteWith(const FormGroup& form_group) {
83 FieldTypeSet a;;
84 form_group.GetAvailableFieldTypes(&a);
85
86 for (FieldTypeSet::const_iterator iter = a.begin(); iter != a.end(); ++iter) {
87 AutoFillType type(*iter);
88 SetInfo(type, form_group.GetFieldText(type));
89 }
90}