data_model_wrapper.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
1// Copyright (c) 2012 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_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ 6#define CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ 7 8#include "base/compiler_specific.h" 9#include "base/string16.h" 10#include "chrome/browser/ui/autofill/autofill_dialog_types.h" 11#include "components/autofill/browser/field_types.h" 12#include "components/autofill/browser/wallet/wallet_items.h" 13 14namespace gfx { 15class Image; 16} 17 18namespace autofill { 19 20class AutofillDataModel; 21class AutofillProfile; 22class CreditCard; 23class FormStructure; 24 25namespace wallet { 26class Address; 27class FullWallet; 28} 29 30// A glue class that allows uniform interactions with autocomplete data sources, 31// regardless of their type. Implementations are intended to be lightweight and 32// copyable, only holding weak references to their backing model. 33class DataModelWrapper { 34 public: 35 virtual ~DataModelWrapper(); 36 37 // Returns the data for a specific autocomplete type. 38 virtual string16 GetInfo(AutofillFieldType type) = 0; 39 40 // Returns the icon, if any, that represents this model. 41 virtual gfx::Image GetIcon(); 42 43 // Fills in |inputs| with the data that this model contains (|inputs| is an 44 // out-param). 45 virtual void FillInputs(DetailInputs* inputs); 46 47 // Returns text to display to the user to summarize this data source. The 48 // default implementation assumes this is an address. 49 virtual string16 GetDisplayText(); 50 51 // Fills in |form_structure| with the data that this model contains. |inputs| 52 // and |comparator| are used to determine whether each field in the 53 // FormStructure should be filled in or left alone. 54 void FillFormStructure( 55 const DetailInputs& inputs, 56 const InputFieldComparator& compare, 57 FormStructure* form_structure); 58 59 protected: 60 DataModelWrapper(); 61 62 // Fills in |field| with data from the model. 63 virtual void FillFormField(AutofillField* field); 64 65 private: 66 DISALLOW_COPY_AND_ASSIGN(DataModelWrapper); 67}; 68 69// A DataModelWrapper for Autofill data. 70class AutofillDataModelWrapper : public DataModelWrapper { 71 public: 72 AutofillDataModelWrapper(const AutofillDataModel* data_model, size_t variant); 73 virtual ~AutofillDataModelWrapper(); 74 75 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; 76 77 protected: 78 virtual void FillFormField(AutofillField* field) OVERRIDE; 79 80 size_t variant() const { return variant_; } 81 82 private: 83 const AutofillDataModel* data_model_; 84 const size_t variant_; 85 86 DISALLOW_COPY_AND_ASSIGN(AutofillDataModelWrapper); 87}; 88 89// A DataModelWrapper for Autofill profiles. 90class AutofillProfileWrapper : public AutofillDataModelWrapper { 91 public: 92 AutofillProfileWrapper(const AutofillProfile* profile, size_t variant); 93 virtual ~AutofillProfileWrapper(); 94 95 virtual void FillInputs(DetailInputs* inputs) OVERRIDE; 96 97 private: 98 const AutofillProfile* profile_; 99 100 DISALLOW_COPY_AND_ASSIGN(AutofillProfileWrapper); 101}; 102 103// A DataModelWrapper specifically for Autofill CreditCard data. 104class AutofillCreditCardWrapper : public AutofillDataModelWrapper { 105 public: 106 explicit AutofillCreditCardWrapper(const CreditCard* card); 107 virtual ~AutofillCreditCardWrapper(); 108 109 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; 110 virtual gfx::Image GetIcon() OVERRIDE; 111 virtual string16 GetDisplayText() OVERRIDE; 112 113 protected: 114 virtual void FillFormField(AutofillField* field) OVERRIDE; 115 116 private: 117 const CreditCard* card_; 118 119 DISALLOW_COPY_AND_ASSIGN(AutofillCreditCardWrapper); 120}; 121 122// A DataModelWrapper for Wallet addresses. 123class WalletAddressWrapper : public DataModelWrapper { 124 public: 125 explicit WalletAddressWrapper(const wallet::Address* address); 126 virtual ~WalletAddressWrapper(); 127 128 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; 129 130 private: 131 const wallet::Address* address_; 132 133 DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper); 134}; 135 136// A DataModelWrapper for Wallet instruments. 137class WalletInstrumentWrapper : public DataModelWrapper { 138 public: 139 explicit WalletInstrumentWrapper( 140 const wallet::WalletItems::MaskedInstrument* instrument); 141 virtual ~WalletInstrumentWrapper(); 142 143 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; 144 virtual gfx::Image GetIcon() OVERRIDE; 145 virtual string16 GetDisplayText() OVERRIDE; 146 147 private: 148 const wallet::WalletItems::MaskedInstrument* instrument_; 149 150 DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper); 151}; 152 153// A DataModelWrapper for FullWallets billing data. 154class FullWalletBillingWrapper : public DataModelWrapper { 155 public: 156 explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet); 157 virtual ~FullWalletBillingWrapper(); 158 159 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; 160 virtual string16 GetDisplayText() OVERRIDE; 161 162 private: 163 wallet::FullWallet* full_wallet_; 164 165 DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper); 166}; 167 168// A DataModelWrapper for FullWallets shipping data. 169class FullWalletShippingWrapper : public DataModelWrapper { 170 public: 171 explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet); 172 virtual ~FullWalletShippingWrapper(); 173 174 virtual string16 GetInfo(AutofillFieldType type) OVERRIDE; 175 176 private: 177 wallet::FullWallet* full_wallet_; 178 179 DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper); 180}; 181 182} // namespace autofill 183 184#endif // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_ 185