data_model_wrapper.h revision 90dce4d38c5ff5333bea97d859d4e484e27edf0c
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  virtual string16 GetDisplayText() OVERRIDE;
130
131 private:
132  const wallet::Address* address_;
133
134  DISALLOW_COPY_AND_ASSIGN(WalletAddressWrapper);
135};
136
137// A DataModelWrapper for Wallet instruments.
138class WalletInstrumentWrapper : public DataModelWrapper {
139 public:
140  explicit WalletInstrumentWrapper(
141      const wallet::WalletItems::MaskedInstrument* instrument);
142  virtual ~WalletInstrumentWrapper();
143
144  virtual string16 GetInfo(AutofillFieldType type) OVERRIDE;
145  virtual gfx::Image GetIcon() OVERRIDE;
146  virtual string16 GetDisplayText() OVERRIDE;
147
148 private:
149  const wallet::WalletItems::MaskedInstrument* instrument_;
150
151  DISALLOW_COPY_AND_ASSIGN(WalletInstrumentWrapper);
152};
153
154// A DataModelWrapper for FullWallets billing data.
155class FullWalletBillingWrapper : public DataModelWrapper {
156 public:
157  explicit FullWalletBillingWrapper(wallet::FullWallet* full_wallet);
158  virtual ~FullWalletBillingWrapper();
159
160  virtual string16 GetInfo(AutofillFieldType type) OVERRIDE;
161  virtual string16 GetDisplayText() OVERRIDE;
162
163 private:
164  wallet::FullWallet* full_wallet_;
165
166  DISALLOW_COPY_AND_ASSIGN(FullWalletBillingWrapper);
167};
168
169// A DataModelWrapper for FullWallets shipping data.
170class FullWalletShippingWrapper : public DataModelWrapper {
171 public:
172  explicit FullWalletShippingWrapper(wallet::FullWallet* full_wallet);
173  virtual ~FullWalletShippingWrapper();
174
175  virtual string16 GetInfo(AutofillFieldType type) OVERRIDE;
176
177 private:
178  wallet::FullWallet* full_wallet_;
179
180  DISALLOW_COPY_AND_ASSIGN(FullWalletShippingWrapper);
181};
182
183}  // namespace autofill
184
185#endif  // CHROME_BROWSER_UI_AUTOFILL_DATA_MODEL_WRAPPER_H_
186