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