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

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

Powered by Google App Engine
This is Rietveld 408576698