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