summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata/autofill_change.h
blob: 2a46399da44ef4b31565631e20fbf8c599d4b81a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
#define CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
#pragma once

#include "chrome/browser/webdata/autofill_entry.h"

class AutoFillProfile;
class CreditCard;

// For classic Autofill form fields, the KeyType is AutofillKey.
// Autofill++ types such as AutoFillProfile and CreditCard simply use an int.
template <typename KeyType>
class GenericAutofillChange {
 public:
  typedef enum {
    ADD,
    UPDATE,
    REMOVE
  } Type;

  virtual ~GenericAutofillChange() {}

  Type type() const { return type_; }
  const KeyType& key() const { return key_; }

 protected:
  GenericAutofillChange(Type type, const KeyType& key)
      : type_(type),
        key_(key) {}
 private:
  Type type_;
  KeyType key_;
};

class AutofillChange : public GenericAutofillChange<AutofillKey> {
 public:
  AutofillChange(Type type, const AutofillKey& key);
  virtual ~AutofillChange();
  bool operator==(const AutofillChange& change) const {
    return type() == change.type() && key() == change.key();
  }
};

// DEPRECATED
// TODO(dhollowa): Remove use of labels for sync.  http://crbug.com/58813
class AutofillProfileChange : public GenericAutofillChange<string16> {
 public:
  // The |type| input specifies the change type.  The |key| input is the key,
  // which is expected to be the label identifying the |profile|.
  // When |type| == ADD, |profile| should be non-NULL.
  // When |type| == UPDATE, |profile| should be non-NULL.
  // When |type| == REMOVE, |profile| should be NULL.
  // The |pre_update_label| input specifies the label as it was prior to the
  // change (applicable only for UPDATE).
  AutofillProfileChange(Type type,
                        string16 key,
                        const AutoFillProfile* profile,
                        const string16& pre_update_label);
  virtual ~AutofillProfileChange();

  const AutoFillProfile* profile() const { return profile_; }
  const string16& pre_update_label() const { return pre_update_label_; }
  bool operator==(const AutofillProfileChange& change) const;

 private:
  // Weak reference, can be NULL.
  const AutoFillProfile* profile_;
  const string16 pre_update_label_;
};

// DEPRECATED
// TODO(dhollowa): Remove use of labels for sync.  http://crbug.com/58813
class AutofillCreditCardChange : public GenericAutofillChange<string16> {
 public:
  // The |type| input specifies the change type.  The |key| input is the key,
  // which is expected to be the label identifying the |credit_card|.
  // When |type| == ADD, |credit_card| should be non-NULL.
  // When |type| == UPDATE, |credit_card| should be non-NULL.
  // When |type| == REMOVE, |credit_card| should be NULL.
  AutofillCreditCardChange(Type type,
                           string16 key,
                           const CreditCard* credit_card);
  virtual ~AutofillCreditCardChange();

  const CreditCard* credit_card() const { return credit_card_; }
  bool operator==(const AutofillCreditCardChange& change) const;

 private:
  // Weak reference, can be NULL.
  const CreditCard* credit_card_;
};

// Change notification details for AutoFill profile changes.
class AutofillProfileChangeGUID : public GenericAutofillChange<std::string> {
 public:
  // The |type| input specifies the change type.  The |key| input is the key,
  // which is expected to be the GUID identifying the |profile|.
  // When |type| == ADD, |profile| should be non-NULL.
  // When |type| == UPDATE, |profile| should be non-NULL.
  // When |type| == REMOVE, |profile| should be NULL.
  AutofillProfileChangeGUID(Type type,
                            std::string key,
                            const AutoFillProfile* profile);
  virtual ~AutofillProfileChangeGUID();

  const AutoFillProfile* profile() const { return profile_; }
  bool operator==(const AutofillProfileChangeGUID& change) const;

 private:
  // Weak reference, can be NULL.
  const AutoFillProfile* profile_;
};

// Change notification details for AutoFill credit card changes.
class AutofillCreditCardChangeGUID : public GenericAutofillChange<std::string> {
 public:
  // The |type| input specifies the change type.  The |key| input is the key,
  // which is expected to be the GUID identifying the |credit_card|.
  // When |type| == ADD, |credit_card| should be non-NULL.
  // When |type| == UPDATE, |credit_card| should be non-NULL.
  // When |type| == REMOVE, |credit_card| should be NULL.
  AutofillCreditCardChangeGUID(Type type,
                               std::string key,
                               const CreditCard* credit_card);
  virtual ~AutofillCreditCardChangeGUID();

  const CreditCard* credit_card() const { return credit_card_; }
  bool operator==(const AutofillCreditCardChangeGUID& change) const;

 private:
  // Weak reference, can be NULL.
  const CreditCard* credit_card_;
};

#endif  // CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__