Home | History | Annotate | Download | only in webdata
      1 // Copyright (c) 2011 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 
      5 #ifndef CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
      6 #define CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
      7 #pragma once
      8 
      9 #include "chrome/browser/webdata/autofill_entry.h"
     10 
     11 class AutofillProfile;
     12 class CreditCard;
     13 
     14 // For classic Autofill form fields, the KeyType is AutofillKey.
     15 // Autofill++ types such as AutofillProfile and CreditCard simply use an int.
     16 template <typename KeyType>
     17 class GenericAutofillChange {
     18  public:
     19   typedef enum {
     20     ADD,
     21     UPDATE,
     22     REMOVE
     23   } Type;
     24 
     25   virtual ~GenericAutofillChange() {}
     26 
     27   Type type() const { return type_; }
     28   const KeyType& key() const { return key_; }
     29 
     30  protected:
     31   GenericAutofillChange(Type type, const KeyType& key)
     32       : type_(type),
     33         key_(key) {}
     34  private:
     35   Type type_;
     36   KeyType key_;
     37 };
     38 
     39 class AutofillChange : public GenericAutofillChange<AutofillKey> {
     40  public:
     41   AutofillChange(Type type, const AutofillKey& key);
     42   virtual ~AutofillChange();
     43   bool operator==(const AutofillChange& change) const {
     44     return type() == change.type() && key() == change.key();
     45   }
     46 };
     47 
     48 // Change notification details for Autofill profile changes.
     49 class AutofillProfileChange : public GenericAutofillChange<std::string> {
     50  public:
     51   // The |type| input specifies the change type.  The |key| input is the key,
     52   // which is expected to be the GUID identifying the |profile|.
     53   // When |type| == ADD, |profile| should be non-NULL.
     54   // When |type| == UPDATE, |profile| should be non-NULL.
     55   // When |type| == REMOVE, |profile| should be NULL.
     56   AutofillProfileChange(Type type,
     57                         std::string key,
     58                         const AutofillProfile* profile);
     59   virtual ~AutofillProfileChange();
     60 
     61   const AutofillProfile* profile() const { return profile_; }
     62   bool operator==(const AutofillProfileChange& change) const;
     63 
     64  private:
     65   // Weak reference, can be NULL.
     66   const AutofillProfile* profile_;
     67 };
     68 
     69 // Change notification details for Autofill credit card changes.
     70 class AutofillCreditCardChange : public GenericAutofillChange<std::string> {
     71  public:
     72   // The |type| input specifies the change type.  The |key| input is the key,
     73   // which is expected to be the GUID identifying the |credit_card|.
     74   // When |type| == ADD, |credit_card| should be non-NULL.
     75   // When |type| == UPDATE, |credit_card| should be non-NULL.
     76   // When |type| == REMOVE, |credit_card| should be NULL.
     77   AutofillCreditCardChange(Type type,
     78                            std::string key,
     79                            const CreditCard* credit_card);
     80   virtual ~AutofillCreditCardChange();
     81 
     82   const CreditCard* credit_card() const { return credit_card_; }
     83   bool operator==(const AutofillCreditCardChange& change) const;
     84 
     85  private:
     86   // Weak reference, can be NULL.
     87   const CreditCard* credit_card_;
     88 };
     89 
     90 #endif  // CHROME_BROWSER_WEBDATA_AUTOFILL_CHANGE_H__
     91