Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / autofill / core / browser / webdata / autofill_change.h
blob6212c6079c56623274f472c884e45759ad5c00a6
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__
8 #include <string>
9 #include <vector>
11 #include "base/logging.h"
12 #include "components/autofill/core/browser/webdata/autofill_entry.h"
14 namespace autofill {
16 class AutofillProfile;
17 class CreditCard;
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 {
23 public:
24 enum Type {
25 ADD,
26 UPDATE,
27 REMOVE
30 virtual ~GenericAutofillChange() {}
32 Type type() const { return type_; }
33 const KeyType& key() const { return key_; }
35 protected:
36 GenericAutofillChange(Type type, const KeyType& key)
37 : type_(type),
38 key_(key) {}
39 private:
40 Type type_;
41 KeyType key_;
44 class AutofillChange : public GenericAutofillChange<AutofillKey> {
45 public:
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> {
58 public:
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());
81 private:
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__