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

Side by Side Diff: chrome/browser/webdata/autofill_web_data_service.cc

Issue 12937016: Rename AutofillWebDataServiceImpl --> AutofillWebDataService. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove c/b/api/autofill_webdata_service.h Created 7 years, 9 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 "chrome/browser/webdata/autofill_web_data_service_impl.h" 5 #include "chrome/browser/webdata/autofill_web_data_service.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 "chrome/browser/webdata/autofill_change.h" 9 #include "chrome/browser/webdata/autofill_change.h"
10 #include "chrome/browser/webdata/autofill_entry.h" 10 #include "chrome/browser/webdata/autofill_entry.h"
11 #include "chrome/browser/webdata/autofill_table.h" 11 #include "chrome/browser/webdata/autofill_table.h"
12 #include "chrome/browser/webdata/web_database_service.h" 12 #include "chrome/browser/webdata/web_database_service.h"
13 #include "chrome/common/chrome_notification_types.h" 13 #include "chrome/common/chrome_notification_types.h"
14 #include "components/autofill/browser/autofill_country.h" 14 #include "components/autofill/browser/autofill_country.h"
15 #include "components/autofill/browser/autofill_profile.h" 15 #include "components/autofill/browser/autofill_profile.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 scoped_refptr<WebDatabaseService> wdbs, 56 scoped_refptr<WebDatabaseService> wdbs,
57 const ProfileErrorCallback& callback) 57 const ProfileErrorCallback& callback)
58 : WebDataServiceBase(wdbs, callback) { 58 : WebDataServiceBase(wdbs, callback) {
59 } 59 }
60 60
61 AutofillWebDataService::AutofillWebDataService() 61 AutofillWebDataService::AutofillWebDataService()
62 : WebDataServiceBase(NULL, 62 : WebDataServiceBase(NULL,
63 WebDataServiceBase::ProfileErrorCallback()) { 63 WebDataServiceBase::ProfileErrorCallback()) {
64 } 64 }
65 65
66 AutofillWebDataServiceImpl::AutofillWebDataServiceImpl(
67 scoped_refptr<WebDatabaseService> wdbs,
68 const ProfileErrorCallback& callback)
69 : AutofillWebDataService(wdbs, callback) {
70 }
71
72 content::NotificationSource 66 content::NotificationSource
73 AutofillWebDataServiceImpl::GetNotificationSource() { 67 AutofillWebDataService::GetNotificationSource() {
74 return content::Source<AutofillWebDataService>(this); 68 return content::Source<AutofillWebDataService>(this);
75 } 69 }
76 70
77 void AutofillWebDataServiceImpl::AddFormFields( 71 void AutofillWebDataService::AddFormFields(
78 const std::vector<FormFieldData>& fields) { 72 const std::vector<FormFieldData>& fields) {
79 wdbs_->ScheduleDBTask(FROM_HERE, 73 wdbs_->ScheduleDBTask(FROM_HERE,
80 Bind(&AutofillWebDataServiceImpl::AddFormElementsImpl, this, fields)); 74 Bind(&AutofillWebDataService::AddFormElementsImpl, this, fields));
81 } 75 }
82 76
83 WebDataServiceBase::Handle 77 WebDataServiceBase::Handle
84 AutofillWebDataServiceImpl::GetFormValuesForElementName( 78 AutofillWebDataService::GetFormValuesForElementName(
85 const string16& name, const string16& prefix, int limit, 79 const string16& name, const string16& prefix, int limit,
86 WebDataServiceConsumer* consumer) { 80 WebDataServiceConsumer* consumer) {
87 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, 81 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE,
88 Bind(&AutofillWebDataServiceImpl::GetFormValuesForElementNameImpl, 82 Bind(&AutofillWebDataService::GetFormValuesForElementNameImpl,
89 this, name, prefix, limit), consumer); 83 this, name, prefix, limit), consumer);
90 } 84 }
91 85
92 void AutofillWebDataServiceImpl::RemoveExpiredFormElements() { 86 void AutofillWebDataService::RemoveExpiredFormElements() {
93 wdbs_->ScheduleDBTask(FROM_HERE, 87 wdbs_->ScheduleDBTask(FROM_HERE,
94 Bind(&AutofillWebDataServiceImpl::RemoveExpiredFormElementsImpl, this)); 88 Bind(&AutofillWebDataService::RemoveExpiredFormElementsImpl, this));
95 } 89 }
96 90
97 void AutofillWebDataServiceImpl::RemoveFormValueForElementName( 91 void AutofillWebDataService::RemoveFormValueForElementName(
98 const string16& name, const string16& value) { 92 const string16& name, const string16& value) {
99 wdbs_->ScheduleDBTask(FROM_HERE, 93 wdbs_->ScheduleDBTask(FROM_HERE,
100 Bind(&AutofillWebDataServiceImpl::RemoveFormValueForElementNameImpl, 94 Bind(&AutofillWebDataService::RemoveFormValueForElementNameImpl,
101 this, name, value)); 95 this, name, value));
102 } 96 }
103 97
104 void AutofillWebDataServiceImpl::AddAutofillProfile( 98 void AutofillWebDataService::AddAutofillProfile(
105 const AutofillProfile& profile) { 99 const AutofillProfile& profile) {
106 wdbs_->ScheduleDBTask(FROM_HERE, 100 wdbs_->ScheduleDBTask(FROM_HERE,
107 Bind(&AutofillWebDataServiceImpl::AddAutofillProfileImpl, this, profile)); 101 Bind(&AutofillWebDataService::AddAutofillProfileImpl, this, profile));
108 } 102 }
109 103
110 void AutofillWebDataServiceImpl::UpdateAutofillProfile( 104 void AutofillWebDataService::UpdateAutofillProfile(
111 const AutofillProfile& profile) { 105 const AutofillProfile& profile) {
112 wdbs_->ScheduleDBTask(FROM_HERE, 106 wdbs_->ScheduleDBTask(FROM_HERE,
113 Bind(&AutofillWebDataServiceImpl::UpdateAutofillProfileImpl, 107 Bind(&AutofillWebDataService::UpdateAutofillProfileImpl,
114 this, profile)); 108 this, profile));
115 } 109 }
116 110
117 void AutofillWebDataServiceImpl::RemoveAutofillProfile( 111 void AutofillWebDataService::RemoveAutofillProfile(
118 const std::string& guid) { 112 const std::string& guid) {
119 wdbs_->ScheduleDBTask(FROM_HERE, 113 wdbs_->ScheduleDBTask(FROM_HERE,
120 Bind(&AutofillWebDataServiceImpl::RemoveAutofillProfileImpl, this, guid)); 114 Bind(&AutofillWebDataService::RemoveAutofillProfileImpl, this, guid));
121 } 115 }
122 116
123 WebDataServiceBase::Handle AutofillWebDataServiceImpl::GetAutofillProfiles( 117 WebDataServiceBase::Handle AutofillWebDataService::GetAutofillProfiles(
124 WebDataServiceConsumer* consumer) { 118 WebDataServiceConsumer* consumer) {
125 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, 119 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE,
126 Bind(&AutofillWebDataServiceImpl::GetAutofillProfilesImpl, this), 120 Bind(&AutofillWebDataService::GetAutofillProfilesImpl, this),
127 consumer); 121 consumer);
128 } 122 }
129 123
130 void AutofillWebDataServiceImpl::AddCreditCard(const CreditCard& credit_card) { 124 void AutofillWebDataService::AddCreditCard(const CreditCard& credit_card) {
131 wdbs_->ScheduleDBTask(FROM_HERE, 125 wdbs_->ScheduleDBTask(FROM_HERE,
132 Bind(&AutofillWebDataServiceImpl::AddCreditCardImpl, this, credit_card)); 126 Bind(&AutofillWebDataService::AddCreditCardImpl, this, credit_card));
133 } 127 }
134 128
135 void AutofillWebDataServiceImpl::UpdateCreditCard( 129 void AutofillWebDataService::UpdateCreditCard(
136 const CreditCard& credit_card) { 130 const CreditCard& credit_card) {
137 wdbs_->ScheduleDBTask(FROM_HERE, 131 wdbs_->ScheduleDBTask(FROM_HERE,
138 Bind(&AutofillWebDataServiceImpl::UpdateCreditCardImpl, this, 132 Bind(&AutofillWebDataService::UpdateCreditCardImpl, this,
139 credit_card)); 133 credit_card));
140 } 134 }
141 135
142 void AutofillWebDataServiceImpl::RemoveCreditCard(const std::string& guid) { 136 void AutofillWebDataService::RemoveCreditCard(const std::string& guid) {
143 wdbs_->ScheduleDBTask(FROM_HERE, 137 wdbs_->ScheduleDBTask(FROM_HERE,
144 Bind(&AutofillWebDataServiceImpl::RemoveCreditCardImpl, this, guid)); 138 Bind(&AutofillWebDataService::RemoveCreditCardImpl, this, guid));
145 } 139 }
146 140
147 AutofillWebDataServiceImpl::Handle AutofillWebDataServiceImpl::GetCreditCards( 141 WebDataServiceBase::Handle AutofillWebDataService::GetCreditCards(
148 WebDataServiceConsumer* consumer) { 142 WebDataServiceConsumer* consumer) {
149 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, 143 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE,
150 Bind(&AutofillWebDataServiceImpl::GetCreditCardsImpl, this), consumer); 144 Bind(&AutofillWebDataService::GetCreditCardsImpl, this), consumer);
151 } 145 }
152 146
153 void AutofillWebDataServiceImpl::RemoveFormElementsAddedBetween( 147 void AutofillWebDataService::RemoveFormElementsAddedBetween(
154 const Time& delete_begin, const Time& delete_end) { 148 const Time& delete_begin, const Time& delete_end) {
155 wdbs_->ScheduleDBTask(FROM_HERE, 149 wdbs_->ScheduleDBTask(FROM_HERE,
156 Bind(&AutofillWebDataServiceImpl::RemoveFormElementsAddedBetweenImpl, 150 Bind(&AutofillWebDataService::RemoveFormElementsAddedBetweenImpl,
157 this, delete_begin, delete_end)); 151 this, delete_begin, delete_end));
158 } 152 }
159 153
160 void 154 void
161 AutofillWebDataServiceImpl::RemoveAutofillProfilesAndCreditCardsModifiedBetween( 155 AutofillWebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
162 const Time& delete_begin, const Time& delete_end) { 156 const Time& delete_begin, const Time& delete_end) {
163 wdbs_->ScheduleDBTask(FROM_HERE, Bind( 157 wdbs_->ScheduleDBTask(FROM_HERE, Bind(
164 &AutofillWebDataServiceImpl::RemoveAutofillProfilesAndCreditCardsModifiedBetween Impl, 158 &AutofillWebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl ,
165 this, delete_begin, delete_end)); 159 this, delete_begin, delete_end));
166 } 160 }
167 161
168 AutofillWebDataServiceImpl::~AutofillWebDataServiceImpl() { 162 AutofillWebDataService::~AutofillWebDataService() {
169 } 163 }
170 164
171 //////////////////////////////////////////////////////////////////////////////// 165 ////////////////////////////////////////////////////////////////////////////////
172 // 166 //
173 // Autofill implementation. 167 // Autofill implementation.
174 // 168 //
175 //////////////////////////////////////////////////////////////////////////////// 169 ////////////////////////////////////////////////////////////////////////////////
176 170
177 WebDatabase::State AutofillWebDataServiceImpl::AddFormElementsImpl( 171 WebDatabase::State AutofillWebDataService::AddFormElementsImpl(
178 const std::vector<FormFieldData>& fields, WebDatabase* db) { 172 const std::vector<FormFieldData>& fields, WebDatabase* db) {
179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 173 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
180 AutofillChangeList changes; 174 AutofillChangeList changes;
181 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( 175 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues(
182 fields, &changes)) { 176 fields, &changes)) {
183 NOTREACHED(); 177 NOTREACHED();
184 return WebDatabase::COMMIT_NOT_NEEDED; 178 return WebDatabase::COMMIT_NOT_NEEDED;
185 } 179 }
186 180
187 // Post the notifications including the list of affected keys. 181 // Post the notifications including the list of affected keys.
188 // This is sent here so that work resulting from this notification will be 182 // This is sent here so that work resulting from this notification will be
189 // done on the DB thread, and not the UI thread. 183 // done on the DB thread, and not the UI thread.
190 content::NotificationService::current()->Notify( 184 content::NotificationService::current()->Notify(
191 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 185 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
192 content::Source<AutofillWebDataService>(this), 186 content::Source<AutofillWebDataService>(this),
193 content::Details<AutofillChangeList>(&changes)); 187 content::Details<AutofillChangeList>(&changes));
194 188
195 return WebDatabase::COMMIT_NEEDED; 189 return WebDatabase::COMMIT_NEEDED;
196 } 190 }
197 191
198 scoped_ptr<WDTypedResult> 192 scoped_ptr<WDTypedResult>
199 AutofillWebDataServiceImpl::GetFormValuesForElementNameImpl( 193 AutofillWebDataService::GetFormValuesForElementNameImpl(
200 const string16& name, const string16& prefix, int limit, WebDatabase* db) { 194 const string16& name, const string16& prefix, int limit, WebDatabase* db) {
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 195 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
202 std::vector<string16> values; 196 std::vector<string16> values;
203 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( 197 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName(
204 name, prefix, &values, limit); 198 name, prefix, &values, limit);
205 return scoped_ptr<WDTypedResult>( 199 return scoped_ptr<WDTypedResult>(
206 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); 200 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values));
207 } 201 }
208 202
209 WebDatabase::State 203 WebDatabase::State
210 AutofillWebDataServiceImpl::RemoveFormElementsAddedBetweenImpl( 204 AutofillWebDataService::RemoveFormElementsAddedBetweenImpl(
211 const base::Time& delete_begin, const base::Time& delete_end, 205 const base::Time& delete_begin, const base::Time& delete_end,
212 WebDatabase* db) { 206 WebDatabase* db) {
213 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 207 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
214 AutofillChangeList changes; 208 AutofillChangeList changes;
215 209
216 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( 210 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween(
217 delete_begin, delete_end, &changes)) { 211 delete_begin, delete_end, &changes)) {
218 if (!changes.empty()) { 212 if (!changes.empty()) {
219 // Post the notifications including the list of affected keys. 213 // Post the notifications including the list of affected keys.
220 // This is sent here so that work resulting from this notification 214 // This is sent here so that work resulting from this notification
221 // will be done on the DB thread, and not the UI thread. 215 // will be done on the DB thread, and not the UI thread.
222 content::NotificationService::current()->Notify( 216 content::NotificationService::current()->Notify(
223 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 217 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
224 content::Source<AutofillWebDataService>(this), 218 content::Source<AutofillWebDataService>(this),
225 content::Details<AutofillChangeList>(&changes)); 219 content::Details<AutofillChangeList>(&changes));
226 } 220 }
227 return WebDatabase::COMMIT_NEEDED; 221 return WebDatabase::COMMIT_NEEDED;
228 } 222 }
229 return WebDatabase::COMMIT_NOT_NEEDED; 223 return WebDatabase::COMMIT_NOT_NEEDED;
230 } 224 }
231 225
232 WebDatabase::State 226 WebDatabase::State
233 AutofillWebDataServiceImpl::RemoveExpiredFormElementsImpl( 227 AutofillWebDataService::RemoveExpiredFormElementsImpl(
234 WebDatabase* db) { 228 WebDatabase* db) {
235 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 229 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
236 AutofillChangeList changes; 230 AutofillChangeList changes;
237 231
238 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { 232 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
239 if (!changes.empty()) { 233 if (!changes.empty()) {
240 // Post the notifications including the list of affected keys. 234 // Post the notifications including the list of affected keys.
241 // This is sent here so that work resulting from this notification 235 // This is sent here so that work resulting from this notification
242 // will be done on the DB thread, and not the UI thread. 236 // will be done on the DB thread, and not the UI thread.
243 content::NotificationService::current()->Notify( 237 content::NotificationService::current()->Notify(
244 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 238 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
245 content::Source<AutofillWebDataService>(this), 239 content::Source<AutofillWebDataService>(this),
246 content::Details<AutofillChangeList>(&changes)); 240 content::Details<AutofillChangeList>(&changes));
247 } 241 }
248 return WebDatabase::COMMIT_NEEDED; 242 return WebDatabase::COMMIT_NEEDED;
249 } 243 }
250 return WebDatabase::COMMIT_NOT_NEEDED; 244 return WebDatabase::COMMIT_NOT_NEEDED;
251 } 245 }
252 246
253 WebDatabase::State 247 WebDatabase::State
254 AutofillWebDataServiceImpl::RemoveFormValueForElementNameImpl( 248 AutofillWebDataService::RemoveFormValueForElementNameImpl(
255 const string16& name, const string16& value, WebDatabase* db) { 249 const string16& name, const string16& value, WebDatabase* db) {
256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 250 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
257 251
258 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { 252 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
259 AutofillChangeList changes; 253 AutofillChangeList changes;
260 changes.push_back(AutofillChange(AutofillChange::REMOVE, 254 changes.push_back(AutofillChange(AutofillChange::REMOVE,
261 AutofillKey(name, value))); 255 AutofillKey(name, value)));
262 256
263 // Post the notifications including the list of affected keys. 257 // Post the notifications including the list of affected keys.
264 content::NotificationService::current()->Notify( 258 content::NotificationService::current()->Notify(
265 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 259 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
266 content::Source<AutofillWebDataService>(this), 260 content::Source<AutofillWebDataService>(this),
267 content::Details<AutofillChangeList>(&changes)); 261 content::Details<AutofillChangeList>(&changes));
268 262
269 return WebDatabase::COMMIT_NEEDED; 263 return WebDatabase::COMMIT_NEEDED;
270 } 264 }
271 return WebDatabase::COMMIT_NOT_NEEDED; 265 return WebDatabase::COMMIT_NOT_NEEDED;
272 } 266 }
273 267
274 WebDatabase::State 268 WebDatabase::State
275 AutofillWebDataServiceImpl::AddAutofillProfileImpl( 269 AutofillWebDataService::AddAutofillProfileImpl(
276 const AutofillProfile& profile, WebDatabase* db) { 270 const AutofillProfile& profile, WebDatabase* db) {
277 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 271 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
278 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { 272 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) {
279 NOTREACHED(); 273 NOTREACHED();
280 return WebDatabase::COMMIT_NOT_NEEDED; 274 return WebDatabase::COMMIT_NOT_NEEDED;
281 } 275 }
282 276
283 // Send GUID-based notification. 277 // Send GUID-based notification.
284 AutofillProfileChange change(AutofillProfileChange::ADD, 278 AutofillProfileChange change(AutofillProfileChange::ADD,
285 profile.guid(), &profile); 279 profile.guid(), &profile);
286 content::NotificationService::current()->Notify( 280 content::NotificationService::current()->Notify(
287 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 281 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
288 content::Source<AutofillWebDataService>(this), 282 content::Source<AutofillWebDataService>(this),
289 content::Details<AutofillProfileChange>(&change)); 283 content::Details<AutofillProfileChange>(&change));
290 284
291 return WebDatabase::COMMIT_NEEDED; 285 return WebDatabase::COMMIT_NEEDED;
292 } 286 }
293 287
294 WebDatabase::State 288 WebDatabase::State
295 AutofillWebDataServiceImpl::UpdateAutofillProfileImpl( 289 AutofillWebDataService::UpdateAutofillProfileImpl(
296 const AutofillProfile& profile, WebDatabase* db) { 290 const AutofillProfile& profile, WebDatabase* db) {
297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
298 // Only perform the update if the profile exists. It is currently 292 // Only perform the update if the profile exists. It is currently
299 // valid to try to update a missing profile. We simply drop the write and 293 // valid to try to update a missing profile. We simply drop the write and
300 // the caller will detect this on the next refresh. 294 // the caller will detect this on the next refresh.
301 AutofillProfile* original_profile = NULL; 295 AutofillProfile* original_profile = NULL;
302 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), 296 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(),
303 &original_profile)) { 297 &original_profile)) {
304 return WebDatabase::COMMIT_NOT_NEEDED; 298 return WebDatabase::COMMIT_NOT_NEEDED;
305 } 299 }
(...skipping 10 matching lines...) Expand all
316 profile.guid(), &profile); 310 profile.guid(), &profile);
317 content::NotificationService::current()->Notify( 311 content::NotificationService::current()->Notify(
318 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 312 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
319 content::Source<AutofillWebDataService>(this), 313 content::Source<AutofillWebDataService>(this),
320 content::Details<AutofillProfileChange>(&change)); 314 content::Details<AutofillProfileChange>(&change));
321 315
322 return WebDatabase::COMMIT_NEEDED; 316 return WebDatabase::COMMIT_NEEDED;
323 } 317 }
324 318
325 WebDatabase::State 319 WebDatabase::State
326 AutofillWebDataServiceImpl::RemoveAutofillProfileImpl( 320 AutofillWebDataService::RemoveAutofillProfileImpl(
kaiwang 2013/03/25 23:21:25 one line? Also applies to functions below
Cait (Slow) 2013/03/26 14:55:03 Done.
327 const std::string& guid, WebDatabase* db) { 321 const std::string& guid, WebDatabase* db) {
328 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
329 AutofillProfile* profile = NULL; 323 AutofillProfile* profile = NULL;
330 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { 324 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) {
331 NOTREACHED(); 325 NOTREACHED();
332 return WebDatabase::COMMIT_NOT_NEEDED; 326 return WebDatabase::COMMIT_NOT_NEEDED;
333 } 327 }
334 scoped_ptr<AutofillProfile> scoped_profile(profile); 328 scoped_ptr<AutofillProfile> scoped_profile(profile);
335 329
336 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { 330 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) {
337 NOTREACHED(); 331 NOTREACHED();
338 return WebDatabase::COMMIT_NOT_NEEDED; 332 return WebDatabase::COMMIT_NOT_NEEDED;
339 } 333 }
340 334
341 // Send GUID-based notification. 335 // Send GUID-based notification.
342 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); 336 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL);
343 content::NotificationService::current()->Notify( 337 content::NotificationService::current()->Notify(
344 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 338 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
345 content::Source<AutofillWebDataService>(this), 339 content::Source<AutofillWebDataService>(this),
346 content::Details<AutofillProfileChange>(&change)); 340 content::Details<AutofillProfileChange>(&change));
347 341
348 return WebDatabase::COMMIT_NEEDED; 342 return WebDatabase::COMMIT_NEEDED;
349 } 343 }
350 344
351 scoped_ptr<WDTypedResult> 345 scoped_ptr<WDTypedResult>
352 AutofillWebDataServiceImpl::GetAutofillProfilesImpl( 346 AutofillWebDataService::GetAutofillProfilesImpl(
353 WebDatabase* db) { 347 WebDatabase* db) {
354 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
355 std::vector<AutofillProfile*> profiles; 349 std::vector<AutofillProfile*> profiles;
356 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); 350 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles);
357 return scoped_ptr<WDTypedResult>( 351 return scoped_ptr<WDTypedResult>(
358 new WDDestroyableResult<std::vector<AutofillProfile*> >( 352 new WDDestroyableResult<std::vector<AutofillProfile*> >(
359 AUTOFILL_PROFILES_RESULT, 353 AUTOFILL_PROFILES_RESULT,
360 profiles, 354 profiles,
361 base::Bind(&AutofillWebDataServiceImpl::DestroyAutofillProfileResult, 355 base::Bind(&AutofillWebDataService::DestroyAutofillProfileResult,
362 base::Unretained(this)))); 356 base::Unretained(this))));
363 } 357 }
364 358
365 WebDatabase::State 359 WebDatabase::State
366 AutofillWebDataServiceImpl::AddCreditCardImpl( 360 AutofillWebDataService::AddCreditCardImpl(
367 const CreditCard& credit_card, WebDatabase* db) { 361 const CreditCard& credit_card, WebDatabase* db) {
368 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
369 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { 363 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) {
370 NOTREACHED(); 364 NOTREACHED();
371 return WebDatabase::COMMIT_NOT_NEEDED; 365 return WebDatabase::COMMIT_NOT_NEEDED;
372 } 366 }
373 367
374 return WebDatabase::COMMIT_NEEDED; 368 return WebDatabase::COMMIT_NEEDED;
375 } 369 }
376 370
377 WebDatabase::State 371 WebDatabase::State
378 AutofillWebDataServiceImpl::UpdateCreditCardImpl( 372 AutofillWebDataService::UpdateCreditCardImpl(
379 const CreditCard& credit_card, WebDatabase* db) { 373 const CreditCard& credit_card, WebDatabase* db) {
380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
381 // It is currently valid to try to update a missing profile. We simply drop 375 // It is currently valid to try to update a missing profile. We simply drop
382 // the write and the caller will detect this on the next refresh. 376 // the write and the caller will detect this on the next refresh.
383 CreditCard* original_credit_card = NULL; 377 CreditCard* original_credit_card = NULL;
384 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), 378 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(),
385 &original_credit_card)) { 379 &original_credit_card)) {
386 return WebDatabase::COMMIT_NOT_NEEDED; 380 return WebDatabase::COMMIT_NOT_NEEDED;
387 } 381 }
388 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); 382 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card);
389 383
390 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { 384 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) {
391 NOTREACHED(); 385 NOTREACHED();
392 return WebDatabase::COMMIT_NOT_NEEDED; 386 return WebDatabase::COMMIT_NOT_NEEDED;
393 } 387 }
394 return WebDatabase::COMMIT_NEEDED; 388 return WebDatabase::COMMIT_NEEDED;
395 } 389 }
396 390
397 WebDatabase::State 391 WebDatabase::State
398 AutofillWebDataServiceImpl::RemoveCreditCardImpl( 392 AutofillWebDataService::RemoveCreditCardImpl(
399 const std::string& guid, WebDatabase* db) { 393 const std::string& guid, WebDatabase* db) {
400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 394 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
401 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { 395 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) {
402 NOTREACHED(); 396 NOTREACHED();
403 return WebDatabase::COMMIT_NOT_NEEDED; 397 return WebDatabase::COMMIT_NOT_NEEDED;
404 } 398 }
405 return WebDatabase::COMMIT_NEEDED; 399 return WebDatabase::COMMIT_NEEDED;
406 } 400 }
407 401
408 scoped_ptr<WDTypedResult> 402 scoped_ptr<WDTypedResult>
409 AutofillWebDataServiceImpl::GetCreditCardsImpl(WebDatabase* db) { 403 AutofillWebDataService::GetCreditCardsImpl(WebDatabase* db) {
410 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 404 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
411 std::vector<CreditCard*> credit_cards; 405 std::vector<CreditCard*> credit_cards;
412 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); 406 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards);
413 return scoped_ptr<WDTypedResult>( 407 return scoped_ptr<WDTypedResult>(
414 new WDDestroyableResult<std::vector<CreditCard*> >( 408 new WDDestroyableResult<std::vector<CreditCard*> >(
415 AUTOFILL_CREDITCARDS_RESULT, 409 AUTOFILL_CREDITCARDS_RESULT,
416 credit_cards, 410 credit_cards,
417 base::Bind(&AutofillWebDataServiceImpl::DestroyAutofillCreditCardResult, 411 base::Bind(&AutofillWebDataService::DestroyAutofillCreditCardResult,
418 base::Unretained(this)))); 412 base::Unretained(this))));
419 } 413 }
420 414
421 WebDatabase::State 415 WebDatabase::State
422 AutofillWebDataServiceImpl::RemoveAutofillProfilesAndCreditCardsModifiedBetweenI mpl( 416 AutofillWebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
423 const base::Time& delete_begin, const base::Time& delete_end, 417 const base::Time& delete_begin, const base::Time& delete_end,
424 WebDatabase* db) { 418 WebDatabase* db) {
425 std::vector<std::string> profile_guids; 419 std::vector<std::string> profile_guids;
426 std::vector<std::string> credit_card_guids; 420 std::vector<std::string> credit_card_guids;
427 if (AutofillTable::FromWebDatabase(db)-> 421 if (AutofillTable::FromWebDatabase(db)->
428 RemoveAutofillProfilesAndCreditCardsModifiedBetween( 422 RemoveAutofillProfilesAndCreditCardsModifiedBetween(
429 delete_begin, 423 delete_begin,
430 delete_end, 424 delete_end,
431 &profile_guids, 425 &profile_guids,
432 &credit_card_guids)) { 426 &credit_card_guids)) {
433 for (std::vector<std::string>::iterator iter = profile_guids.begin(); 427 for (std::vector<std::string>::iterator iter = profile_guids.begin();
434 iter != profile_guids.end(); ++iter) { 428 iter != profile_guids.end(); ++iter) {
435 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, 429 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter,
436 NULL); 430 NULL);
437 content::NotificationService::current()->Notify( 431 content::NotificationService::current()->Notify(
438 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 432 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
439 content::Source<AutofillWebDataService>(this), 433 content::Source<AutofillWebDataService>(this),
440 content::Details<AutofillProfileChange>(&change)); 434 content::Details<AutofillProfileChange>(&change));
441 } 435 }
442 // Note: It is the caller's responsibility to post notifications for any 436 // Note: It is the caller's responsibility to post notifications for any
443 // changes, e.g. by calling the Refresh() method of PersonalDataManager. 437 // changes, e.g. by calling the Refresh() method of PersonalDataManager.
444 return WebDatabase::COMMIT_NEEDED; 438 return WebDatabase::COMMIT_NEEDED;
445 } 439 }
446 return WebDatabase::COMMIT_NOT_NEEDED; 440 return WebDatabase::COMMIT_NOT_NEEDED;
447 } 441 }
448 442
449 void AutofillWebDataServiceImpl::DestroyAutofillProfileResult( 443 void AutofillWebDataService::DestroyAutofillProfileResult(
450 const WDTypedResult* result) { 444 const WDTypedResult* result) {
451 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); 445 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT);
452 const WDResult<std::vector<AutofillProfile*> >* r = 446 const WDResult<std::vector<AutofillProfile*> >* r =
453 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); 447 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result);
454 std::vector<AutofillProfile*> profiles = r->GetValue(); 448 std::vector<AutofillProfile*> profiles = r->GetValue();
455 STLDeleteElements(&profiles); 449 STLDeleteElements(&profiles);
456 } 450 }
457 451
458 void AutofillWebDataServiceImpl::DestroyAutofillCreditCardResult( 452 void AutofillWebDataService::DestroyAutofillCreditCardResult(
459 const WDTypedResult* result) { 453 const WDTypedResult* result) {
460 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 454 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
461 const WDResult<std::vector<CreditCard*> >* r = 455 const WDResult<std::vector<CreditCard*> >* r =
462 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 456 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
463 457
464 std::vector<CreditCard*> credit_cards = r->GetValue(); 458 std::vector<CreditCard*> credit_cards = r->GetValue();
465 STLDeleteElements(&credit_cards); 459 STLDeleteElements(&credit_cards);
466 } 460 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/autofill_web_data_service.h ('k') | chrome/browser/webdata/autofill_web_data_service_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698