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
3 // found in the LICENSE file.
5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
11 #include "base/logging.h"
12 #include "components/autofill/core/browser/webdata/autofill_entry.h"
16 class AutofillProfile
;
19 // For classic Autofill form fields, the KeyType is AutofillKey.
20 // Autofill++ types such as AutofillProfile and CreditCard simply use a string.
21 template <typename KeyType
>
22 class GenericAutofillChange
{
30 virtual ~GenericAutofillChange() {}
32 Type
type() const { return type_
; }
33 const KeyType
& key() const { return key_
; }
36 GenericAutofillChange(Type type
, const KeyType
& key
)
44 class AutofillChange
: public GenericAutofillChange
<AutofillKey
> {
46 AutofillChange(Type type
, const AutofillKey
& key
);
47 ~AutofillChange() override
;
48 bool operator==(const AutofillChange
& change
) const {
49 return type() == change
.type() && key() == change
.key();
53 typedef std::vector
<AutofillChange
> AutofillChangeList
;
55 // Change notification details for Autofill profile or credit card changes.
56 template <typename DataType
>
57 class AutofillDataModelChange
: public GenericAutofillChange
<std::string
> {
59 // The |type| input specifies the change type. The |key| input is the key,
60 // which is expected to be the GUID identifying the |data_model|.
61 // When |type| == ADD, |data_model| should be non-NULL.
62 // When |type| == UPDATE, |data_model| should be non-NULL.
63 // When |type| == REMOVE, |data_model| should be NULL.
64 AutofillDataModelChange(Type type
,
65 const std::string
& key
,
66 const DataType
* data_model
)
67 : GenericAutofillChange
<std::string
>(type
, key
), data_model_(data_model
) {
68 DCHECK(type
== REMOVE
? !data_model
69 : data_model
&& data_model
->guid() == key
);
72 ~AutofillDataModelChange() override
{}
74 const DataType
* data_model() const { return data_model_
; }
76 bool operator==(const AutofillDataModelChange
<DataType
>& change
) const {
77 return type() == change
.type() && key() == change
.key() &&
78 (type() == REMOVE
|| *data_model() == *change
.data_model());
82 // Weak reference, can be NULL.
83 const DataType
* data_model_
;
86 typedef AutofillDataModelChange
<AutofillProfile
> AutofillProfileChange
;
87 typedef AutofillDataModelChange
<CreditCard
> CreditCardChange
;
89 } // namespace autofill
91 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__