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

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

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

Powered by Google App Engine
This is Rietveld 408576698