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_service.h" | 5 #include "components/autofill/browser/webdata/autofill_webdata_backend.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_database_service.h" | |
18 | 17 |
19 using base::Bind; | 18 using base::Bind; |
20 using base::Time; | 19 using base::Time; |
21 using content::BrowserThread; | 20 using content::BrowserThread; |
22 | 21 |
23 namespace autofill { | 22 namespace autofill { |
24 | 23 |
25 // static | 24 AutofillWebDataBackend::AutofillWebDataBackend() { |
26 void AutofillWebDataService::NotifyOfMultipleAutofillChanges( | |
27 AutofillWebDataService* web_data_service) { | |
28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
29 | |
30 if (!web_data_service) | |
31 return; | |
32 | |
33 BrowserThread::PostTask( | |
34 BrowserThread::UI, FROM_HERE, | |
35 Bind(&AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread, | |
36 make_scoped_refptr(web_data_service))); | |
37 } | 25 } |
38 | 26 |
39 AutofillWebDataService::AutofillWebDataService( | 27 void AutofillWebDataBackend::AddObserver( |
40 scoped_refptr<WebDatabaseService> wdbs, | |
41 const ProfileErrorCallback& callback) | |
42 : WebDataServiceBase(wdbs, callback) { | |
43 } | |
44 | |
45 AutofillWebDataService::AutofillWebDataService() | |
46 : WebDataServiceBase(NULL, | |
47 WebDataServiceBase::ProfileErrorCallback()) { | |
48 } | |
49 | |
50 void AutofillWebDataService::ShutdownOnUIThread() { | |
51 BrowserThread::PostTask( | |
52 BrowserThread::DB, FROM_HERE, | |
53 base::Bind(&AutofillWebDataService::ShutdownOnDBThread, this)); | |
54 WebDataServiceBase::ShutdownOnUIThread(); | |
55 } | |
56 | |
57 void AutofillWebDataService::AddFormFields( | |
58 const std::vector<FormFieldData>& fields) { | |
59 wdbs_->ScheduleDBTask(FROM_HERE, | |
60 Bind(&AutofillWebDataService::AddFormElementsImpl, this, fields)); | |
61 } | |
62 | |
63 WebDataServiceBase::Handle AutofillWebDataService::GetFormValuesForElementName( | |
64 const base::string16& name, const base::string16& prefix, int limit, | |
65 WebDataServiceConsumer* consumer) { | |
66 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | |
67 Bind(&AutofillWebDataService::GetFormValuesForElementNameImpl, | |
68 this, name, prefix, limit), consumer); | |
69 } | |
70 | |
71 void AutofillWebDataService::RemoveFormElementsAddedBetween( | |
72 const Time& delete_begin, const Time& delete_end) { | |
73 wdbs_->ScheduleDBTask(FROM_HERE, | |
74 Bind(&AutofillWebDataService::RemoveFormElementsAddedBetweenImpl, | |
75 this, delete_begin, delete_end)); | |
76 } | |
77 | |
78 void AutofillWebDataService::RemoveExpiredFormElements() { | |
79 wdbs_->ScheduleDBTask(FROM_HERE, | |
80 Bind(&AutofillWebDataService::RemoveExpiredFormElementsImpl, this)); | |
81 } | |
82 | |
83 void AutofillWebDataService::RemoveFormValueForElementName( | |
84 const base::string16& name, const base::string16& value) { | |
85 wdbs_->ScheduleDBTask(FROM_HERE, | |
86 Bind(&AutofillWebDataService::RemoveFormValueForElementNameImpl, | |
87 this, name, value)); | |
88 } | |
89 | |
90 void AutofillWebDataService::AddAutofillProfile( | |
91 const AutofillProfile& profile) { | |
92 wdbs_->ScheduleDBTask(FROM_HERE, | |
93 Bind(&AutofillWebDataService::AddAutofillProfileImpl, this, profile)); | |
94 } | |
95 | |
96 void AutofillWebDataService::UpdateAutofillProfile( | |
97 const AutofillProfile& profile) { | |
98 wdbs_->ScheduleDBTask(FROM_HERE, | |
99 Bind(&AutofillWebDataService::UpdateAutofillProfileImpl, | |
100 this, profile)); | |
101 } | |
102 | |
103 void AutofillWebDataService::RemoveAutofillProfile( | |
104 const std::string& guid) { | |
105 wdbs_->ScheduleDBTask(FROM_HERE, | |
106 Bind(&AutofillWebDataService::RemoveAutofillProfileImpl, this, guid)); | |
107 } | |
108 | |
109 WebDataServiceBase::Handle AutofillWebDataService::GetAutofillProfiles( | |
110 WebDataServiceConsumer* consumer) { | |
111 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | |
112 Bind(&AutofillWebDataService::GetAutofillProfilesImpl, this), | |
113 consumer); | |
114 } | |
115 | |
116 void AutofillWebDataService::AddCreditCard(const CreditCard& credit_card) { | |
117 wdbs_->ScheduleDBTask( | |
118 FROM_HERE, | |
119 Bind(&AutofillWebDataService::AddCreditCardImpl, this, credit_card)); | |
120 } | |
121 | |
122 void AutofillWebDataService::UpdateCreditCard( | |
123 const CreditCard& credit_card) { | |
124 wdbs_->ScheduleDBTask( | |
125 FROM_HERE, | |
126 Bind(&AutofillWebDataService::UpdateCreditCardImpl, this, credit_card)); | |
127 } | |
128 | |
129 void AutofillWebDataService::RemoveCreditCard(const std::string& guid) { | |
130 wdbs_->ScheduleDBTask( | |
131 FROM_HERE, | |
132 Bind(&AutofillWebDataService::RemoveCreditCardImpl, this, guid)); | |
133 } | |
134 | |
135 WebDataServiceBase::Handle AutofillWebDataService::GetCreditCards( | |
136 WebDataServiceConsumer* consumer) { | |
137 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | |
138 Bind(&AutofillWebDataService::GetCreditCardsImpl, this), consumer); | |
139 } | |
140 | |
141 void AutofillWebDataService::RemoveAutofillDataModifiedBetween( | |
142 const Time& delete_begin, | |
143 const Time& delete_end) { | |
144 wdbs_->ScheduleDBTask( | |
145 FROM_HERE, | |
146 Bind(&AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl, | |
147 this, delete_begin, delete_end)); | |
148 } | |
149 | |
150 void AutofillWebDataService::AddObserver( | |
151 AutofillWebDataServiceObserverOnDBThread* observer) { | 28 AutofillWebDataServiceObserverOnDBThread* observer) { |
152 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 29 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
153 db_observer_list_.AddObserver(observer); | 30 db_observer_list_.AddObserver(observer); |
154 } | 31 } |
155 | 32 |
156 void AutofillWebDataService::RemoveObserver( | 33 void AutofillWebDataBackend::RemoveObserver( |
157 AutofillWebDataServiceObserverOnDBThread* observer) { | 34 AutofillWebDataServiceObserverOnDBThread* observer) { |
158 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 35 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
159 db_observer_list_.RemoveObserver(observer); | 36 db_observer_list_.RemoveObserver(observer); |
160 } | 37 } |
161 | 38 |
162 void AutofillWebDataService::AddObserver( | 39 AutofillWebDataBackend::~AutofillWebDataBackend() { |
163 AutofillWebDataServiceObserverOnUIThread* observer) { | |
164 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
165 ui_observer_list_.AddObserver(observer); | |
166 } | 40 } |
167 | 41 |
168 void AutofillWebDataService::RemoveObserver( | 42 WebDatabase::State AutofillWebDataBackend::AddFormElements( |
169 AutofillWebDataServiceObserverOnUIThread* observer) { | |
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
171 ui_observer_list_.RemoveObserver(observer); | |
172 } | |
173 | |
174 base::SupportsUserData* AutofillWebDataService::GetDBUserData() { | |
175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
176 if (!db_thread_user_data_) | |
177 db_thread_user_data_.reset(new SupportsUserDataAggregatable()); | |
178 return db_thread_user_data_.get(); | |
179 } | |
180 | |
181 void AutofillWebDataService::ShutdownOnDBThread() { | |
182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
183 db_thread_user_data_.reset(); | |
184 } | |
185 | |
186 AutofillWebDataService::~AutofillWebDataService() { | |
187 DCHECK(!db_thread_user_data_.get()) << "Forgot to call ShutdownOnUIThread?"; | |
188 } | |
189 | |
190 //////////////////////////////////////////////////////////////////////////////// | |
191 // | |
192 // Autofill implementation. | |
193 // | |
194 //////////////////////////////////////////////////////////////////////////////// | |
195 | |
196 WebDatabase::State AutofillWebDataService::AddFormElementsImpl( | |
197 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 43 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
198 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
199 AutofillChangeList changes; | 45 AutofillChangeList changes; |
200 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( | 46 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( |
201 fields, &changes)) { | 47 fields, &changes)) { |
202 NOTREACHED(); | 48 NOTREACHED(); |
203 return WebDatabase::COMMIT_NOT_NEEDED; | 49 return WebDatabase::COMMIT_NOT_NEEDED; |
204 } | 50 } |
205 | 51 |
206 // Post the notifications including the list of affected keys. | 52 // Post the notifications including the list of affected keys. |
207 // This is sent here so that work resulting from this notification will be | 53 // This is sent here so that work resulting from this notification will be |
208 // done on the DB thread, and not the UI thread. | 54 // done on the DB thread, and not the UI thread. |
209 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 55 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
210 db_observer_list_, | 56 db_observer_list_, |
211 AutofillEntriesChanged(changes)); | 57 AutofillEntriesChanged(changes)); |
212 | 58 |
213 return WebDatabase::COMMIT_NEEDED; | 59 return WebDatabase::COMMIT_NEEDED; |
214 } | 60 } |
215 | 61 |
216 scoped_ptr<WDTypedResult> | 62 scoped_ptr<WDTypedResult> |
217 AutofillWebDataService::GetFormValuesForElementNameImpl( | 63 AutofillWebDataBackend::GetFormValuesForElementName( |
218 const base::string16& name, const base::string16& prefix, int limit, | 64 const base::string16& name, const base::string16& prefix, int limit, |
219 WebDatabase* db) { | 65 WebDatabase* db) { |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
221 std::vector<base::string16> values; | 67 std::vector<base::string16> values; |
222 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( | 68 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( |
223 name, prefix, &values, limit); | 69 name, prefix, &values, limit); |
224 return scoped_ptr<WDTypedResult>( | 70 return scoped_ptr<WDTypedResult>( |
225 new WDResult<std::vector<base::string16> >(AUTOFILL_VALUE_RESULT, | 71 new WDResult<std::vector<base::string16> >(AUTOFILL_VALUE_RESULT, |
226 values)); | 72 values)); |
227 } | 73 } |
228 | 74 |
229 WebDatabase::State AutofillWebDataService::RemoveFormElementsAddedBetweenImpl( | 75 WebDatabase::State AutofillWebDataBackend::RemoveFormElementsAddedBetween( |
230 const base::Time& delete_begin, const base::Time& delete_end, | 76 const base::Time& delete_begin, const base::Time& delete_end, |
231 WebDatabase* db) { | 77 WebDatabase* db) { |
232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
233 AutofillChangeList changes; | 79 AutofillChangeList changes; |
234 | 80 |
235 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( | 81 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( |
236 delete_begin, delete_end, &changes)) { | 82 delete_begin, delete_end, &changes)) { |
237 if (!changes.empty()) { | 83 if (!changes.empty()) { |
238 // Post the notifications including the list of affected keys. | 84 // Post the notifications including the list of affected keys. |
239 // This is sent here so that work resulting from this notification | 85 // This is sent here so that work resulting from this notification |
240 // will be done on the DB thread, and not the UI thread. | 86 // will be done on the DB thread, and not the UI thread. |
241 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 87 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
242 db_observer_list_, | 88 db_observer_list_, |
243 AutofillEntriesChanged(changes)); | 89 AutofillEntriesChanged(changes)); |
244 } | 90 } |
245 return WebDatabase::COMMIT_NEEDED; | 91 return WebDatabase::COMMIT_NEEDED; |
246 } | 92 } |
247 return WebDatabase::COMMIT_NOT_NEEDED; | 93 return WebDatabase::COMMIT_NOT_NEEDED; |
248 } | 94 } |
249 | 95 |
250 WebDatabase::State AutofillWebDataService::RemoveExpiredFormElementsImpl( | 96 WebDatabase::State AutofillWebDataBackend::RemoveExpiredFormElements( |
251 WebDatabase* db) { | 97 WebDatabase* db) { |
252 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
253 AutofillChangeList changes; | 99 AutofillChangeList changes; |
254 | 100 |
255 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { | 101 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { |
256 if (!changes.empty()) { | 102 if (!changes.empty()) { |
257 // Post the notifications including the list of affected keys. | 103 // Post the notifications including the list of affected keys. |
258 // This is sent here so that work resulting from this notification | 104 // This is sent here so that work resulting from this notification |
259 // will be done on the DB thread, and not the UI thread. | 105 // will be done on the DB thread, and not the UI thread. |
260 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 106 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
261 db_observer_list_, | 107 db_observer_list_, |
262 AutofillEntriesChanged(changes)); | 108 AutofillEntriesChanged(changes)); |
263 } | 109 } |
264 return WebDatabase::COMMIT_NEEDED; | 110 return WebDatabase::COMMIT_NEEDED; |
265 } | 111 } |
266 return WebDatabase::COMMIT_NOT_NEEDED; | 112 return WebDatabase::COMMIT_NOT_NEEDED; |
267 } | 113 } |
268 | 114 |
269 WebDatabase::State AutofillWebDataService::RemoveFormValueForElementNameImpl( | 115 WebDatabase::State AutofillWebDataBackend::RemoveFormValueForElementName( |
270 const base::string16& name, const base::string16& value, WebDatabase* db) { | 116 const base::string16& name, const base::string16& value, WebDatabase* db) { |
271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
272 | 118 |
273 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { | 119 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { |
274 AutofillChangeList changes; | 120 AutofillChangeList changes; |
275 changes.push_back( | 121 changes.push_back( |
276 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); | 122 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); |
277 | 123 |
278 // Post the notifications including the list of affected keys. | 124 // Post the notifications including the list of affected keys. |
279 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 125 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
280 db_observer_list_, | 126 db_observer_list_, |
281 AutofillEntriesChanged(changes)); | 127 AutofillEntriesChanged(changes)); |
282 | 128 |
283 return WebDatabase::COMMIT_NEEDED; | 129 return WebDatabase::COMMIT_NEEDED; |
284 } | 130 } |
285 return WebDatabase::COMMIT_NOT_NEEDED; | 131 return WebDatabase::COMMIT_NOT_NEEDED; |
286 } | 132 } |
287 | 133 |
288 WebDatabase::State AutofillWebDataService::AddAutofillProfileImpl( | 134 WebDatabase::State AutofillWebDataBackend::AddAutofillProfile( |
289 const AutofillProfile& profile, WebDatabase* db) { | 135 const AutofillProfile& profile, WebDatabase* db) { |
290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
291 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { | 137 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { |
292 NOTREACHED(); | 138 NOTREACHED(); |
293 return WebDatabase::COMMIT_NOT_NEEDED; | 139 return WebDatabase::COMMIT_NOT_NEEDED; |
294 } | 140 } |
295 | 141 |
296 // Send GUID-based notification. | 142 // Send GUID-based notification. |
297 AutofillProfileChange change( | 143 AutofillProfileChange change( |
298 AutofillProfileChange::ADD, profile.guid(), &profile); | 144 AutofillProfileChange::ADD, profile.guid(), &profile); |
299 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 145 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
300 db_observer_list_, | 146 db_observer_list_, |
301 AutofillProfileChanged(change)); | 147 AutofillProfileChanged(change)); |
302 | 148 |
303 return WebDatabase::COMMIT_NEEDED; | 149 return WebDatabase::COMMIT_NEEDED; |
304 } | 150 } |
305 | 151 |
306 WebDatabase::State AutofillWebDataService::UpdateAutofillProfileImpl( | 152 WebDatabase::State AutofillWebDataBackend::UpdateAutofillProfile( |
307 const AutofillProfile& profile, WebDatabase* db) { | 153 const AutofillProfile& profile, WebDatabase* db) { |
308 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
309 // Only perform the update if the profile exists. It is currently | 155 // Only perform the update if the profile exists. It is currently |
310 // valid to try to update a missing profile. We simply drop the write and | 156 // valid to try to update a missing profile. We simply drop the write and |
311 // the caller will detect this on the next refresh. | 157 // the caller will detect this on the next refresh. |
312 AutofillProfile* original_profile = NULL; | 158 AutofillProfile* original_profile = NULL; |
313 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), | 159 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), |
314 &original_profile)) { | 160 &original_profile)) { |
315 return WebDatabase::COMMIT_NOT_NEEDED; | 161 return WebDatabase::COMMIT_NOT_NEEDED; |
316 } | 162 } |
317 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | 163 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
318 | 164 |
319 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( | 165 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( |
320 profile)) { | 166 profile)) { |
321 NOTREACHED(); | 167 NOTREACHED(); |
322 return WebDatabase::COMMIT_NEEDED; | 168 return WebDatabase::COMMIT_NEEDED; |
323 } | 169 } |
324 | 170 |
325 // Send GUID-based notification. | 171 // Send GUID-based notification. |
326 AutofillProfileChange change( | 172 AutofillProfileChange change( |
327 AutofillProfileChange::UPDATE, profile.guid(), &profile); | 173 AutofillProfileChange::UPDATE, profile.guid(), &profile); |
328 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 174 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
329 db_observer_list_, | 175 db_observer_list_, |
330 AutofillProfileChanged(change)); | 176 AutofillProfileChanged(change)); |
331 | 177 |
332 return WebDatabase::COMMIT_NEEDED; | 178 return WebDatabase::COMMIT_NEEDED; |
333 } | 179 } |
334 | 180 |
335 WebDatabase::State AutofillWebDataService::RemoveAutofillProfileImpl( | 181 WebDatabase::State AutofillWebDataBackend::RemoveAutofillProfile( |
336 const std::string& guid, WebDatabase* db) { | 182 const std::string& guid, WebDatabase* db) { |
337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
338 AutofillProfile* profile = NULL; | 184 AutofillProfile* profile = NULL; |
339 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { | 185 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { |
340 NOTREACHED(); | 186 NOTREACHED(); |
341 return WebDatabase::COMMIT_NOT_NEEDED; | 187 return WebDatabase::COMMIT_NOT_NEEDED; |
342 } | 188 } |
343 scoped_ptr<AutofillProfile> scoped_profile(profile); | 189 scoped_ptr<AutofillProfile> scoped_profile(profile); |
344 | 190 |
345 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { | 191 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { |
346 NOTREACHED(); | 192 NOTREACHED(); |
347 return WebDatabase::COMMIT_NOT_NEEDED; | 193 return WebDatabase::COMMIT_NOT_NEEDED; |
348 } | 194 } |
349 | 195 |
350 // Send GUID-based notification. | 196 // Send GUID-based notification. |
351 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | 197 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
352 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 198 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
353 db_observer_list_, | 199 db_observer_list_, |
354 AutofillProfileChanged(change)); | 200 AutofillProfileChanged(change)); |
355 | 201 |
356 return WebDatabase::COMMIT_NEEDED; | 202 return WebDatabase::COMMIT_NEEDED; |
357 } | 203 } |
358 | 204 |
359 scoped_ptr<WDTypedResult> AutofillWebDataService::GetAutofillProfilesImpl( | 205 scoped_ptr<WDTypedResult> AutofillWebDataBackend::GetAutofillProfiles( |
360 WebDatabase* db) { | 206 WebDatabase* db) { |
361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
362 std::vector<AutofillProfile*> profiles; | 208 std::vector<AutofillProfile*> profiles; |
363 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); | 209 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); |
364 return scoped_ptr<WDTypedResult>( | 210 return scoped_ptr<WDTypedResult>( |
365 new WDDestroyableResult<std::vector<AutofillProfile*> >( | 211 new WDDestroyableResult<std::vector<AutofillProfile*> >( |
366 AUTOFILL_PROFILES_RESULT, | 212 AUTOFILL_PROFILES_RESULT, |
367 profiles, | 213 profiles, |
368 base::Bind(&AutofillWebDataService::DestroyAutofillProfileResult, | 214 base::Bind(&AutofillWebDataBackend::DestroyAutofillProfileResult, |
369 base::Unretained(this)))); | 215 base::Unretained(this)))); |
370 } | 216 } |
371 | 217 |
372 WebDatabase::State AutofillWebDataService::AddCreditCardImpl( | 218 WebDatabase::State AutofillWebDataBackend::AddCreditCard( |
373 const CreditCard& credit_card, WebDatabase* db) { | 219 const CreditCard& credit_card, WebDatabase* db) { |
374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
375 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { | 221 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { |
376 NOTREACHED(); | 222 NOTREACHED(); |
377 return WebDatabase::COMMIT_NOT_NEEDED; | 223 return WebDatabase::COMMIT_NOT_NEEDED; |
378 } | 224 } |
379 | 225 |
380 return WebDatabase::COMMIT_NEEDED; | 226 return WebDatabase::COMMIT_NEEDED; |
381 } | 227 } |
382 | 228 |
383 WebDatabase::State AutofillWebDataService::UpdateCreditCardImpl( | 229 WebDatabase::State AutofillWebDataBackend::UpdateCreditCard( |
384 const CreditCard& credit_card, WebDatabase* db) { | 230 const CreditCard& credit_card, WebDatabase* db) { |
385 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
386 // It is currently valid to try to update a missing profile. We simply drop | 232 // It is currently valid to try to update a missing profile. We simply drop |
387 // the write and the caller will detect this on the next refresh. | 233 // the write and the caller will detect this on the next refresh. |
388 CreditCard* original_credit_card = NULL; | 234 CreditCard* original_credit_card = NULL; |
389 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), | 235 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), |
390 &original_credit_card)) { | 236 &original_credit_card)) { |
391 return WebDatabase::COMMIT_NOT_NEEDED; | 237 return WebDatabase::COMMIT_NOT_NEEDED; |
392 } | 238 } |
393 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); | 239 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
394 | 240 |
395 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { | 241 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { |
396 NOTREACHED(); | 242 NOTREACHED(); |
397 return WebDatabase::COMMIT_NOT_NEEDED; | 243 return WebDatabase::COMMIT_NOT_NEEDED; |
398 } | 244 } |
399 return WebDatabase::COMMIT_NEEDED; | 245 return WebDatabase::COMMIT_NEEDED; |
400 } | 246 } |
401 | 247 |
402 WebDatabase::State AutofillWebDataService::RemoveCreditCardImpl( | 248 WebDatabase::State AutofillWebDataBackend::RemoveCreditCard( |
403 const std::string& guid, WebDatabase* db) { | 249 const std::string& guid, WebDatabase* db) { |
404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
405 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { | 251 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { |
406 NOTREACHED(); | 252 NOTREACHED(); |
407 return WebDatabase::COMMIT_NOT_NEEDED; | 253 return WebDatabase::COMMIT_NOT_NEEDED; |
408 } | 254 } |
409 return WebDatabase::COMMIT_NEEDED; | 255 return WebDatabase::COMMIT_NEEDED; |
410 } | 256 } |
411 | 257 |
412 scoped_ptr<WDTypedResult> AutofillWebDataService::GetCreditCardsImpl( | 258 scoped_ptr<WDTypedResult> AutofillWebDataBackend::GetCreditCards( |
413 WebDatabase* db) { | 259 WebDatabase* db) { |
414 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
415 std::vector<CreditCard*> credit_cards; | 261 std::vector<CreditCard*> credit_cards; |
416 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); | 262 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); |
417 return scoped_ptr<WDTypedResult>( | 263 return scoped_ptr<WDTypedResult>( |
418 new WDDestroyableResult<std::vector<CreditCard*> >( | 264 new WDDestroyableResult<std::vector<CreditCard*> >( |
419 AUTOFILL_CREDITCARDS_RESULT, | 265 AUTOFILL_CREDITCARDS_RESULT, |
420 credit_cards, | 266 credit_cards, |
421 base::Bind(&AutofillWebDataService::DestroyAutofillCreditCardResult, | 267 base::Bind(&AutofillWebDataBackend::DestroyAutofillCreditCardResult, |
422 base::Unretained(this)))); | 268 base::Unretained(this)))); |
423 } | 269 } |
424 | 270 |
425 WebDatabase::State | 271 WebDatabase::State |
426 AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl( | 272 AutofillWebDataBackend::RemoveAutofillDataModifiedBetween( |
427 const base::Time& delete_begin, | 273 const base::Time& delete_begin, |
428 const base::Time& delete_end, | 274 const base::Time& delete_end, |
429 WebDatabase* db) { | 275 WebDatabase* db) { |
430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
431 std::vector<std::string> profile_guids; | 277 std::vector<std::string> profile_guids; |
432 std::vector<std::string> credit_card_guids; | 278 std::vector<std::string> credit_card_guids; |
433 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween( | 279 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween( |
434 delete_begin, | 280 delete_begin, |
435 delete_end, | 281 delete_end, |
436 &profile_guids, | 282 &profile_guids, |
437 &credit_card_guids)) { | 283 &credit_card_guids)) { |
438 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 284 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
439 iter != profile_guids.end(); ++iter) { | 285 iter != profile_guids.end(); ++iter) { |
440 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL); | 286 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL); |
441 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 287 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
442 db_observer_list_, | 288 db_observer_list_, |
443 AutofillProfileChanged(change)); | 289 AutofillProfileChanged(change)); |
444 } | 290 } |
445 // Note: It is the caller's responsibility to post notifications for any | 291 // Note: It is the caller's responsibility to post notifications for any |
446 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | 292 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
447 return WebDatabase::COMMIT_NEEDED; | 293 return WebDatabase::COMMIT_NEEDED; |
448 } | 294 } |
449 return WebDatabase::COMMIT_NOT_NEEDED; | 295 return WebDatabase::COMMIT_NOT_NEEDED; |
450 } | 296 } |
451 | 297 |
452 void AutofillWebDataService::DestroyAutofillProfileResult( | 298 void AutofillWebDataBackend::DestroyAutofillProfileResult( |
453 const WDTypedResult* result) { | 299 const WDTypedResult* result) { |
454 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); | 300 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); |
455 const WDResult<std::vector<AutofillProfile*> >* r = | 301 const WDResult<std::vector<AutofillProfile*> >* r = |
456 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); | 302 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
457 std::vector<AutofillProfile*> profiles = r->GetValue(); | 303 std::vector<AutofillProfile*> profiles = r->GetValue(); |
458 STLDeleteElements(&profiles); | 304 STLDeleteElements(&profiles); |
459 } | 305 } |
460 | 306 |
461 void AutofillWebDataService::DestroyAutofillCreditCardResult( | 307 void AutofillWebDataBackend::DestroyAutofillCreditCardResult( |
462 const WDTypedResult* result) { | 308 const WDTypedResult* result) { |
463 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 309 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
464 const WDResult<std::vector<CreditCard*> >* r = | 310 const WDResult<std::vector<CreditCard*> >* r = |
465 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 311 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
466 | 312 |
467 std::vector<CreditCard*> credit_cards = r->GetValue(); | 313 std::vector<CreditCard*> credit_cards = r->GetValue(); |
468 STLDeleteElements(&credit_cards); | 314 STLDeleteElements(&credit_cards); |
469 } | 315 } |
470 | 316 |
471 void AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread() { | |
472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
473 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread, | |
474 ui_observer_list_, | |
475 AutofillMultipleChanged()); | |
476 } | |
477 | |
478 } // namespace autofill | 317 } // namespace autofill |
OLD | NEW |