OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/browser/webdata/autofill_webdata_backend.h" | 5 #include "components/autofill/browser/webdata/autofill_webdata_backend_impl.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "components/autofill/browser/autofill_country.h" | 9 #include "components/autofill/browser/autofill_country.h" |
10 #include "components/autofill/browser/autofill_profile.h" | 10 #include "components/autofill/browser/autofill_profile.h" |
11 #include "components/autofill/browser/credit_card.h" | 11 #include "components/autofill/browser/credit_card.h" |
12 #include "components/autofill/browser/webdata/autofill_change.h" | 12 #include "components/autofill/browser/webdata/autofill_change.h" |
13 #include "components/autofill/browser/webdata/autofill_entry.h" | 13 #include "components/autofill/browser/webdata/autofill_entry.h" |
14 #include "components/autofill/browser/webdata/autofill_table.h" | 14 #include "components/autofill/browser/webdata/autofill_table.h" |
15 #include "components/autofill/browser/webdata/autofill_webdata_service_observer.
h" | 15 #include "components/autofill/browser/webdata/autofill_webdata_service_observer.
h" |
16 #include "components/autofill/common/form_field_data.h" | 16 #include "components/autofill/common/form_field_data.h" |
| 17 #include "components/webdata/common/web_data_service_backend.h" |
17 | 18 |
18 using base::Bind; | 19 using base::Bind; |
19 using base::Time; | 20 using base::Time; |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
22 namespace autofill { | 23 namespace autofill { |
23 | 24 |
24 AutofillWebDataBackend::AutofillWebDataBackend() { | 25 AutofillWebDataBackendImpl::AutofillWebDataBackendImpl( |
| 26 scoped_refptr<WebDataServiceBackend> web_database_backend, |
| 27 const base::Closure& on_changed_callback) |
| 28 : web_database_backend_(web_database_backend), |
| 29 on_changed_callback_(on_changed_callback) { |
25 } | 30 } |
26 | 31 |
27 void AutofillWebDataBackend::AddObserver( | 32 void AutofillWebDataBackendImpl::AddObserver( |
28 AutofillWebDataServiceObserverOnDBThread* observer) { | 33 AutofillWebDataServiceObserverOnDBThread* observer) { |
29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 34 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
30 db_observer_list_.AddObserver(observer); | 35 db_observer_list_.AddObserver(observer); |
31 } | 36 } |
32 | 37 |
33 void AutofillWebDataBackend::RemoveObserver( | 38 void AutofillWebDataBackendImpl::RemoveObserver( |
34 AutofillWebDataServiceObserverOnDBThread* observer) { | 39 AutofillWebDataServiceObserverOnDBThread* observer) { |
35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 40 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
36 db_observer_list_.RemoveObserver(observer); | 41 db_observer_list_.RemoveObserver(observer); |
37 } | 42 } |
38 | 43 |
39 AutofillWebDataBackend::~AutofillWebDataBackend() { | 44 AutofillWebDataBackendImpl::~AutofillWebDataBackendImpl() { |
40 } | 45 } |
41 | 46 |
42 WebDatabase::State AutofillWebDataBackend::AddFormElements( | 47 WebDatabase* AutofillWebDataBackendImpl::GetDatabase() { |
| 48 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 49 return web_database_backend_->database(); |
| 50 } |
| 51 |
| 52 void AutofillWebDataBackendImpl::RemoveExpiredFormElementsWrapper() { |
| 53 web_database_backend_->ExecuteWriteTask( |
| 54 Bind(&AutofillWebDataBackendImpl::RemoveExpiredFormElements, this)); |
| 55 } |
| 56 |
| 57 void AutofillWebDataBackendImpl::NotifyOfMultipleAutofillChanges() { |
| 58 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 59 BrowserThread::PostTask(BrowserThread::UI, |
| 60 FROM_HERE, |
| 61 on_changed_callback_); |
| 62 } |
| 63 |
| 64 WebDatabase::State AutofillWebDataBackendImpl::AddFormElements( |
43 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 65 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
45 AutofillChangeList changes; | 67 AutofillChangeList changes; |
46 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( | 68 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( |
47 fields, &changes)) { | 69 fields, &changes)) { |
48 NOTREACHED(); | 70 NOTREACHED(); |
49 return WebDatabase::COMMIT_NOT_NEEDED; | 71 return WebDatabase::COMMIT_NOT_NEEDED; |
50 } | 72 } |
51 | 73 |
52 // Post the notifications including the list of affected keys. | 74 // Post the notifications including the list of affected keys. |
53 // This is sent here so that work resulting from this notification will be | 75 // This is sent here so that work resulting from this notification will be |
54 // done on the DB thread, and not the UI thread. | 76 // done on the DB thread, and not the UI thread. |
55 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 77 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
56 db_observer_list_, | 78 db_observer_list_, |
57 AutofillEntriesChanged(changes)); | 79 AutofillEntriesChanged(changes)); |
58 | 80 |
59 return WebDatabase::COMMIT_NEEDED; | 81 return WebDatabase::COMMIT_NEEDED; |
60 } | 82 } |
61 | 83 |
62 scoped_ptr<WDTypedResult> | 84 scoped_ptr<WDTypedResult> |
63 AutofillWebDataBackend::GetFormValuesForElementName( | 85 AutofillWebDataBackendImpl::GetFormValuesForElementName( |
64 const base::string16& name, const base::string16& prefix, int limit, | 86 const base::string16& name, const base::string16& prefix, int limit, |
65 WebDatabase* db) { | 87 WebDatabase* db) { |
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
67 std::vector<base::string16> values; | 89 std::vector<base::string16> values; |
68 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( | 90 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( |
69 name, prefix, &values, limit); | 91 name, prefix, &values, limit); |
70 return scoped_ptr<WDTypedResult>( | 92 return scoped_ptr<WDTypedResult>( |
71 new WDResult<std::vector<base::string16> >(AUTOFILL_VALUE_RESULT, | 93 new WDResult<std::vector<base::string16> >(AUTOFILL_VALUE_RESULT, |
72 values)); | 94 values)); |
73 } | 95 } |
74 | 96 |
75 WebDatabase::State AutofillWebDataBackend::RemoveFormElementsAddedBetween( | 97 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormElementsAddedBetween( |
76 const base::Time& delete_begin, const base::Time& delete_end, | 98 const base::Time& delete_begin, const base::Time& delete_end, |
77 WebDatabase* db) { | 99 WebDatabase* db) { |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 100 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
79 AutofillChangeList changes; | 101 AutofillChangeList changes; |
80 | 102 |
81 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( | 103 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( |
82 delete_begin, delete_end, &changes)) { | 104 delete_begin, delete_end, &changes)) { |
83 if (!changes.empty()) { | 105 if (!changes.empty()) { |
84 // Post the notifications including the list of affected keys. | 106 // Post the notifications including the list of affected keys. |
85 // This is sent here so that work resulting from this notification | 107 // This is sent here so that work resulting from this notification |
86 // will be done on the DB thread, and not the UI thread. | 108 // will be done on the DB thread, and not the UI thread. |
87 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 109 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
88 db_observer_list_, | 110 db_observer_list_, |
89 AutofillEntriesChanged(changes)); | 111 AutofillEntriesChanged(changes)); |
90 } | 112 } |
91 return WebDatabase::COMMIT_NEEDED; | 113 return WebDatabase::COMMIT_NEEDED; |
92 } | 114 } |
93 return WebDatabase::COMMIT_NOT_NEEDED; | 115 return WebDatabase::COMMIT_NOT_NEEDED; |
94 } | 116 } |
95 | 117 |
96 WebDatabase::State AutofillWebDataBackend::RemoveExpiredFormElements( | 118 WebDatabase::State AutofillWebDataBackendImpl::RemoveExpiredFormElements( |
97 WebDatabase* db) { | 119 WebDatabase* db) { |
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 120 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
99 AutofillChangeList changes; | 121 AutofillChangeList changes; |
100 | 122 |
101 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { | 123 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { |
102 if (!changes.empty()) { | 124 if (!changes.empty()) { |
103 // Post the notifications including the list of affected keys. | 125 // Post the notifications including the list of affected keys. |
104 // This is sent here so that work resulting from this notification | 126 // This is sent here so that work resulting from this notification |
105 // will be done on the DB thread, and not the UI thread. | 127 // will be done on the DB thread, and not the UI thread. |
106 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 128 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
107 db_observer_list_, | 129 db_observer_list_, |
108 AutofillEntriesChanged(changes)); | 130 AutofillEntriesChanged(changes)); |
109 } | 131 } |
110 return WebDatabase::COMMIT_NEEDED; | 132 return WebDatabase::COMMIT_NEEDED; |
111 } | 133 } |
112 return WebDatabase::COMMIT_NOT_NEEDED; | 134 return WebDatabase::COMMIT_NOT_NEEDED; |
113 } | 135 } |
114 | 136 |
115 WebDatabase::State AutofillWebDataBackend::RemoveFormValueForElementName( | 137 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName( |
116 const base::string16& name, const base::string16& value, WebDatabase* db) { | 138 const base::string16& name, const base::string16& value, WebDatabase* db) { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 139 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
118 | 140 |
119 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { | 141 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { |
120 AutofillChangeList changes; | 142 AutofillChangeList changes; |
121 changes.push_back( | 143 changes.push_back( |
122 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); | 144 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); |
123 | 145 |
124 // Post the notifications including the list of affected keys. | 146 // Post the notifications including the list of affected keys. |
125 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 147 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
126 db_observer_list_, | 148 db_observer_list_, |
127 AutofillEntriesChanged(changes)); | 149 AutofillEntriesChanged(changes)); |
128 | 150 |
129 return WebDatabase::COMMIT_NEEDED; | 151 return WebDatabase::COMMIT_NEEDED; |
130 } | 152 } |
131 return WebDatabase::COMMIT_NOT_NEEDED; | 153 return WebDatabase::COMMIT_NOT_NEEDED; |
132 } | 154 } |
133 | 155 |
134 WebDatabase::State AutofillWebDataBackend::AddAutofillProfile( | 156 WebDatabase::State AutofillWebDataBackendImpl::AddAutofillProfile( |
135 const AutofillProfile& profile, WebDatabase* db) { | 157 const AutofillProfile& profile, WebDatabase* db) { |
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
137 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { | 159 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { |
138 NOTREACHED(); | 160 NOTREACHED(); |
139 return WebDatabase::COMMIT_NOT_NEEDED; | 161 return WebDatabase::COMMIT_NOT_NEEDED; |
140 } | 162 } |
141 | 163 |
142 // Send GUID-based notification. | 164 // Send GUID-based notification. |
143 AutofillProfileChange change( | 165 AutofillProfileChange change( |
144 AutofillProfileChange::ADD, profile.guid(), &profile); | 166 AutofillProfileChange::ADD, profile.guid(), &profile); |
145 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 167 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
146 db_observer_list_, | 168 db_observer_list_, |
147 AutofillProfileChanged(change)); | 169 AutofillProfileChanged(change)); |
148 | 170 |
149 return WebDatabase::COMMIT_NEEDED; | 171 return WebDatabase::COMMIT_NEEDED; |
150 } | 172 } |
151 | 173 |
152 WebDatabase::State AutofillWebDataBackend::UpdateAutofillProfile( | 174 WebDatabase::State AutofillWebDataBackendImpl::UpdateAutofillProfile( |
153 const AutofillProfile& profile, WebDatabase* db) { | 175 const AutofillProfile& profile, WebDatabase* db) { |
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 176 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
155 // Only perform the update if the profile exists. It is currently | 177 // Only perform the update if the profile exists. It is currently |
156 // valid to try to update a missing profile. We simply drop the write and | 178 // valid to try to update a missing profile. We simply drop the write and |
157 // the caller will detect this on the next refresh. | 179 // the caller will detect this on the next refresh. |
158 AutofillProfile* original_profile = NULL; | 180 AutofillProfile* original_profile = NULL; |
159 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), | 181 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), |
160 &original_profile)) { | 182 &original_profile)) { |
161 return WebDatabase::COMMIT_NOT_NEEDED; | 183 return WebDatabase::COMMIT_NOT_NEEDED; |
162 } | 184 } |
163 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | 185 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
164 | 186 |
165 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( | 187 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( |
166 profile)) { | 188 profile)) { |
167 NOTREACHED(); | 189 NOTREACHED(); |
168 return WebDatabase::COMMIT_NEEDED; | 190 return WebDatabase::COMMIT_NEEDED; |
169 } | 191 } |
170 | 192 |
171 // Send GUID-based notification. | 193 // Send GUID-based notification. |
172 AutofillProfileChange change( | 194 AutofillProfileChange change( |
173 AutofillProfileChange::UPDATE, profile.guid(), &profile); | 195 AutofillProfileChange::UPDATE, profile.guid(), &profile); |
174 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 196 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
175 db_observer_list_, | 197 db_observer_list_, |
176 AutofillProfileChanged(change)); | 198 AutofillProfileChanged(change)); |
177 | 199 |
178 return WebDatabase::COMMIT_NEEDED; | 200 return WebDatabase::COMMIT_NEEDED; |
179 } | 201 } |
180 | 202 |
181 WebDatabase::State AutofillWebDataBackend::RemoveAutofillProfile( | 203 WebDatabase::State AutofillWebDataBackendImpl::RemoveAutofillProfile( |
182 const std::string& guid, WebDatabase* db) { | 204 const std::string& guid, WebDatabase* db) { |
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 205 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
184 AutofillProfile* profile = NULL; | 206 AutofillProfile* profile = NULL; |
185 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { | 207 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { |
186 NOTREACHED(); | 208 NOTREACHED(); |
187 return WebDatabase::COMMIT_NOT_NEEDED; | 209 return WebDatabase::COMMIT_NOT_NEEDED; |
188 } | 210 } |
189 scoped_ptr<AutofillProfile> scoped_profile(profile); | 211 scoped_ptr<AutofillProfile> scoped_profile(profile); |
190 | 212 |
191 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { | 213 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { |
192 NOTREACHED(); | 214 NOTREACHED(); |
193 return WebDatabase::COMMIT_NOT_NEEDED; | 215 return WebDatabase::COMMIT_NOT_NEEDED; |
194 } | 216 } |
195 | 217 |
196 // Send GUID-based notification. | 218 // Send GUID-based notification. |
197 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | 219 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
198 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 220 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
199 db_observer_list_, | 221 db_observer_list_, |
200 AutofillProfileChanged(change)); | 222 AutofillProfileChanged(change)); |
201 | 223 |
202 return WebDatabase::COMMIT_NEEDED; | 224 return WebDatabase::COMMIT_NEEDED; |
203 } | 225 } |
204 | 226 |
205 scoped_ptr<WDTypedResult> AutofillWebDataBackend::GetAutofillProfiles( | 227 scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetAutofillProfiles( |
206 WebDatabase* db) { | 228 WebDatabase* db) { |
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
208 std::vector<AutofillProfile*> profiles; | 230 std::vector<AutofillProfile*> profiles; |
209 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); | 231 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); |
210 return scoped_ptr<WDTypedResult>( | 232 return scoped_ptr<WDTypedResult>( |
211 new WDDestroyableResult<std::vector<AutofillProfile*> >( | 233 new WDDestroyableResult<std::vector<AutofillProfile*> >( |
212 AUTOFILL_PROFILES_RESULT, | 234 AUTOFILL_PROFILES_RESULT, |
213 profiles, | 235 profiles, |
214 base::Bind(&AutofillWebDataBackend::DestroyAutofillProfileResult, | 236 base::Bind(&AutofillWebDataBackendImpl::DestroyAutofillProfileResult, |
215 base::Unretained(this)))); | 237 base::Unretained(this)))); |
216 } | 238 } |
217 | 239 |
218 WebDatabase::State AutofillWebDataBackend::AddCreditCard( | 240 WebDatabase::State AutofillWebDataBackendImpl::AddCreditCard( |
219 const CreditCard& credit_card, WebDatabase* db) { | 241 const CreditCard& credit_card, WebDatabase* db) { |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 242 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
221 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { | 243 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { |
222 NOTREACHED(); | 244 NOTREACHED(); |
223 return WebDatabase::COMMIT_NOT_NEEDED; | 245 return WebDatabase::COMMIT_NOT_NEEDED; |
224 } | 246 } |
225 | 247 |
226 return WebDatabase::COMMIT_NEEDED; | 248 return WebDatabase::COMMIT_NEEDED; |
227 } | 249 } |
228 | 250 |
229 WebDatabase::State AutofillWebDataBackend::UpdateCreditCard( | 251 WebDatabase::State AutofillWebDataBackendImpl::UpdateCreditCard( |
230 const CreditCard& credit_card, WebDatabase* db) { | 252 const CreditCard& credit_card, WebDatabase* db) { |
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
232 // It is currently valid to try to update a missing profile. We simply drop | 254 // It is currently valid to try to update a missing profile. We simply drop |
233 // the write and the caller will detect this on the next refresh. | 255 // the write and the caller will detect this on the next refresh. |
234 CreditCard* original_credit_card = NULL; | 256 CreditCard* original_credit_card = NULL; |
235 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), | 257 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), |
236 &original_credit_card)) { | 258 &original_credit_card)) { |
237 return WebDatabase::COMMIT_NOT_NEEDED; | 259 return WebDatabase::COMMIT_NOT_NEEDED; |
238 } | 260 } |
239 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); | 261 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
240 | 262 |
241 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { | 263 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { |
242 NOTREACHED(); | 264 NOTREACHED(); |
243 return WebDatabase::COMMIT_NOT_NEEDED; | 265 return WebDatabase::COMMIT_NOT_NEEDED; |
244 } | 266 } |
245 return WebDatabase::COMMIT_NEEDED; | 267 return WebDatabase::COMMIT_NEEDED; |
246 } | 268 } |
247 | 269 |
248 WebDatabase::State AutofillWebDataBackend::RemoveCreditCard( | 270 WebDatabase::State AutofillWebDataBackendImpl::RemoveCreditCard( |
249 const std::string& guid, WebDatabase* db) { | 271 const std::string& guid, WebDatabase* db) { |
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
251 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { | 273 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { |
252 NOTREACHED(); | 274 NOTREACHED(); |
253 return WebDatabase::COMMIT_NOT_NEEDED; | 275 return WebDatabase::COMMIT_NOT_NEEDED; |
254 } | 276 } |
255 return WebDatabase::COMMIT_NEEDED; | 277 return WebDatabase::COMMIT_NEEDED; |
256 } | 278 } |
257 | 279 |
258 scoped_ptr<WDTypedResult> AutofillWebDataBackend::GetCreditCards( | 280 scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetCreditCards( |
259 WebDatabase* db) { | 281 WebDatabase* db) { |
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 282 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
261 std::vector<CreditCard*> credit_cards; | 283 std::vector<CreditCard*> credit_cards; |
262 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); | 284 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); |
263 return scoped_ptr<WDTypedResult>( | 285 return scoped_ptr<WDTypedResult>( |
264 new WDDestroyableResult<std::vector<CreditCard*> >( | 286 new WDDestroyableResult<std::vector<CreditCard*> >( |
265 AUTOFILL_CREDITCARDS_RESULT, | 287 AUTOFILL_CREDITCARDS_RESULT, |
266 credit_cards, | 288 credit_cards, |
267 base::Bind(&AutofillWebDataBackend::DestroyAutofillCreditCardResult, | 289 base::Bind(&AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult, |
268 base::Unretained(this)))); | 290 base::Unretained(this)))); |
269 } | 291 } |
270 | 292 |
271 WebDatabase::State | 293 WebDatabase::State |
272 AutofillWebDataBackend::RemoveAutofillDataModifiedBetween( | 294 AutofillWebDataBackendImpl::RemoveAutofillDataModifiedBetween( |
273 const base::Time& delete_begin, | 295 const base::Time& delete_begin, |
274 const base::Time& delete_end, | 296 const base::Time& delete_end, |
275 WebDatabase* db) { | 297 WebDatabase* db) { |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 298 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
277 std::vector<std::string> profile_guids; | 299 std::vector<std::string> profile_guids; |
278 std::vector<std::string> credit_card_guids; | 300 std::vector<std::string> credit_card_guids; |
279 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween( | 301 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween( |
280 delete_begin, | 302 delete_begin, |
281 delete_end, | 303 delete_end, |
282 &profile_guids, | 304 &profile_guids, |
283 &credit_card_guids)) { | 305 &credit_card_guids)) { |
284 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 306 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
285 iter != profile_guids.end(); ++iter) { | 307 iter != profile_guids.end(); ++iter) { |
286 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL); | 308 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL); |
287 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 309 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
288 db_observer_list_, | 310 db_observer_list_, |
289 AutofillProfileChanged(change)); | 311 AutofillProfileChanged(change)); |
290 } | 312 } |
291 // Note: It is the caller's responsibility to post notifications for any | 313 // Note: It is the caller's responsibility to post notifications for any |
292 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | 314 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
293 return WebDatabase::COMMIT_NEEDED; | 315 return WebDatabase::COMMIT_NEEDED; |
294 } | 316 } |
295 return WebDatabase::COMMIT_NOT_NEEDED; | 317 return WebDatabase::COMMIT_NOT_NEEDED; |
296 } | 318 } |
297 | 319 |
298 void AutofillWebDataBackend::DestroyAutofillProfileResult( | 320 void AutofillWebDataBackendImpl::DestroyAutofillProfileResult( |
299 const WDTypedResult* result) { | 321 const WDTypedResult* result) { |
300 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); | 322 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); |
301 const WDResult<std::vector<AutofillProfile*> >* r = | 323 const WDResult<std::vector<AutofillProfile*> >* r = |
302 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); | 324 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
303 std::vector<AutofillProfile*> profiles = r->GetValue(); | 325 std::vector<AutofillProfile*> profiles = r->GetValue(); |
304 STLDeleteElements(&profiles); | 326 STLDeleteElements(&profiles); |
305 } | 327 } |
306 | 328 |
307 void AutofillWebDataBackend::DestroyAutofillCreditCardResult( | 329 void AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult( |
308 const WDTypedResult* result) { | 330 const WDTypedResult* result) { |
309 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 331 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
310 const WDResult<std::vector<CreditCard*> >* r = | 332 const WDResult<std::vector<CreditCard*> >* r = |
311 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 333 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
312 | 334 |
313 std::vector<CreditCard*> credit_cards = r->GetValue(); | 335 std::vector<CreditCard*> credit_cards = r->GetValue(); |
314 STLDeleteElements(&credit_cards); | 336 STLDeleteElements(&credit_cards); |
315 } | 337 } |
316 | 338 |
317 } // namespace autofill | 339 } // namespace autofill |
OLD | NEW |