Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Side by Side Diff: components/autofill/browser/webdata/autofill_webdata_backend_impl.cc

Issue 14679005: Create an AutofillBackend interface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix WIN Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 scoped_ptr<WDTypedResult> AutofillWebDataBackend::HasFormElements( 97 scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::HasFormElements(
76 WebDatabase* db) { 98 WebDatabase* db) {
77 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 99 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
78 bool value = AutofillTable::FromWebDatabase(db)->HasFormElements(); 100 bool value = AutofillTable::FromWebDatabase(db)->HasFormElements();
79 return scoped_ptr<WDTypedResult>( 101 return scoped_ptr<WDTypedResult>(
80 new WDResult<bool>(AUTOFILL_VALUE_RESULT, value)); 102 new WDResult<bool>(AUTOFILL_VALUE_RESULT, value));
81 } 103 }
82 104
83 WebDatabase::State AutofillWebDataBackend::RemoveFormElementsAddedBetween( 105 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormElementsAddedBetween(
84 const base::Time& delete_begin, const base::Time& delete_end, 106 const base::Time& delete_begin, const base::Time& delete_end,
85 WebDatabase* db) { 107 WebDatabase* db) {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 108 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
87 AutofillChangeList changes; 109 AutofillChangeList changes;
88 110
89 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( 111 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween(
90 delete_begin, delete_end, &changes)) { 112 delete_begin, delete_end, &changes)) {
91 if (!changes.empty()) { 113 if (!changes.empty()) {
92 // Post the notifications including the list of affected keys. 114 // Post the notifications including the list of affected keys.
93 // This is sent here so that work resulting from this notification 115 // This is sent here so that work resulting from this notification
94 // will be done on the DB thread, and not the UI thread. 116 // will be done on the DB thread, and not the UI thread.
95 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 117 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
96 db_observer_list_, 118 db_observer_list_,
97 AutofillEntriesChanged(changes)); 119 AutofillEntriesChanged(changes));
98 } 120 }
99 return WebDatabase::COMMIT_NEEDED; 121 return WebDatabase::COMMIT_NEEDED;
100 } 122 }
101 return WebDatabase::COMMIT_NOT_NEEDED; 123 return WebDatabase::COMMIT_NOT_NEEDED;
102 } 124 }
103 125
104 WebDatabase::State AutofillWebDataBackend::RemoveExpiredFormElements( 126 WebDatabase::State AutofillWebDataBackendImpl::RemoveExpiredFormElements(
105 WebDatabase* db) { 127 WebDatabase* db) {
106 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 128 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
107 AutofillChangeList changes; 129 AutofillChangeList changes;
108 130
109 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { 131 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
110 if (!changes.empty()) { 132 if (!changes.empty()) {
111 // Post the notifications including the list of affected keys. 133 // Post the notifications including the list of affected keys.
112 // This is sent here so that work resulting from this notification 134 // This is sent here so that work resulting from this notification
113 // will be done on the DB thread, and not the UI thread. 135 // will be done on the DB thread, and not the UI thread.
114 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 136 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
115 db_observer_list_, 137 db_observer_list_,
116 AutofillEntriesChanged(changes)); 138 AutofillEntriesChanged(changes));
117 } 139 }
118 return WebDatabase::COMMIT_NEEDED; 140 return WebDatabase::COMMIT_NEEDED;
119 } 141 }
120 return WebDatabase::COMMIT_NOT_NEEDED; 142 return WebDatabase::COMMIT_NOT_NEEDED;
121 } 143 }
122 144
123 WebDatabase::State AutofillWebDataBackend::RemoveFormValueForElementName( 145 WebDatabase::State AutofillWebDataBackendImpl::RemoveFormValueForElementName(
124 const base::string16& name, const base::string16& value, WebDatabase* db) { 146 const base::string16& name, const base::string16& value, WebDatabase* db) {
125 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 147 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
126 148
127 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { 149 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
128 AutofillChangeList changes; 150 AutofillChangeList changes;
129 changes.push_back( 151 changes.push_back(
130 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); 152 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value)));
131 153
132 // Post the notifications including the list of affected keys. 154 // Post the notifications including the list of affected keys.
133 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 155 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
134 db_observer_list_, 156 db_observer_list_,
135 AutofillEntriesChanged(changes)); 157 AutofillEntriesChanged(changes));
136 158
137 return WebDatabase::COMMIT_NEEDED; 159 return WebDatabase::COMMIT_NEEDED;
138 } 160 }
139 return WebDatabase::COMMIT_NOT_NEEDED; 161 return WebDatabase::COMMIT_NOT_NEEDED;
140 } 162 }
141 163
142 WebDatabase::State AutofillWebDataBackend::AddAutofillProfile( 164 WebDatabase::State AutofillWebDataBackendImpl::AddAutofillProfile(
143 const AutofillProfile& profile, WebDatabase* db) { 165 const AutofillProfile& profile, WebDatabase* db) {
144 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
145 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { 167 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) {
146 NOTREACHED(); 168 NOTREACHED();
147 return WebDatabase::COMMIT_NOT_NEEDED; 169 return WebDatabase::COMMIT_NOT_NEEDED;
148 } 170 }
149 171
150 // Send GUID-based notification. 172 // Send GUID-based notification.
151 AutofillProfileChange change( 173 AutofillProfileChange change(
152 AutofillProfileChange::ADD, profile.guid(), &profile); 174 AutofillProfileChange::ADD, profile.guid(), &profile);
153 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 175 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
154 db_observer_list_, 176 db_observer_list_,
155 AutofillProfileChanged(change)); 177 AutofillProfileChanged(change));
156 178
157 return WebDatabase::COMMIT_NEEDED; 179 return WebDatabase::COMMIT_NEEDED;
158 } 180 }
159 181
160 WebDatabase::State AutofillWebDataBackend::UpdateAutofillProfile( 182 WebDatabase::State AutofillWebDataBackendImpl::UpdateAutofillProfile(
161 const AutofillProfile& profile, WebDatabase* db) { 183 const AutofillProfile& profile, WebDatabase* db) {
162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 184 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
163 // Only perform the update if the profile exists. It is currently 185 // Only perform the update if the profile exists. It is currently
164 // valid to try to update a missing profile. We simply drop the write and 186 // valid to try to update a missing profile. We simply drop the write and
165 // the caller will detect this on the next refresh. 187 // the caller will detect this on the next refresh.
166 AutofillProfile* original_profile = NULL; 188 AutofillProfile* original_profile = NULL;
167 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), 189 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(),
168 &original_profile)) { 190 &original_profile)) {
169 return WebDatabase::COMMIT_NOT_NEEDED; 191 return WebDatabase::COMMIT_NOT_NEEDED;
170 } 192 }
171 scoped_ptr<AutofillProfile> scoped_profile(original_profile); 193 scoped_ptr<AutofillProfile> scoped_profile(original_profile);
172 194
173 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( 195 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti(
174 profile)) { 196 profile)) {
175 NOTREACHED(); 197 NOTREACHED();
176 return WebDatabase::COMMIT_NEEDED; 198 return WebDatabase::COMMIT_NEEDED;
177 } 199 }
178 200
179 // Send GUID-based notification. 201 // Send GUID-based notification.
180 AutofillProfileChange change( 202 AutofillProfileChange change(
181 AutofillProfileChange::UPDATE, profile.guid(), &profile); 203 AutofillProfileChange::UPDATE, profile.guid(), &profile);
182 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 204 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
183 db_observer_list_, 205 db_observer_list_,
184 AutofillProfileChanged(change)); 206 AutofillProfileChanged(change));
185 207
186 return WebDatabase::COMMIT_NEEDED; 208 return WebDatabase::COMMIT_NEEDED;
187 } 209 }
188 210
189 WebDatabase::State AutofillWebDataBackend::RemoveAutofillProfile( 211 WebDatabase::State AutofillWebDataBackendImpl::RemoveAutofillProfile(
190 const std::string& guid, WebDatabase* db) { 212 const std::string& guid, WebDatabase* db) {
191 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
192 AutofillProfile* profile = NULL; 214 AutofillProfile* profile = NULL;
193 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { 215 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) {
194 NOTREACHED(); 216 NOTREACHED();
195 return WebDatabase::COMMIT_NOT_NEEDED; 217 return WebDatabase::COMMIT_NOT_NEEDED;
196 } 218 }
197 scoped_ptr<AutofillProfile> scoped_profile(profile); 219 scoped_ptr<AutofillProfile> scoped_profile(profile);
198 220
199 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { 221 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) {
200 NOTREACHED(); 222 NOTREACHED();
201 return WebDatabase::COMMIT_NOT_NEEDED; 223 return WebDatabase::COMMIT_NOT_NEEDED;
202 } 224 }
203 225
204 // Send GUID-based notification. 226 // Send GUID-based notification.
205 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); 227 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL);
206 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 228 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
207 db_observer_list_, 229 db_observer_list_,
208 AutofillProfileChanged(change)); 230 AutofillProfileChanged(change));
209 231
210 return WebDatabase::COMMIT_NEEDED; 232 return WebDatabase::COMMIT_NEEDED;
211 } 233 }
212 234
213 scoped_ptr<WDTypedResult> AutofillWebDataBackend::GetAutofillProfiles( 235 scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetAutofillProfiles(
214 WebDatabase* db) { 236 WebDatabase* db) {
215 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 237 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
216 std::vector<AutofillProfile*> profiles; 238 std::vector<AutofillProfile*> profiles;
217 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); 239 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles);
218 return scoped_ptr<WDTypedResult>( 240 return scoped_ptr<WDTypedResult>(
219 new WDDestroyableResult<std::vector<AutofillProfile*> >( 241 new WDDestroyableResult<std::vector<AutofillProfile*> >(
220 AUTOFILL_PROFILES_RESULT, 242 AUTOFILL_PROFILES_RESULT,
221 profiles, 243 profiles,
222 base::Bind(&AutofillWebDataBackend::DestroyAutofillProfileResult, 244 base::Bind(&AutofillWebDataBackendImpl::DestroyAutofillProfileResult,
223 base::Unretained(this)))); 245 base::Unretained(this))));
224 } 246 }
225 247
226 WebDatabase::State AutofillWebDataBackend::AddCreditCard( 248 WebDatabase::State AutofillWebDataBackendImpl::AddCreditCard(
227 const CreditCard& credit_card, WebDatabase* db) { 249 const CreditCard& credit_card, WebDatabase* db) {
228 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
229 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { 251 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) {
230 NOTREACHED(); 252 NOTREACHED();
231 return WebDatabase::COMMIT_NOT_NEEDED; 253 return WebDatabase::COMMIT_NOT_NEEDED;
232 } 254 }
233 255
234 return WebDatabase::COMMIT_NEEDED; 256 return WebDatabase::COMMIT_NEEDED;
235 } 257 }
236 258
237 WebDatabase::State AutofillWebDataBackend::UpdateCreditCard( 259 WebDatabase::State AutofillWebDataBackendImpl::UpdateCreditCard(
238 const CreditCard& credit_card, WebDatabase* db) { 260 const CreditCard& credit_card, WebDatabase* db) {
239 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 261 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
240 // It is currently valid to try to update a missing profile. We simply drop 262 // It is currently valid to try to update a missing profile. We simply drop
241 // the write and the caller will detect this on the next refresh. 263 // the write and the caller will detect this on the next refresh.
242 CreditCard* original_credit_card = NULL; 264 CreditCard* original_credit_card = NULL;
243 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), 265 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(),
244 &original_credit_card)) { 266 &original_credit_card)) {
245 return WebDatabase::COMMIT_NOT_NEEDED; 267 return WebDatabase::COMMIT_NOT_NEEDED;
246 } 268 }
247 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); 269 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card);
248 270
249 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { 271 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) {
250 NOTREACHED(); 272 NOTREACHED();
251 return WebDatabase::COMMIT_NOT_NEEDED; 273 return WebDatabase::COMMIT_NOT_NEEDED;
252 } 274 }
253 return WebDatabase::COMMIT_NEEDED; 275 return WebDatabase::COMMIT_NEEDED;
254 } 276 }
255 277
256 WebDatabase::State AutofillWebDataBackend::RemoveCreditCard( 278 WebDatabase::State AutofillWebDataBackendImpl::RemoveCreditCard(
257 const std::string& guid, WebDatabase* db) { 279 const std::string& guid, WebDatabase* db) {
258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
259 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { 281 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) {
260 NOTREACHED(); 282 NOTREACHED();
261 return WebDatabase::COMMIT_NOT_NEEDED; 283 return WebDatabase::COMMIT_NOT_NEEDED;
262 } 284 }
263 return WebDatabase::COMMIT_NEEDED; 285 return WebDatabase::COMMIT_NEEDED;
264 } 286 }
265 287
266 scoped_ptr<WDTypedResult> AutofillWebDataBackend::GetCreditCards( 288 scoped_ptr<WDTypedResult> AutofillWebDataBackendImpl::GetCreditCards(
267 WebDatabase* db) { 289 WebDatabase* db) {
268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
269 std::vector<CreditCard*> credit_cards; 291 std::vector<CreditCard*> credit_cards;
270 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); 292 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards);
271 return scoped_ptr<WDTypedResult>( 293 return scoped_ptr<WDTypedResult>(
272 new WDDestroyableResult<std::vector<CreditCard*> >( 294 new WDDestroyableResult<std::vector<CreditCard*> >(
273 AUTOFILL_CREDITCARDS_RESULT, 295 AUTOFILL_CREDITCARDS_RESULT,
274 credit_cards, 296 credit_cards,
275 base::Bind(&AutofillWebDataBackend::DestroyAutofillCreditCardResult, 297 base::Bind(&AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult,
276 base::Unretained(this)))); 298 base::Unretained(this))));
277 } 299 }
278 300
279 WebDatabase::State 301 WebDatabase::State
280 AutofillWebDataBackend::RemoveAutofillDataModifiedBetween( 302 AutofillWebDataBackendImpl::RemoveAutofillDataModifiedBetween(
281 const base::Time& delete_begin, 303 const base::Time& delete_begin,
282 const base::Time& delete_end, 304 const base::Time& delete_end,
283 WebDatabase* db) { 305 WebDatabase* db) {
284 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
285 std::vector<std::string> profile_guids; 307 std::vector<std::string> profile_guids;
286 std::vector<std::string> credit_card_guids; 308 std::vector<std::string> credit_card_guids;
287 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween( 309 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween(
288 delete_begin, 310 delete_begin,
289 delete_end, 311 delete_end,
290 &profile_guids, 312 &profile_guids,
291 &credit_card_guids)) { 313 &credit_card_guids)) {
292 for (std::vector<std::string>::iterator iter = profile_guids.begin(); 314 for (std::vector<std::string>::iterator iter = profile_guids.begin();
293 iter != profile_guids.end(); ++iter) { 315 iter != profile_guids.end(); ++iter) {
294 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL); 316 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL);
295 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, 317 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread,
296 db_observer_list_, 318 db_observer_list_,
297 AutofillProfileChanged(change)); 319 AutofillProfileChanged(change));
298 } 320 }
299 // Note: It is the caller's responsibility to post notifications for any 321 // Note: It is the caller's responsibility to post notifications for any
300 // changes, e.g. by calling the Refresh() method of PersonalDataManager. 322 // changes, e.g. by calling the Refresh() method of PersonalDataManager.
301 return WebDatabase::COMMIT_NEEDED; 323 return WebDatabase::COMMIT_NEEDED;
302 } 324 }
303 return WebDatabase::COMMIT_NOT_NEEDED; 325 return WebDatabase::COMMIT_NOT_NEEDED;
304 } 326 }
305 327
306 void AutofillWebDataBackend::DestroyAutofillProfileResult( 328 void AutofillWebDataBackendImpl::DestroyAutofillProfileResult(
307 const WDTypedResult* result) { 329 const WDTypedResult* result) {
308 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); 330 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
309 const WDResult<std::vector<AutofillProfile*> >* r = 331 const WDResult<std::vector<AutofillProfile*> >* r =
310 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); 332 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
311 std::vector<AutofillProfile*> profiles = r->GetValue(); 333 std::vector<AutofillProfile*> profiles = r->GetValue();
312 STLDeleteElements(&profiles); 334 STLDeleteElements(&profiles);
313 } 335 }
314 336
315 void AutofillWebDataBackend::DestroyAutofillCreditCardResult( 337 void AutofillWebDataBackendImpl::DestroyAutofillCreditCardResult(
316 const WDTypedResult* result) { 338 const WDTypedResult* result) {
317 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 339 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
318 const WDResult<std::vector<CreditCard*> >* r = 340 const WDResult<std::vector<CreditCard*> >* r =
319 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 341 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
320 342
321 std::vector<CreditCard*> credit_cards = r->GetValue(); 343 std::vector<CreditCard*> credit_cards = r->GetValue();
322 STLDeleteElements(&credit_cards); 344 STLDeleteElements(&credit_cards);
323 } 345 }
324 346
325 } // namespace autofill 347 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698