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_(new base::Closure(on_changed_callback)) { | |
Ilya Sherman
2013/05/09 05:04:24
nit: Why are you storing the as a pointer rather t
Cait (Slow)
2013/05/09 18:29:54
Done.
| |
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(); | |
Ilya Sherman
2013/05/09 05:04:24
nit: De-indent two spaces.
Cait (Slow)
2013/05/09 18:29:54
Done.
| |
50 } | |
51 | |
52 void AutofillWebDataBackendImpl::RemoveExpiredFormElementsWrapper() { | |
53 if (RemoveExpiredFormElements(web_database_backend_->database()) == | |
54 WebDatabase::COMMIT_NEEDED) { | |
55 web_database_backend_->database()->CommitTransaction(); | |
56 web_database_backend_->database()->BeginTransaction(); | |
57 } | |
Ilya Sherman
2013/05/09 05:04:24
Is this new behavior that's being added in this CL
Cait (Slow)
2013/05/09 18:29:54
This is duplicating behavior in WebDataServiceBack
| |
58 } | |
59 | |
60 void AutofillWebDataBackendImpl::NotifyOfMultipleAutofillChanges() { | |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | |
62 BrowserThread::PostTask(BrowserThread::UI, | |
63 FROM_HERE, | |
64 *(on_changed_callback_.get())); | |
Ilya Sherman
2013/05/09 05:04:24
nit: I don't think the .get() is necessary.
Cait (Slow)
2013/05/09 18:29:54
Done.
| |
65 } | |
66 | |
67 WebDatabase::State AutofillWebDataBackendImpl::AddFormElements( | |
43 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 68 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 69 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
45 AutofillChangeList changes; | 70 AutofillChangeList changes; |
46 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( | 71 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( |
47 fields, &changes)) { | 72 fields, &changes)) { |
48 NOTREACHED(); | 73 NOTREACHED(); |
49 return WebDatabase::COMMIT_NOT_NEEDED; | 74 return WebDatabase::COMMIT_NOT_NEEDED; |
50 } | 75 } |
51 | 76 |
52 // Post the notifications including the list of affected keys. | 77 // Post the notifications including the list of affected keys. |
53 // This is sent here so that work resulting from this notification will be | 78 // This is sent here so that work resulting from this notification will be |
54 // done on the DB thread, and not the UI thread. | 79 // done on the DB thread, and not the UI thread. |
55 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 80 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
56 db_observer_list_, | 81 db_observer_list_, |
57 AutofillEntriesChanged(changes)); | 82 AutofillEntriesChanged(changes)); |
58 | 83 |
59 return WebDatabase::COMMIT_NEEDED; | 84 return WebDatabase::COMMIT_NEEDED; |
60 } | 85 } |
61 | 86 |
62 scoped_ptr<WDTypedResult> | 87 scoped_ptr<WDTypedResult> |
63 AutofillWebDataBackend::GetFormValuesForElementName( | 88 AutofillWebDataBackendImpl::GetFormValuesForElementName( |
64 const base::string16& name, const base::string16& prefix, int limit, | 89 const base::string16& name, const base::string16& prefix, int limit, |
65 WebDatabase* db) { | 90 WebDatabase* db) { |
66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
67 std::vector<base::string16> values; | 92 std::vector<base::string16> values; |
68 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( | 93 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( |
69 name, prefix, &values, limit); | 94 name, prefix, &values, limit); |
70 return scoped_ptr<WDTypedResult>( | 95 return scoped_ptr<WDTypedResult>( |
71 new WDResult<std::vector<base::string16> >(AUTOFILL_VALUE_RESULT, | 96 new WDResult<std::vector<base::string16> >(AUTOFILL_VALUE_RESULT, |
72 values)); | 97 values)); |
73 } | 98 } |
74 | 99 |
75 WebDatabase::State AutofillWebDataBackend::RemoveFormElementsAddedBetween( | 100 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormElementsAddedBetween( |
76 const base::Time& delete_begin, const base::Time& delete_end, | 101 const base::Time& delete_begin, const base::Time& delete_end, |
77 WebDatabase* db) { | 102 WebDatabase* db) { |
78 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 103 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
79 AutofillChangeList changes; | 104 AutofillChangeList changes; |
80 | 105 |
81 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( | 106 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( |
82 delete_begin, delete_end, &changes)) { | 107 delete_begin, delete_end, &changes)) { |
83 if (!changes.empty()) { | 108 if (!changes.empty()) { |
84 // Post the notifications including the list of affected keys. | 109 // Post the notifications including the list of affected keys. |
85 // This is sent here so that work resulting from this notification | 110 // This is sent here so that work resulting from this notification |
86 // will be done on the DB thread, and not the UI thread. | 111 // will be done on the DB thread, and not the UI thread. |
87 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 112 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
88 db_observer_list_, | 113 db_observer_list_, |
89 AutofillEntriesChanged(changes)); | 114 AutofillEntriesChanged(changes)); |
90 } | 115 } |
91 return WebDatabase::COMMIT_NEEDED; | 116 return WebDatabase::COMMIT_NEEDED; |
92 } | 117 } |
93 return WebDatabase::COMMIT_NOT_NEEDED; | 118 return WebDatabase::COMMIT_NOT_NEEDED; |
94 } | 119 } |
95 | 120 |
96 WebDatabase::State AutofillWebDataBackend::RemoveExpiredFormElements( | 121 WebDatabase::State AutofillWebDataBackendImpl::RemoveExpiredFormElements( |
97 WebDatabase* db) { | 122 WebDatabase* db) { |
98 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 123 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
99 AutofillChangeList changes; | 124 AutofillChangeList changes; |
100 | 125 |
101 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { | 126 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { |
102 if (!changes.empty()) { | 127 if (!changes.empty()) { |
103 // Post the notifications including the list of affected keys. | 128 // Post the notifications including the list of affected keys. |
104 // This is sent here so that work resulting from this notification | 129 // This is sent here so that work resulting from this notification |
105 // will be done on the DB thread, and not the UI thread. | 130 // will be done on the DB thread, and not the UI thread. |
106 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 131 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
107 db_observer_list_, | 132 db_observer_list_, |
108 AutofillEntriesChanged(changes)); | 133 AutofillEntriesChanged(changes)); |
109 } | 134 } |
110 return WebDatabase::COMMIT_NEEDED; | 135 return WebDatabase::COMMIT_NEEDED; |
111 } | 136 } |
112 return WebDatabase::COMMIT_NOT_NEEDED; | 137 return WebDatabase::COMMIT_NOT_NEEDED; |
113 } | 138 } |
114 | 139 |
115 WebDatabase::State AutofillWebDataBackend::RemoveFormValueForElementName( | 140 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName( |
116 const base::string16& name, const base::string16& value, WebDatabase* db) { | 141 const base::string16& name, const base::string16& value, WebDatabase* db) { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 142 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
118 | 143 |
119 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { | 144 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { |
120 AutofillChangeList changes; | 145 AutofillChangeList changes; |
121 changes.push_back( | 146 changes.push_back( |
122 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); | 147 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); |
123 | 148 |
124 // Post the notifications including the list of affected keys. | 149 // Post the notifications including the list of affected keys. |
125 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 150 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
126 db_observer_list_, | 151 db_observer_list_, |
127 AutofillEntriesChanged(changes)); | 152 AutofillEntriesChanged(changes)); |
128 | 153 |
129 return WebDatabase::COMMIT_NEEDED; | 154 return WebDatabase::COMMIT_NEEDED; |
130 } | 155 } |
131 return WebDatabase::COMMIT_NOT_NEEDED; | 156 return WebDatabase::COMMIT_NOT_NEEDED; |
132 } | 157 } |
133 | 158 |
134 WebDatabase::State AutofillWebDataBackend::AddAutofillProfile( | 159 WebDatabase::State AutofillWebDataBackendImpl::AddAutofillProfile( |
135 const AutofillProfile& profile, WebDatabase* db) { | 160 const AutofillProfile& profile, WebDatabase* db) { |
136 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
137 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { | 162 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { |
138 NOTREACHED(); | 163 NOTREACHED(); |
139 return WebDatabase::COMMIT_NOT_NEEDED; | 164 return WebDatabase::COMMIT_NOT_NEEDED; |
140 } | 165 } |
141 | 166 |
142 // Send GUID-based notification. | 167 // Send GUID-based notification. |
143 AutofillProfileChange change( | 168 AutofillProfileChange change( |
144 AutofillProfileChange::ADD, profile.guid(), &profile); | 169 AutofillProfileChange::ADD, profile.guid(), &profile); |
145 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 170 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
146 db_observer_list_, | 171 db_observer_list_, |
147 AutofillProfileChanged(change)); | 172 AutofillProfileChanged(change)); |
148 | 173 |
149 return WebDatabase::COMMIT_NEEDED; | 174 return WebDatabase::COMMIT_NEEDED; |
150 } | 175 } |
151 | 176 |
152 WebDatabase::State AutofillWebDataBackend::UpdateAutofillProfile( | 177 WebDatabase::State AutofillWebDataBackendImpl::UpdateAutofillProfile( |
153 const AutofillProfile& profile, WebDatabase* db) { | 178 const AutofillProfile& profile, WebDatabase* db) { |
154 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
155 // Only perform the update if the profile exists. It is currently | 180 // 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 | 181 // valid to try to update a missing profile. We simply drop the write and |
157 // the caller will detect this on the next refresh. | 182 // the caller will detect this on the next refresh. |
158 AutofillProfile* original_profile = NULL; | 183 AutofillProfile* original_profile = NULL; |
159 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), | 184 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), |
160 &original_profile)) { | 185 &original_profile)) { |
161 return WebDatabase::COMMIT_NOT_NEEDED; | 186 return WebDatabase::COMMIT_NOT_NEEDED; |
162 } | 187 } |
163 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | 188 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
164 | 189 |
165 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( | 190 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( |
166 profile)) { | 191 profile)) { |
167 NOTREACHED(); | 192 NOTREACHED(); |
168 return WebDatabase::COMMIT_NEEDED; | 193 return WebDatabase::COMMIT_NEEDED; |
169 } | 194 } |
170 | 195 |
171 // Send GUID-based notification. | 196 // Send GUID-based notification. |
172 AutofillProfileChange change( | 197 AutofillProfileChange change( |
173 AutofillProfileChange::UPDATE, profile.guid(), &profile); | 198 AutofillProfileChange::UPDATE, profile.guid(), &profile); |
174 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 199 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
175 db_observer_list_, | 200 db_observer_list_, |
176 AutofillProfileChanged(change)); | 201 AutofillProfileChanged(change)); |
177 | 202 |
178 return WebDatabase::COMMIT_NEEDED; | 203 return WebDatabase::COMMIT_NEEDED; |
179 } | 204 } |
180 | 205 |
181 WebDatabase::State AutofillWebDataBackend::RemoveAutofillProfile( | 206 WebDatabase::State AutofillWebDataBackendImpl::RemoveAutofillProfile( |
182 const std::string& guid, WebDatabase* db) { | 207 const std::string& guid, WebDatabase* db) { |
183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 208 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
184 AutofillProfile* profile = NULL; | 209 AutofillProfile* profile = NULL; |
185 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { | 210 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { |
186 NOTREACHED(); | 211 NOTREACHED(); |
187 return WebDatabase::COMMIT_NOT_NEEDED; | 212 return WebDatabase::COMMIT_NOT_NEEDED; |
188 } | 213 } |
189 scoped_ptr<AutofillProfile> scoped_profile(profile); | 214 scoped_ptr<AutofillProfile> scoped_profile(profile); |
190 | 215 |
191 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { | 216 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { |
192 NOTREACHED(); | 217 NOTREACHED(); |
193 return WebDatabase::COMMIT_NOT_NEEDED; | 218 return WebDatabase::COMMIT_NOT_NEEDED; |
194 } | 219 } |
195 | 220 |
196 // Send GUID-based notification. | 221 // Send GUID-based notification. |
197 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | 222 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
198 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 223 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
199 db_observer_list_, | 224 db_observer_list_, |
200 AutofillProfileChanged(change)); | 225 AutofillProfileChanged(change)); |
201 | 226 |
202 return WebDatabase::COMMIT_NEEDED; | 227 return WebDatabase::COMMIT_NEEDED; |
203 } | 228 } |
204 | 229 |
205 scoped_ptr<WDTypedResult> AutofillWebDataBackend::GetAutofillProfiles( | 230 scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetAutofillProfiles( |
206 WebDatabase* db) { | 231 WebDatabase* db) { |
207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 232 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
208 std::vector<AutofillProfile*> profiles; | 233 std::vector<AutofillProfile*> profiles; |
209 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); | 234 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); |
210 return scoped_ptr<WDTypedResult>( | 235 return scoped_ptr<WDTypedResult>( |
211 new WDDestroyableResult<std::vector<AutofillProfile*> >( | 236 new WDDestroyableResult<std::vector<AutofillProfile*> >( |
212 AUTOFILL_PROFILES_RESULT, | 237 AUTOFILL_PROFILES_RESULT, |
213 profiles, | 238 profiles, |
214 base::Bind(&AutofillWebDataBackend::DestroyAutofillProfileResult, | 239 base::Bind(&AutofillWebDataBackendImpl::DestroyAutofillProfileResult, |
215 base::Unretained(this)))); | 240 base::Unretained(this)))); |
216 } | 241 } |
217 | 242 |
218 WebDatabase::State AutofillWebDataBackend::AddCreditCard( | 243 WebDatabase::State AutofillWebDataBackendImpl::AddCreditCard( |
219 const CreditCard& credit_card, WebDatabase* db) { | 244 const CreditCard& credit_card, WebDatabase* db) { |
220 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 245 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
221 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { | 246 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { |
222 NOTREACHED(); | 247 NOTREACHED(); |
223 return WebDatabase::COMMIT_NOT_NEEDED; | 248 return WebDatabase::COMMIT_NOT_NEEDED; |
224 } | 249 } |
225 | 250 |
226 return WebDatabase::COMMIT_NEEDED; | 251 return WebDatabase::COMMIT_NEEDED; |
227 } | 252 } |
228 | 253 |
229 WebDatabase::State AutofillWebDataBackend::UpdateCreditCard( | 254 WebDatabase::State AutofillWebDataBackendImpl::UpdateCreditCard( |
230 const CreditCard& credit_card, WebDatabase* db) { | 255 const CreditCard& credit_card, WebDatabase* db) { |
231 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
232 // It is currently valid to try to update a missing profile. We simply drop | 257 // 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. | 258 // the write and the caller will detect this on the next refresh. |
234 CreditCard* original_credit_card = NULL; | 259 CreditCard* original_credit_card = NULL; |
235 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), | 260 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), |
236 &original_credit_card)) { | 261 &original_credit_card)) { |
237 return WebDatabase::COMMIT_NOT_NEEDED; | 262 return WebDatabase::COMMIT_NOT_NEEDED; |
238 } | 263 } |
239 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); | 264 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
240 | 265 |
241 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { | 266 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { |
242 NOTREACHED(); | 267 NOTREACHED(); |
243 return WebDatabase::COMMIT_NOT_NEEDED; | 268 return WebDatabase::COMMIT_NOT_NEEDED; |
244 } | 269 } |
245 return WebDatabase::COMMIT_NEEDED; | 270 return WebDatabase::COMMIT_NEEDED; |
246 } | 271 } |
247 | 272 |
248 WebDatabase::State AutofillWebDataBackend::RemoveCreditCard( | 273 WebDatabase::State AutofillWebDataBackendImpl::RemoveCreditCard( |
249 const std::string& guid, WebDatabase* db) { | 274 const std::string& guid, WebDatabase* db) { |
250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 275 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
251 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { | 276 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { |
252 NOTREACHED(); | 277 NOTREACHED(); |
253 return WebDatabase::COMMIT_NOT_NEEDED; | 278 return WebDatabase::COMMIT_NOT_NEEDED; |
254 } | 279 } |
255 return WebDatabase::COMMIT_NEEDED; | 280 return WebDatabase::COMMIT_NEEDED; |
256 } | 281 } |
257 | 282 |
258 scoped_ptr<WDTypedResult> AutofillWebDataBackend::GetCreditCards( | 283 scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetCreditCards( |
259 WebDatabase* db) { | 284 WebDatabase* db) { |
260 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 285 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
261 std::vector<CreditCard*> credit_cards; | 286 std::vector<CreditCard*> credit_cards; |
262 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); | 287 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); |
263 return scoped_ptr<WDTypedResult>( | 288 return scoped_ptr<WDTypedResult>( |
264 new WDDestroyableResult<std::vector<CreditCard*> >( | 289 new WDDestroyableResult<std::vector<CreditCard*> >( |
265 AUTOFILL_CREDITCARDS_RESULT, | 290 AUTOFILL_CREDITCARDS_RESULT, |
266 credit_cards, | 291 credit_cards, |
267 base::Bind(&AutofillWebDataBackend::DestroyAutofillCreditCardResult, | 292 base::Bind(&AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult, |
268 base::Unretained(this)))); | 293 base::Unretained(this)))); |
269 } | 294 } |
270 | 295 |
271 WebDatabase::State | 296 WebDatabase::State |
272 AutofillWebDataBackend::RemoveAutofillDataModifiedBetween( | 297 AutofillWebDataBackendImpl::RemoveAutofillDataModifiedBetween( |
273 const base::Time& delete_begin, | 298 const base::Time& delete_begin, |
274 const base::Time& delete_end, | 299 const base::Time& delete_end, |
275 WebDatabase* db) { | 300 WebDatabase* db) { |
276 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 301 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
277 std::vector<std::string> profile_guids; | 302 std::vector<std::string> profile_guids; |
278 std::vector<std::string> credit_card_guids; | 303 std::vector<std::string> credit_card_guids; |
279 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween( | 304 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween( |
280 delete_begin, | 305 delete_begin, |
281 delete_end, | 306 delete_end, |
282 &profile_guids, | 307 &profile_guids, |
283 &credit_card_guids)) { | 308 &credit_card_guids)) { |
284 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 309 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
285 iter != profile_guids.end(); ++iter) { | 310 iter != profile_guids.end(); ++iter) { |
286 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL); | 311 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL); |
287 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, | 312 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
288 db_observer_list_, | 313 db_observer_list_, |
289 AutofillProfileChanged(change)); | 314 AutofillProfileChanged(change)); |
290 } | 315 } |
291 // Note: It is the caller's responsibility to post notifications for any | 316 // Note: It is the caller's responsibility to post notifications for any |
292 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | 317 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
293 return WebDatabase::COMMIT_NEEDED; | 318 return WebDatabase::COMMIT_NEEDED; |
294 } | 319 } |
295 return WebDatabase::COMMIT_NOT_NEEDED; | 320 return WebDatabase::COMMIT_NOT_NEEDED; |
296 } | 321 } |
297 | 322 |
298 void AutofillWebDataBackend::DestroyAutofillProfileResult( | 323 void AutofillWebDataBackendImpl::DestroyAutofillProfileResult( |
299 const WDTypedResult* result) { | 324 const WDTypedResult* result) { |
300 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); | 325 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); |
301 const WDResult<std::vector<AutofillProfile*> >* r = | 326 const WDResult<std::vector<AutofillProfile*> >* r = |
302 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); | 327 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
303 std::vector<AutofillProfile*> profiles = r->GetValue(); | 328 std::vector<AutofillProfile*> profiles = r->GetValue(); |
304 STLDeleteElements(&profiles); | 329 STLDeleteElements(&profiles); |
305 } | 330 } |
306 | 331 |
307 void AutofillWebDataBackend::DestroyAutofillCreditCardResult( | 332 void AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult( |
308 const WDTypedResult* result) { | 333 const WDTypedResult* result) { |
309 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 334 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
310 const WDResult<std::vector<CreditCard*> >* r = | 335 const WDResult<std::vector<CreditCard*> >* r = |
311 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 336 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
312 | 337 |
313 std::vector<CreditCard*> credit_cards = r->GetValue(); | 338 std::vector<CreditCard*> credit_cards = r->GetValue(); |
314 STLDeleteElements(&credit_cards); | 339 STLDeleteElements(&credit_cards); |
315 } | 340 } |
316 | 341 |
317 } // namespace autofill | 342 } // namespace autofill |
OLD | NEW |