OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/webdata/web_data_service.h" | 5 #include "chrome/browser/webdata/web_data_service.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return db_; | 143 return db_; |
144 } | 144 } |
145 | 145 |
146 ////////////////////////////////////////////////////////////////////////////// | 146 ////////////////////////////////////////////////////////////////////////////// |
147 // | 147 // |
148 // Keywords. | 148 // Keywords. |
149 // | 149 // |
150 ////////////////////////////////////////////////////////////////////////////// | 150 ////////////////////////////////////////////////////////////////////////////// |
151 | 151 |
152 void WebDataService::AddKeyword(const TemplateURLData& data) { | 152 void WebDataService::AddKeyword(const TemplateURLData& data) { |
153 GenericRequest<TemplateURLData>* request = | 153 ScheduleDBTask( |
154 new GenericRequest<TemplateURLData>( | 154 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data)); |
155 this, NULL, &request_manager_, data); | |
156 ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request)); | |
157 } | 155 } |
158 | 156 |
159 void WebDataService::RemoveKeyword(TemplateURLID id) { | 157 void WebDataService::RemoveKeyword(TemplateURLID id) { |
160 GenericRequest<TemplateURLID>* request = | 158 ScheduleDBTask( |
161 new GenericRequest<TemplateURLID>(this, NULL, &request_manager_, id); | 159 FROM_HERE, Bind(&WebDataService::RemoveKeywordImpl, this, id)); |
162 ScheduleTask(FROM_HERE, | |
163 Bind(&WebDataService::RemoveKeywordImpl, this, request)); | |
164 } | 160 } |
165 | 161 |
166 void WebDataService::UpdateKeyword(const TemplateURLData& data) { | 162 void WebDataService::UpdateKeyword(const TemplateURLData& data) { |
167 GenericRequest<TemplateURLData>* request = | 163 ScheduleDBTask( |
168 new GenericRequest<TemplateURLData>( | 164 FROM_HERE, Bind(&WebDataService::UpdateKeywordImpl, this, data)); |
169 this, NULL, &request_manager_, data); | |
170 ScheduleTask(FROM_HERE, | |
171 Bind(&WebDataService::UpdateKeywordImpl, this, request)); | |
172 } | 165 } |
173 | 166 |
174 WebDataService::Handle WebDataService::GetKeywords( | 167 WebDataService::Handle WebDataService::GetKeywords( |
175 WebDataServiceConsumer* consumer) { | 168 WebDataServiceConsumer* consumer) { |
176 WebDataRequest* request = | 169 return ScheduleDBTaskWithResult(FROM_HERE, |
177 new WebDataRequest(this, consumer, &request_manager_); | 170 Bind(&WebDataService::GetKeywordsImpl, this), consumer); |
178 ScheduleTask(FROM_HERE, | |
179 Bind(&WebDataService::GetKeywordsImpl, this, request)); | |
180 return request->GetHandle(); | |
181 } | 171 } |
182 | 172 |
183 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { | 173 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { |
184 GenericRequest<TemplateURLID>* request = new GenericRequest<TemplateURLID>( | 174 ScheduleDBTask(FROM_HERE, |
185 this, NULL, &request_manager_, url ? url->id() : 0); | 175 Bind(&WebDataService::SetDefaultSearchProviderImpl, this, |
186 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl, | 176 url ? url->id() : 0)); |
187 this, request)); | |
188 } | 177 } |
189 | 178 |
190 void WebDataService::SetBuiltinKeywordVersion(int version) { | 179 void WebDataService::SetBuiltinKeywordVersion(int version) { |
191 GenericRequest<int>* request = new GenericRequest<int>( | 180 ScheduleDBTask(FROM_HERE, |
192 this, NULL, &request_manager_, version); | 181 Bind(&WebDataService::SetBuiltinKeywordVersionImpl, this, version)); |
193 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl, | |
194 this, request)); | |
195 } | 182 } |
196 | 183 |
197 ////////////////////////////////////////////////////////////////////////////// | 184 ////////////////////////////////////////////////////////////////////////////// |
198 // | 185 // |
199 // Web Apps | 186 // Web Apps |
200 // | 187 // |
201 ////////////////////////////////////////////////////////////////////////////// | 188 ////////////////////////////////////////////////////////////////////////////// |
202 | 189 |
203 void WebDataService::SetWebAppImage(const GURL& app_url, | 190 void WebDataService::SetWebAppImage(const GURL& app_url, |
204 const SkBitmap& image) { | 191 const SkBitmap& image) { |
205 GenericRequest2<GURL, SkBitmap>* request = | 192 ScheduleDBTask(FROM_HERE, |
206 new GenericRequest2<GURL, SkBitmap>( | 193 Bind(&WebDataService::SetWebAppImageImpl, this, app_url, image)); |
207 this, NULL, &request_manager_, app_url, image); | |
208 ScheduleTask(FROM_HERE, | |
209 Bind(&WebDataService::SetWebAppImageImpl, this, request)); | |
210 } | 194 } |
211 | 195 |
212 void WebDataService::SetWebAppHasAllImages(const GURL& app_url, | 196 void WebDataService::SetWebAppHasAllImages(const GURL& app_url, |
213 bool has_all_images) { | 197 bool has_all_images) { |
214 GenericRequest2<GURL, bool>* request = | 198 ScheduleDBTask(FROM_HERE, |
215 new GenericRequest2<GURL, bool>( | 199 Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, app_url, |
216 this, NULL, &request_manager_, app_url, has_all_images); | 200 has_all_images)); |
217 ScheduleTask(FROM_HERE, | |
218 Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request)); | |
219 } | 201 } |
220 | 202 |
221 void WebDataService::RemoveWebApp(const GURL& app_url) { | 203 void WebDataService::RemoveWebApp(const GURL& app_url) { |
222 GenericRequest<GURL>* request = | 204 ScheduleDBTask(FROM_HERE, |
223 new GenericRequest<GURL>(this, NULL, &request_manager_, app_url); | 205 Bind(&WebDataService::RemoveWebAppImpl, this, app_url)); |
224 ScheduleTask(FROM_HERE, | |
225 Bind(&WebDataService::RemoveWebAppImpl, this, request)); | |
226 } | 206 } |
227 | 207 |
228 WebDataService::Handle WebDataService::GetWebAppImages( | 208 WebDataService::Handle WebDataService::GetWebAppImages( |
229 const GURL& app_url, | 209 const GURL& app_url, |
230 WebDataServiceConsumer* consumer) { | 210 WebDataServiceConsumer* consumer) { |
231 GenericRequest<GURL>* request = | 211 return ScheduleDBTaskWithResult(FROM_HERE, |
232 new GenericRequest<GURL>(this, consumer, &request_manager_, app_url); | 212 Bind(&WebDataService::GetWebAppImagesImpl, this, app_url), consumer); |
233 ScheduleTask(FROM_HERE, | |
234 Bind(&WebDataService::GetWebAppImagesImpl, this, request)); | |
235 return request->GetHandle(); | |
236 } | 213 } |
237 | 214 |
238 ////////////////////////////////////////////////////////////////////////////// | 215 ////////////////////////////////////////////////////////////////////////////// |
239 // | 216 // |
240 // Web Intents. | 217 // Web Intents. |
241 // | 218 // |
242 ////////////////////////////////////////////////////////////////////////////// | 219 ////////////////////////////////////////////////////////////////////////////// |
243 | 220 |
244 void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { | 221 void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { |
245 GenericRequest<WebIntentServiceData>* request = | 222 ScheduleDBTask(FROM_HERE, |
246 new GenericRequest<WebIntentServiceData>( | 223 Bind(&WebDataService::AddWebIntentServiceImpl, this, service)); |
247 this, NULL, &request_manager_, service); | |
248 ScheduleTask(FROM_HERE, | |
249 Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); | |
250 } | 224 } |
251 | 225 |
252 void WebDataService::RemoveWebIntentService( | 226 void WebDataService::RemoveWebIntentService( |
253 const WebIntentServiceData& service) { | 227 const WebIntentServiceData& service) { |
254 GenericRequest<WebIntentServiceData>* request = | 228 ScheduleDBTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, |
255 new GenericRequest<WebIntentServiceData>( | 229 this, service)); |
256 this, NULL, &request_manager_, service); | |
257 ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, | |
258 this, request)); | |
259 } | 230 } |
260 | 231 |
261 WebDataService::Handle WebDataService::GetWebIntentServicesForAction( | 232 WebDataService::Handle WebDataService::GetWebIntentServicesForAction( |
262 const string16& action, | 233 const string16& action, |
263 WebDataServiceConsumer* consumer) { | 234 WebDataServiceConsumer* consumer) { |
264 DCHECK(consumer); | 235 return ScheduleDBTaskWithResult(FROM_HERE, |
265 GenericRequest<string16>* request = | 236 Bind(&WebDataService::GetWebIntentServicesImpl, this, action), consumer); |
266 new GenericRequest<string16>( | |
267 this, consumer, &request_manager_, action); | |
268 ScheduleTask(FROM_HERE, | |
269 Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); | |
270 return request->GetHandle(); | |
271 } | 237 } |
272 | 238 |
273 WebDataService::Handle WebDataService::GetWebIntentServicesForURL( | 239 WebDataService::Handle WebDataService::GetWebIntentServicesForURL( |
274 const string16& service_url, | 240 const string16& service_url, |
275 WebDataServiceConsumer* consumer) { | 241 WebDataServiceConsumer* consumer) { |
276 DCHECK(consumer); | 242 return ScheduleDBTaskWithResult(FROM_HERE, |
277 GenericRequest<string16>* request = | 243 Bind(&WebDataService::GetWebIntentServicesForURLImpl, this, service_url), |
278 new GenericRequest<string16>( | 244 consumer); |
279 this, consumer, &request_manager_, service_url); | |
280 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl, | |
281 this, request)); | |
282 return request->GetHandle(); | |
283 } | 245 } |
284 | 246 |
285 | 247 |
286 WebDataService::Handle WebDataService::GetAllWebIntentServices( | 248 WebDataService::Handle WebDataService::GetAllWebIntentServices( |
287 WebDataServiceConsumer* consumer) { | 249 WebDataServiceConsumer* consumer) { |
288 DCHECK(consumer); | 250 return ScheduleDBTaskWithResult(FROM_HERE, |
289 GenericRequest<std::string>* request = | 251 Bind(&WebDataService::GetAllWebIntentServicesImpl, this), consumer); |
290 new GenericRequest<std::string>( | |
291 this, consumer, &request_manager_, std::string()); | |
292 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, | |
293 this, request)); | |
294 return request->GetHandle(); | |
295 } | 252 } |
296 | 253 |
297 void WebDataService::AddDefaultWebIntentService( | 254 void WebDataService::AddDefaultWebIntentService( |
298 const DefaultWebIntentService& service) { | 255 const DefaultWebIntentService& service) { |
299 GenericRequest<DefaultWebIntentService>* request = | 256 ScheduleDBTask(FROM_HERE, |
300 new GenericRequest<DefaultWebIntentService>( | 257 Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, service)); |
301 this, NULL, &request_manager_, service); | |
302 ScheduleTask(FROM_HERE, | |
303 Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, | |
304 request)); | |
305 } | 258 } |
306 | 259 |
307 void WebDataService::RemoveDefaultWebIntentService( | 260 void WebDataService::RemoveDefaultWebIntentService( |
308 const DefaultWebIntentService& service) { | 261 const DefaultWebIntentService& service) { |
309 GenericRequest<DefaultWebIntentService>* request = | 262 ScheduleDBTask(FROM_HERE, |
310 new GenericRequest<DefaultWebIntentService>( | 263 Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, service)); |
311 this, NULL, &request_manager_, service); | |
312 ScheduleTask(FROM_HERE, | |
313 Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, | |
314 request)); | |
315 } | 264 } |
316 | 265 |
317 void WebDataService::RemoveWebIntentServiceDefaults( | 266 void WebDataService::RemoveWebIntentServiceDefaults( |
318 const GURL& service_url) { | 267 const GURL& service_url) { |
319 GenericRequest<GURL>* request = | 268 ScheduleDBTask(FROM_HERE, |
320 new GenericRequest<GURL>(this, NULL, &request_manager_, service_url); | 269 Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, |
321 ScheduleTask( | 270 service_url)); |
322 FROM_HERE, | |
323 Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request)); | |
324 } | 271 } |
325 | 272 |
326 WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( | 273 WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( |
327 const string16& action, | 274 const string16& action, |
328 WebDataServiceConsumer* consumer) { | 275 WebDataServiceConsumer* consumer) { |
329 DCHECK(consumer); | 276 return ScheduleDBTaskWithResult(FROM_HERE, |
330 GenericRequest<string16>* request = new GenericRequest<string16>( | 277 Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, this, |
331 this, consumer, &request_manager_, action); | 278 action), |
332 ScheduleTask(FROM_HERE, | 279 consumer); |
333 Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, | |
334 this, request)); | |
335 return request->GetHandle(); | |
336 } | 280 } |
337 | 281 |
338 WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( | 282 WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( |
339 WebDataServiceConsumer* consumer) { | 283 WebDataServiceConsumer* consumer) { |
340 DCHECK(consumer); | 284 return ScheduleDBTaskWithResult(FROM_HERE, |
341 GenericRequest<std::string>* request = new GenericRequest<std::string>( | 285 Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, this), |
342 this, consumer, &request_manager_, std::string()); | 286 consumer); |
343 ScheduleTask(FROM_HERE, | |
344 Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, | |
345 this, request)); | |
346 return request->GetHandle(); | |
347 } | 287 } |
348 | 288 |
349 //////////////////////////////////////////////////////////////////////////////// | 289 //////////////////////////////////////////////////////////////////////////////// |
350 // | 290 // |
351 // Token Service | 291 // Token Service |
352 // | 292 // |
353 //////////////////////////////////////////////////////////////////////////////// | 293 //////////////////////////////////////////////////////////////////////////////// |
354 | 294 |
355 void WebDataService::SetTokenForService(const std::string& service, | 295 void WebDataService::SetTokenForService(const std::string& service, |
356 const std::string& token) { | 296 const std::string& token) { |
357 GenericRequest2<std::string, std::string>* request = | 297 ScheduleDBTask(FROM_HERE, |
358 new GenericRequest2<std::string, std::string>( | 298 Bind(&WebDataService::SetTokenForServiceImpl, this, service, token)); |
359 this, NULL, &request_manager_, service, token); | |
360 ScheduleTask(FROM_HERE, | |
361 Bind(&WebDataService::SetTokenForServiceImpl, this, request)); | |
362 } | 299 } |
363 | 300 |
364 void WebDataService::RemoveAllTokens() { | 301 void WebDataService::RemoveAllTokens() { |
365 GenericRequest<std::string>* request = | 302 ScheduleDBTask(FROM_HERE, Bind(&WebDataService::RemoveAllTokensImpl, this)); |
366 new GenericRequest<std::string>( | |
367 this, NULL, &request_manager_, std::string()); | |
368 ScheduleTask(FROM_HERE, | |
369 Bind(&WebDataService::RemoveAllTokensImpl, this, request)); | |
370 } | 303 } |
371 | 304 |
372 // Null on failure. Success is WDResult<std::string> | 305 // Null on failure. Success is WDResult<std::string> |
373 WebDataService::Handle WebDataService::GetAllTokens( | 306 WebDataService::Handle WebDataService::GetAllTokens( |
374 WebDataServiceConsumer* consumer) { | 307 WebDataServiceConsumer* consumer) { |
375 | 308 return ScheduleDBTaskWithResult(FROM_HERE, |
376 GenericRequest<std::string>* request = | 309 Bind(&WebDataService::GetAllTokensImpl, this), consumer); |
377 new GenericRequest<std::string>( | |
378 this, consumer, &request_manager_, std::string()); | |
379 ScheduleTask(FROM_HERE, | |
380 Bind(&WebDataService::GetAllTokensImpl, this, request)); | |
381 return request->GetHandle(); | |
382 } | 310 } |
383 | 311 |
384 //////////////////////////////////////////////////////////////////////////////// | 312 //////////////////////////////////////////////////////////////////////////////// |
385 // | 313 // |
386 // Autofill. | 314 // Autofill. |
387 // | 315 // |
388 //////////////////////////////////////////////////////////////////////////////// | 316 //////////////////////////////////////////////////////////////////////////////// |
389 | 317 |
390 void WebDataService::AddFormFields( | 318 void WebDataService::AddFormFields( |
391 const std::vector<FormFieldData>& fields) { | 319 const std::vector<FormFieldData>& fields) { |
392 GenericRequest<std::vector<FormFieldData> >* request = | 320 ScheduleDBTask(FROM_HERE, |
393 new GenericRequest<std::vector<FormFieldData> >( | 321 Bind(&WebDataService::AddFormElementsImpl, this, fields)); |
394 this, NULL, &request_manager_, fields); | |
395 ScheduleTask(FROM_HERE, | |
396 Bind(&WebDataService::AddFormElementsImpl, this, request)); | |
397 } | 322 } |
398 | 323 |
399 WebDataService::Handle WebDataService::GetFormValuesForElementName( | 324 WebDataService::Handle WebDataService::GetFormValuesForElementName( |
400 const string16& name, const string16& prefix, int limit, | 325 const string16& name, const string16& prefix, int limit, |
401 WebDataServiceConsumer* consumer) { | 326 WebDataServiceConsumer* consumer) { |
402 WebDataRequest* request = | 327 return ScheduleDBTaskWithResult(FROM_HERE, |
403 new WebDataRequest(this, consumer, &request_manager_); | 328 Bind(&WebDataService::GetFormValuesForElementNameImpl, |
404 ScheduleTask(FROM_HERE, | 329 this, name, prefix, limit), |
405 Bind(&WebDataService::GetFormValuesForElementNameImpl, | 330 consumer); |
406 this, request, name, prefix, limit)); | |
407 return request->GetHandle(); | |
408 } | 331 } |
409 | 332 |
410 void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, | 333 void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, |
411 const Time& delete_end) { | 334 const Time& delete_end) { |
412 GenericRequest2<Time, Time>* request = | 335 ScheduleDBTask(FROM_HERE, |
413 new GenericRequest2<Time, Time>( | 336 Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, |
414 this, NULL, &request_manager_, delete_begin, delete_end); | 337 this, delete_begin, delete_end)); |
415 ScheduleTask(FROM_HERE, | |
416 Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, | |
417 this, request)); | |
418 } | 338 } |
419 | 339 |
420 void WebDataService::RemoveExpiredFormElements() { | 340 void WebDataService::RemoveExpiredFormElements() { |
421 WebDataRequest* request = | 341 ScheduleDBTask(FROM_HERE, |
422 new WebDataRequest(this, NULL, &request_manager_); | 342 Bind(&WebDataService::RemoveExpiredFormElementsImpl, this)); |
423 ScheduleTask(FROM_HERE, | |
424 Bind(&WebDataService::RemoveExpiredFormElementsImpl, | |
425 this, request)); | |
426 } | 343 } |
427 | 344 |
428 void WebDataService::RemoveFormValueForElementName( | 345 void WebDataService::RemoveFormValueForElementName( |
429 const string16& name, const string16& value) { | 346 const string16& name, const string16& value) { |
430 GenericRequest2<string16, string16>* request = | 347 ScheduleDBTask(FROM_HERE, |
431 new GenericRequest2<string16, string16>( | 348 Bind(&WebDataService::RemoveFormValueForElementNameImpl, |
432 this, NULL, &request_manager_, name, value); | 349 this, name, value)); |
433 ScheduleTask(FROM_HERE, | |
434 Bind(&WebDataService::RemoveFormValueForElementNameImpl, | |
435 this, request)); | |
436 } | 350 } |
437 | 351 |
438 void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { | 352 void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { |
439 GenericRequest<AutofillProfile>* request = | 353 ScheduleDBTask(FROM_HERE, |
440 new GenericRequest<AutofillProfile>( | 354 Bind(&WebDataService::AddAutofillProfileImpl, this, profile)); |
441 this, NULL, &request_manager_, profile); | |
442 ScheduleTask(FROM_HERE, | |
443 Bind(&WebDataService::AddAutofillProfileImpl, this, request)); | |
444 } | 355 } |
445 | 356 |
446 void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { | 357 void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { |
447 GenericRequest<AutofillProfile>* request = | 358 ScheduleDBTask(FROM_HERE, |
448 new GenericRequest<AutofillProfile>( | 359 Bind(&WebDataService::UpdateAutofillProfileImpl, this, profile)); |
449 this, NULL, &request_manager_, profile); | |
450 ScheduleTask(FROM_HERE, | |
451 Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); | |
452 } | 360 } |
453 | 361 |
454 void WebDataService::RemoveAutofillProfile(const std::string& guid) { | 362 void WebDataService::RemoveAutofillProfile(const std::string& guid) { |
455 GenericRequest<std::string>* request = | 363 ScheduleDBTask(FROM_HERE, |
456 new GenericRequest<std::string>(this, NULL, &request_manager_, guid); | 364 Bind(&WebDataService::RemoveAutofillProfileImpl, this, guid)); |
457 ScheduleTask(FROM_HERE, | |
458 Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); | |
459 } | 365 } |
460 | 366 |
461 WebDataService::Handle WebDataService::GetAutofillProfiles( | 367 WebDataService::Handle WebDataService::GetAutofillProfiles( |
462 WebDataServiceConsumer* consumer) { | 368 WebDataServiceConsumer* consumer) { |
463 WebDataRequest* request = | 369 return ScheduleDBTaskWithResult(FROM_HERE, |
464 new WebDataRequest(this, consumer, &request_manager_); | 370 Bind(&WebDataService::GetAutofillProfilesImpl, this), consumer); |
465 ScheduleTask(FROM_HERE, | |
466 Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); | |
467 return request->GetHandle(); | |
468 } | 371 } |
469 | 372 |
470 void WebDataService::EmptyMigrationTrash(bool notify_sync) { | 373 void WebDataService::EmptyMigrationTrash(bool notify_sync) { |
471 GenericRequest<bool>* request = | 374 ScheduleDBTask(FROM_HERE, |
472 new GenericRequest<bool>(this, NULL, &request_manager_, notify_sync); | 375 Bind(&WebDataService::EmptyMigrationTrashImpl, this, notify_sync)); |
473 ScheduleTask(FROM_HERE, | |
474 Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); | |
475 } | 376 } |
476 | 377 |
477 void WebDataService::AddCreditCard(const CreditCard& credit_card) { | 378 void WebDataService::AddCreditCard(const CreditCard& credit_card) { |
478 GenericRequest<CreditCard>* request = | 379 ScheduleDBTask(FROM_HERE, |
479 new GenericRequest<CreditCard>( | 380 Bind(&WebDataService::AddCreditCardImpl, this, credit_card)); |
480 this, NULL, &request_manager_, credit_card); | |
481 ScheduleTask(FROM_HERE, | |
482 Bind(&WebDataService::AddCreditCardImpl, this, request)); | |
483 } | 381 } |
484 | 382 |
485 void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { | 383 void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { |
486 GenericRequest<CreditCard>* request = | 384 ScheduleDBTask(FROM_HERE, |
487 new GenericRequest<CreditCard>( | 385 Bind(&WebDataService::UpdateCreditCardImpl, this, credit_card)); |
488 this, NULL, &request_manager_, credit_card); | |
489 ScheduleTask(FROM_HERE, | |
490 Bind(&WebDataService::UpdateCreditCardImpl, this, request)); | |
491 } | 386 } |
492 | 387 |
493 void WebDataService::RemoveCreditCard(const std::string& guid) { | 388 void WebDataService::RemoveCreditCard(const std::string& guid) { |
494 GenericRequest<std::string>* request = | 389 ScheduleDBTask(FROM_HERE, |
495 new GenericRequest<std::string>(this, NULL, &request_manager_, guid); | 390 Bind(&WebDataService::RemoveCreditCardImpl, this, guid)); |
496 ScheduleTask(FROM_HERE, | |
497 Bind(&WebDataService::RemoveCreditCardImpl, this, request)); | |
498 } | 391 } |
499 | 392 |
500 WebDataService::Handle WebDataService::GetCreditCards( | 393 WebDataService::Handle WebDataService::GetCreditCards( |
501 WebDataServiceConsumer* consumer) { | 394 WebDataServiceConsumer* consumer) { |
502 WebDataRequest* request = | 395 return ScheduleDBTaskWithResult(FROM_HERE, |
503 new WebDataRequest(this, consumer, &request_manager_); | 396 Bind(&WebDataService::GetCreditCardsImpl, this), consumer); |
504 ScheduleTask(FROM_HERE, | |
505 Bind(&WebDataService::GetCreditCardsImpl, this, request)); | |
506 return request->GetHandle(); | |
507 } | 397 } |
508 | 398 |
509 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 399 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
510 const Time& delete_begin, | 400 const Time& delete_begin, |
511 const Time& delete_end) { | 401 const Time& delete_end) { |
512 GenericRequest2<Time, Time>* request = | 402 ScheduleDBTask(FROM_HERE, Bind( |
513 new GenericRequest2<Time, Time>( | |
514 this, NULL, &request_manager_, delete_begin, delete_end); | |
515 ScheduleTask(FROM_HERE, Bind( | |
516 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, | 403 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, |
517 this, request)); | 404 this, delete_begin, delete_end)); |
518 } | 405 } |
519 | 406 |
520 WebDataService::~WebDataService() { | 407 WebDataService::~WebDataService() { |
521 if (is_running_ && db_) { | 408 if (is_running_ && db_) { |
522 DLOG_ASSERT("WebDataService dtor called without Shutdown"); | 409 DLOG_ASSERT("WebDataService dtor called without Shutdown"); |
523 NOTREACHED(); | 410 NOTREACHED(); |
524 } | 411 } |
525 } | 412 } |
526 | 413 |
527 bool WebDataService::InitWithPath(const FilePath& path) { | 414 bool WebDataService::InitWithPath(const FilePath& path) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 } | 516 } |
630 | 517 |
631 void WebDataService::ScheduleTask(const tracked_objects::Location& from_here, | 518 void WebDataService::ScheduleTask(const tracked_objects::Location& from_here, |
632 const base::Closure& task) { | 519 const base::Closure& task) { |
633 if (is_running_) | 520 if (is_running_) |
634 BrowserThread::PostTask(BrowserThread::DB, from_here, task); | 521 BrowserThread::PostTask(BrowserThread::DB, from_here, task); |
635 else | 522 else |
636 NOTREACHED() << "Task scheduled after Shutdown()"; | 523 NOTREACHED() << "Task scheduled after Shutdown()"; |
637 } | 524 } |
638 | 525 |
| 526 void WebDataService::ScheduleDBTask( |
| 527 const tracked_objects::Location& from_here, |
| 528 const base::Closure& task) { |
| 529 WebDataRequest* request = |
| 530 new WebDataRequest(this, NULL, &request_manager_); |
| 531 if (is_running_) { |
| 532 BrowserThread::PostTask(BrowserThread::DB, from_here, |
| 533 base::Bind(&WebDataService::DBTaskWrapper, this, task, request)); |
| 534 } else { |
| 535 NOTREACHED() << "Task scheduled after Shutdown()"; |
| 536 } |
| 537 } |
| 538 |
| 539 WebDataService::Handle WebDataService::ScheduleDBTaskWithResult( |
| 540 const tracked_objects::Location& from_here, |
| 541 const ResultTask& task, |
| 542 WebDataServiceConsumer* consumer) { |
| 543 DCHECK(consumer); |
| 544 WebDataRequest* request = |
| 545 new WebDataRequest(this, consumer, &request_manager_); |
| 546 if (is_running_) { |
| 547 BrowserThread::PostTask(BrowserThread::DB, from_here, |
| 548 base::Bind(&WebDataService::DBResultTaskWrapper, this, task, request)); |
| 549 } else { |
| 550 NOTREACHED() << "Task scheduled after Shutdown()"; |
| 551 } |
| 552 return request->GetHandle(); |
| 553 } |
| 554 |
| 555 void WebDataService::DBTaskWrapper(const base::Closure& task, |
| 556 WebDataRequest* request) { |
| 557 InitializeDatabaseIfNecessary(); |
| 558 if (db_ && !request->IsCancelled()) { |
| 559 task.Run(); |
| 560 } |
| 561 request->RequestComplete(); |
| 562 } |
| 563 |
| 564 void WebDataService::DBResultTaskWrapper(const ResultTask& task, |
| 565 WebDataRequest* request) { |
| 566 InitializeDatabaseIfNecessary(); |
| 567 if (db_ && !request->IsCancelled()) { |
| 568 request->SetResult(task.Run().Pass()); |
| 569 } |
| 570 request->RequestComplete(); |
| 571 } |
| 572 |
639 void WebDataService::ScheduleCommit() { | 573 void WebDataService::ScheduleCommit() { |
640 if (should_commit_ == false) { | 574 if (should_commit_ == false) { |
641 should_commit_ = true; | 575 should_commit_ = true; |
642 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); | 576 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); |
643 } | 577 } |
644 } | 578 } |
645 | 579 |
646 //////////////////////////////////////////////////////////////////////////////// | 580 //////////////////////////////////////////////////////////////////////////////// |
647 // | 581 // |
648 // Keywords implementation. | 582 // Keywords implementation. |
649 // | 583 // |
650 //////////////////////////////////////////////////////////////////////////////// | 584 //////////////////////////////////////////////////////////////////////////////// |
651 | 585 |
652 void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) { | 586 void WebDataService::AddKeywordImpl(const TemplateURLData& data) { |
653 InitializeDatabaseIfNecessary(); | 587 db_->GetKeywordTable()->AddKeyword(data); |
654 if (db_ && !request->IsCancelled()) { | 588 ScheduleCommit(); |
655 db_->GetKeywordTable()->AddKeyword(request->arg()); | |
656 ScheduleCommit(); | |
657 } | |
658 request->RequestComplete(); | |
659 } | 589 } |
660 | 590 |
661 void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) { | 591 void WebDataService::RemoveKeywordImpl(TemplateURLID id) { |
662 InitializeDatabaseIfNecessary(); | 592 DCHECK(id); |
663 if (db_ && !request->IsCancelled()) { | 593 db_->GetKeywordTable()->RemoveKeyword(id); |
664 DCHECK(request->arg()); | 594 ScheduleCommit(); |
665 db_->GetKeywordTable()->RemoveKeyword(request->arg()); | |
666 ScheduleCommit(); | |
667 } | |
668 request->RequestComplete(); | |
669 } | 595 } |
670 | 596 |
671 void WebDataService::UpdateKeywordImpl( | 597 void WebDataService::UpdateKeywordImpl(const TemplateURLData& data) { |
672 GenericRequest<TemplateURLData>* request) { | 598 if (!db_->GetKeywordTable()->UpdateKeyword(data)) { |
673 InitializeDatabaseIfNecessary(); | 599 NOTREACHED(); |
674 if (db_ && !request->IsCancelled()) { | 600 return; |
675 if (!db_->GetKeywordTable()->UpdateKeyword(request->arg())) { | |
676 NOTREACHED(); | |
677 return; | |
678 } | |
679 ScheduleCommit(); | |
680 } | 601 } |
681 request->RequestComplete(); | 602 ScheduleCommit(); |
682 } | 603 } |
683 | 604 |
684 void WebDataService::GetKeywordsImpl(WebDataRequest* request) { | 605 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl() { |
685 InitializeDatabaseIfNecessary(); | 606 WDKeywordsResult result; |
686 if (db_ && !request->IsCancelled()) { | 607 db_->GetKeywordTable()->GetKeywords(&result.keywords); |
687 WDKeywordsResult result; | 608 result.default_search_provider_id = |
688 db_->GetKeywordTable()->GetKeywords(&result.keywords); | 609 db_->GetKeywordTable()->GetDefaultSearchProviderID(); |
689 result.default_search_provider_id = | 610 result.builtin_keyword_version = |
690 db_->GetKeywordTable()->GetDefaultSearchProviderID(); | 611 db_->GetKeywordTable()->GetBuiltinKeywordVersion(); |
691 result.builtin_keyword_version = | 612 return scoped_ptr<WDTypedResult>( |
692 db_->GetKeywordTable()->GetBuiltinKeywordVersion(); | 613 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); |
693 request->SetResult( | |
694 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); | |
695 } | |
696 request->RequestComplete(); | |
697 } | 614 } |
698 | 615 |
699 void WebDataService::SetDefaultSearchProviderImpl( | 616 void WebDataService::SetDefaultSearchProviderImpl(TemplateURLID id) { |
700 GenericRequest<TemplateURLID>* request) { | 617 if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(id)) { |
701 InitializeDatabaseIfNecessary(); | 618 NOTREACHED(); |
702 if (db_ && !request->IsCancelled()) { | 619 return; |
703 if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(request->arg())) { | |
704 NOTREACHED(); | |
705 return; | |
706 } | |
707 ScheduleCommit(); | |
708 } | 620 } |
709 request->RequestComplete(); | 621 ScheduleCommit(); |
710 } | 622 } |
711 | 623 |
712 void WebDataService::SetBuiltinKeywordVersionImpl( | 624 void WebDataService::SetBuiltinKeywordVersionImpl(int version) { |
713 GenericRequest<int>* request) { | 625 if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(version)) { |
714 InitializeDatabaseIfNecessary(); | 626 NOTREACHED(); |
715 if (db_ && !request->IsCancelled()) { | 627 return; |
716 if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(request->arg())) { | |
717 NOTREACHED(); | |
718 return; | |
719 } | |
720 ScheduleCommit(); | |
721 } | 628 } |
722 request->RequestComplete(); | 629 ScheduleCommit(); |
723 } | 630 } |
724 | 631 |
725 //////////////////////////////////////////////////////////////////////////////// | 632 //////////////////////////////////////////////////////////////////////////////// |
726 // | 633 // |
727 // Web Apps implementation. | 634 // Web Apps implementation. |
728 // | 635 // |
729 //////////////////////////////////////////////////////////////////////////////// | 636 //////////////////////////////////////////////////////////////////////////////// |
730 | 637 |
731 void WebDataService::SetWebAppImageImpl( | 638 void WebDataService::SetWebAppImageImpl( |
732 GenericRequest2<GURL, SkBitmap>* request) { | 639 const GURL& app_url, const SkBitmap& image) { |
733 InitializeDatabaseIfNecessary(); | 640 db_->GetWebAppsTable()->SetWebAppImage(app_url, image); |
734 if (db_ && !request->IsCancelled()) { | 641 ScheduleCommit(); |
735 db_->GetWebAppsTable()->SetWebAppImage( | |
736 request->arg1(), request->arg2()); | |
737 ScheduleCommit(); | |
738 } | |
739 request->RequestComplete(); | |
740 } | 642 } |
741 | 643 |
742 void WebDataService::SetWebAppHasAllImagesImpl( | 644 void WebDataService::SetWebAppHasAllImagesImpl( |
743 GenericRequest2<GURL, bool>* request) { | 645 const GURL& app_url, bool has_all_images) { |
744 InitializeDatabaseIfNecessary(); | 646 db_->GetWebAppsTable()->SetWebAppHasAllImages(app_url, has_all_images); |
745 if (db_ && !request->IsCancelled()) { | 647 ScheduleCommit(); |
746 db_->GetWebAppsTable()->SetWebAppHasAllImages(request->arg1(), | |
747 request->arg2()); | |
748 ScheduleCommit(); | |
749 } | |
750 request->RequestComplete(); | |
751 } | 648 } |
752 | 649 |
753 void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) { | 650 void WebDataService::RemoveWebAppImpl(const GURL& app_url) { |
754 InitializeDatabaseIfNecessary(); | 651 db_->GetWebAppsTable()->RemoveWebApp(app_url); |
755 if (db_ && !request->IsCancelled()) { | 652 ScheduleCommit(); |
756 db_->GetWebAppsTable()->RemoveWebApp(request->arg()); | |
757 ScheduleCommit(); | |
758 } | |
759 request->RequestComplete(); | |
760 } | 653 } |
761 | 654 |
762 void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { | 655 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl( |
763 InitializeDatabaseIfNecessary(); | 656 const GURL& app_url) { |
764 if (db_ && !request->IsCancelled()) { | 657 WDAppImagesResult result; |
765 WDAppImagesResult result; | 658 result.has_all_images = |
766 result.has_all_images = | 659 db_->GetWebAppsTable()->GetWebAppHasAllImages(app_url); |
767 db_->GetWebAppsTable()->GetWebAppHasAllImages(request->arg()); | 660 db_->GetWebAppsTable()->GetWebAppImages(app_url, &result.images); |
768 db_->GetWebAppsTable()->GetWebAppImages(request->arg(), &result.images); | 661 return scoped_ptr<WDTypedResult>( |
769 request->SetResult( | 662 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); |
770 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); | |
771 } | |
772 request->RequestComplete(); | |
773 } | 663 } |
774 | 664 |
775 //////////////////////////////////////////////////////////////////////////////// | 665 //////////////////////////////////////////////////////////////////////////////// |
776 // | 666 // |
777 // Web Intents implementation. | 667 // Web Intents implementation. |
778 // | 668 // |
779 //////////////////////////////////////////////////////////////////////////////// | 669 //////////////////////////////////////////////////////////////////////////////// |
780 | 670 |
781 void WebDataService::RemoveWebIntentServiceImpl( | 671 void WebDataService::RemoveWebIntentServiceImpl( |
782 GenericRequest<WebIntentServiceData>* request) { | 672 const webkit_glue::WebIntentServiceData& service) { |
783 InitializeDatabaseIfNecessary(); | 673 db_->GetWebIntentsTable()->RemoveWebIntentService(service); |
784 if (db_ && !request->IsCancelled()) { | 674 ScheduleCommit(); |
785 const WebIntentServiceData& service = request->arg(); | |
786 db_->GetWebIntentsTable()->RemoveWebIntentService(service); | |
787 ScheduleCommit(); | |
788 } | |
789 request->RequestComplete(); | |
790 } | 675 } |
791 | 676 |
792 void WebDataService::AddWebIntentServiceImpl( | 677 void WebDataService::AddWebIntentServiceImpl( |
793 GenericRequest<WebIntentServiceData>* request) { | 678 const webkit_glue::WebIntentServiceData& service) { |
794 InitializeDatabaseIfNecessary(); | 679 db_->GetWebIntentsTable()->SetWebIntentService(service); |
795 if (db_ && !request->IsCancelled()) { | 680 ScheduleCommit(); |
796 const WebIntentServiceData& service = request->arg(); | |
797 db_->GetWebIntentsTable()->SetWebIntentService(service); | |
798 ScheduleCommit(); | |
799 } | |
800 request->RequestComplete(); | |
801 } | 681 } |
802 | 682 |
803 | 683 |
804 void WebDataService::GetWebIntentServicesImpl( | 684 scoped_ptr<WDTypedResult> WebDataService::GetWebIntentServicesImpl( |
805 GenericRequest<string16>* request) { | 685 const string16& action) { |
806 InitializeDatabaseIfNecessary(); | 686 std::vector<WebIntentServiceData> result; |
807 if (db_ && !request->IsCancelled()) { | 687 db_->GetWebIntentsTable()->GetWebIntentServicesForAction(action, &result); |
808 std::vector<WebIntentServiceData> result; | 688 return scoped_ptr<WDTypedResult>( |
809 db_->GetWebIntentsTable()->GetWebIntentServicesForAction(request->arg(), | 689 new WDResult<std::vector<WebIntentServiceData> >( |
810 &result); | 690 WEB_INTENTS_RESULT, result)); |
811 request->SetResult(new WDResult<std::vector<WebIntentServiceData> >( | |
812 WEB_INTENTS_RESULT, result)); | |
813 } | |
814 request->RequestComplete(); | |
815 } | 691 } |
816 | 692 |
817 void WebDataService::GetWebIntentServicesForURLImpl( | 693 scoped_ptr<WDTypedResult> WebDataService::GetWebIntentServicesForURLImpl( |
818 GenericRequest<string16>* request) { | 694 const string16& service_url) { |
819 InitializeDatabaseIfNecessary(); | 695 std::vector<WebIntentServiceData> result; |
820 if (db_ && !request->IsCancelled()) { | 696 db_->GetWebIntentsTable()->GetWebIntentServicesForURL(service_url, &result); |
821 std::vector<WebIntentServiceData> result; | 697 return scoped_ptr<WDTypedResult>( |
822 db_->GetWebIntentsTable()->GetWebIntentServicesForURL( | 698 new WDResult<std::vector<WebIntentServiceData> >( |
823 request->arg(), &result); | 699 WEB_INTENTS_RESULT, result)); |
824 request->SetResult( | |
825 new WDResult<std::vector<WebIntentServiceData> >( | |
826 WEB_INTENTS_RESULT, result)); | |
827 } | |
828 request->RequestComplete(); | |
829 } | 700 } |
830 | 701 |
831 void WebDataService::GetAllWebIntentServicesImpl( | 702 scoped_ptr<WDTypedResult> WebDataService::GetAllWebIntentServicesImpl() { |
832 GenericRequest<std::string>* request) { | 703 std::vector<WebIntentServiceData> result; |
833 InitializeDatabaseIfNecessary(); | 704 db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); |
834 if (db_ && !request->IsCancelled()) { | 705 return scoped_ptr<WDTypedResult>( |
835 std::vector<WebIntentServiceData> result; | 706 new WDResult<std::vector<WebIntentServiceData> >( |
836 db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); | 707 WEB_INTENTS_RESULT, result)); |
837 request->SetResult( | |
838 new WDResult<std::vector<WebIntentServiceData> >( | |
839 WEB_INTENTS_RESULT, result)); | |
840 } | |
841 request->RequestComplete(); | |
842 } | 708 } |
843 | 709 |
844 void WebDataService::AddDefaultWebIntentServiceImpl( | 710 void WebDataService::AddDefaultWebIntentServiceImpl( |
845 GenericRequest<DefaultWebIntentService>* request) { | 711 const DefaultWebIntentService& service) { |
846 InitializeDatabaseIfNecessary(); | 712 db_->GetWebIntentsTable()->SetDefaultService(service); |
847 if (db_ && !request->IsCancelled()) { | 713 ScheduleCommit(); |
848 const DefaultWebIntentService& service = request->arg(); | |
849 db_->GetWebIntentsTable()->SetDefaultService(service); | |
850 ScheduleCommit(); | |
851 } | |
852 request->RequestComplete(); | |
853 } | 714 } |
854 | 715 |
855 void WebDataService::RemoveDefaultWebIntentServiceImpl( | 716 void WebDataService::RemoveDefaultWebIntentServiceImpl( |
856 GenericRequest<DefaultWebIntentService>* request) { | 717 const DefaultWebIntentService& service) { |
857 InitializeDatabaseIfNecessary(); | 718 db_->GetWebIntentsTable()->RemoveDefaultService(service); |
858 if (db_ && !request->IsCancelled()) { | 719 ScheduleCommit(); |
859 const DefaultWebIntentService& service = request->arg(); | |
860 db_->GetWebIntentsTable()->RemoveDefaultService(service); | |
861 ScheduleCommit(); | |
862 } | |
863 request->RequestComplete(); | |
864 } | 720 } |
865 | 721 |
866 void WebDataService::RemoveWebIntentServiceDefaultsImpl( | 722 void WebDataService::RemoveWebIntentServiceDefaultsImpl( |
867 GenericRequest<GURL>* request) { | 723 const GURL& service_url) { |
868 InitializeDatabaseIfNecessary(); | 724 db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); |
869 if (db_ && !request->IsCancelled()) { | 725 ScheduleCommit(); |
870 const GURL& service_url = request->arg(); | |
871 db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); | |
872 ScheduleCommit(); | |
873 } | |
874 request->RequestComplete(); | |
875 } | 726 } |
876 | 727 |
877 void WebDataService::GetDefaultWebIntentServicesForActionImpl( | 728 scoped_ptr<WDTypedResult> |
878 GenericRequest<string16>* request) { | 729 WebDataService::GetDefaultWebIntentServicesForActionImpl( |
879 InitializeDatabaseIfNecessary(); | 730 const string16& action) { |
880 if (db_ && !request->IsCancelled()) { | 731 std::vector<DefaultWebIntentService> result; |
881 std::vector<DefaultWebIntentService> result; | 732 db_->GetWebIntentsTable()->GetDefaultServices(action, &result); |
882 db_->GetWebIntentsTable()->GetDefaultServices( | 733 return scoped_ptr<WDTypedResult>( |
883 request->arg(), &result); | 734 new WDResult<std::vector<DefaultWebIntentService> >( |
884 request->SetResult( | 735 WEB_INTENTS_DEFAULTS_RESULT, result)); |
885 new WDResult<std::vector<DefaultWebIntentService> >( | |
886 WEB_INTENTS_DEFAULTS_RESULT, result)); | |
887 } | |
888 request->RequestComplete(); | |
889 } | 736 } |
890 | 737 |
891 void WebDataService::GetAllDefaultWebIntentServicesImpl( | 738 scoped_ptr<WDTypedResult> WebDataService::GetAllDefaultWebIntentServicesImpl() { |
892 GenericRequest<std::string>* request) { | 739 std::vector<DefaultWebIntentService> result; |
893 InitializeDatabaseIfNecessary(); | 740 db_->GetWebIntentsTable()->GetAllDefaultServices(&result); |
894 if (db_ && !request->IsCancelled()) { | 741 return scoped_ptr<WDTypedResult>( |
895 std::vector<DefaultWebIntentService> result; | 742 new WDResult<std::vector<DefaultWebIntentService> >( |
896 db_->GetWebIntentsTable()->GetAllDefaultServices(&result); | 743 WEB_INTENTS_DEFAULTS_RESULT, result)); |
897 request->SetResult( | |
898 new WDResult<std::vector<DefaultWebIntentService> >( | |
899 WEB_INTENTS_DEFAULTS_RESULT, result)); | |
900 } | |
901 request->RequestComplete(); | |
902 } | 744 } |
903 | 745 |
904 //////////////////////////////////////////////////////////////////////////////// | 746 //////////////////////////////////////////////////////////////////////////////// |
905 // | 747 // |
906 // Token Service implementation. | 748 // Token Service implementation. |
907 // | 749 // |
908 //////////////////////////////////////////////////////////////////////////////// | 750 //////////////////////////////////////////////////////////////////////////////// |
909 | 751 |
910 // argument std::string is unused | 752 void WebDataService::RemoveAllTokensImpl() { |
911 void WebDataService::RemoveAllTokensImpl( | 753 if (db_->GetTokenServiceTable()->RemoveAllTokens()) { |
912 GenericRequest<std::string>* request) { | 754 ScheduleCommit(); |
913 InitializeDatabaseIfNecessary(); | |
914 if (db_ && !request->IsCancelled()) { | |
915 if (db_->GetTokenServiceTable()->RemoveAllTokens()) { | |
916 ScheduleCommit(); | |
917 } | |
918 } | 755 } |
919 request->RequestComplete(); | |
920 } | 756 } |
921 | 757 |
922 void WebDataService::SetTokenForServiceImpl( | 758 void WebDataService::SetTokenForServiceImpl(const std::string& service, |
923 GenericRequest2<std::string, std::string>* request) { | 759 const std::string& token) { |
924 InitializeDatabaseIfNecessary(); | 760 if (db_->GetTokenServiceTable()->SetTokenForService(service, token)) { |
925 if (db_ && !request->IsCancelled()) { | 761 ScheduleCommit(); |
926 if (db_->GetTokenServiceTable()->SetTokenForService( | |
927 request->arg1(), request->arg2())) { | |
928 ScheduleCommit(); | |
929 } | |
930 } | 762 } |
931 request->RequestComplete(); | |
932 } | 763 } |
933 | 764 |
934 // argument is unused | 765 scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl() { |
935 void WebDataService::GetAllTokensImpl( | 766 std::map<std::string, std::string> map; |
936 GenericRequest<std::string>* request) { | 767 db_->GetTokenServiceTable()->GetAllTokens(&map); |
937 InitializeDatabaseIfNecessary(); | 768 return scoped_ptr<WDTypedResult>( |
938 if (db_ && !request->IsCancelled()) { | 769 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); |
939 std::map<std::string, std::string> map; | |
940 db_->GetTokenServiceTable()->GetAllTokens(&map); | |
941 request->SetResult( | |
942 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); | |
943 } | |
944 request->RequestComplete(); | |
945 } | 770 } |
946 | 771 |
947 //////////////////////////////////////////////////////////////////////////////// | 772 //////////////////////////////////////////////////////////////////////////////// |
948 // | 773 // |
949 // Autofill implementation. | 774 // Autofill implementation. |
950 // | 775 // |
951 //////////////////////////////////////////////////////////////////////////////// | 776 //////////////////////////////////////////////////////////////////////////////// |
952 | 777 |
953 void WebDataService::AddFormElementsImpl( | 778 void WebDataService::AddFormElementsImpl( |
954 GenericRequest<std::vector<FormFieldData> >* request) { | 779 const std::vector<FormFieldData>& fields) { |
955 InitializeDatabaseIfNecessary(); | 780 AutofillChangeList changes; |
956 if (db_ && !request->IsCancelled()) { | 781 if (!db_->GetAutofillTable()->AddFormFieldValues(fields, &changes)) { |
| 782 NOTREACHED(); |
| 783 return; |
| 784 } |
| 785 ScheduleCommit(); |
| 786 |
| 787 // Post the notifications including the list of affected keys. |
| 788 // This is sent here so that work resulting from this notification will be |
| 789 // done on the DB thread, and not the UI thread. |
| 790 content::NotificationService::current()->Notify( |
| 791 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 792 content::Source<WebDataService>(this), |
| 793 content::Details<AutofillChangeList>(&changes)); |
| 794 } |
| 795 |
| 796 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl( |
| 797 const string16& name, const string16& prefix, int limit) { |
| 798 std::vector<string16> values; |
| 799 db_->GetAutofillTable()->GetFormValuesForElementName( |
| 800 name, prefix, &values, limit); |
| 801 return scoped_ptr<WDTypedResult>( |
| 802 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); |
| 803 } |
| 804 |
| 805 void WebDataService::RemoveFormElementsAddedBetweenImpl( |
| 806 const base::Time& delete_begin, const base::Time& delete_end) { |
| 807 AutofillChangeList changes; |
| 808 if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( |
| 809 delete_begin, delete_end, &changes)) { |
| 810 if (!changes.empty()) { |
| 811 // Post the notifications including the list of affected keys. |
| 812 // This is sent here so that work resulting from this notification |
| 813 // will be done on the DB thread, and not the UI thread. |
| 814 content::NotificationService::current()->Notify( |
| 815 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 816 content::Source<WebDataService>(this), |
| 817 content::Details<AutofillChangeList>(&changes)); |
| 818 } |
| 819 ScheduleCommit(); |
| 820 } |
| 821 } |
| 822 |
| 823 void WebDataService::RemoveExpiredFormElementsImpl() { |
| 824 AutofillChangeList changes; |
| 825 |
| 826 if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { |
| 827 if (!changes.empty()) { |
| 828 // Post the notifications including the list of affected keys. |
| 829 // This is sent here so that work resulting from this notification |
| 830 // will be done on the DB thread, and not the UI thread. |
| 831 content::NotificationService::current()->Notify( |
| 832 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 833 content::Source<WebDataService>(this), |
| 834 content::Details<AutofillChangeList>(&changes)); |
| 835 } |
| 836 ScheduleCommit(); |
| 837 } |
| 838 } |
| 839 |
| 840 void WebDataService::RemoveFormValueForElementNameImpl( |
| 841 const string16& name, const string16& value) { |
| 842 |
| 843 if (db_->GetAutofillTable()->RemoveFormElement(name, value)) { |
957 AutofillChangeList changes; | 844 AutofillChangeList changes; |
958 if (!db_->GetAutofillTable()->AddFormFieldValues( | 845 changes.push_back(AutofillChange(AutofillChange::REMOVE, |
959 request->arg(), &changes)) { | 846 AutofillKey(name, value))); |
960 NOTREACHED(); | |
961 return; | |
962 } | |
963 request->SetResult( | |
964 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); | |
965 ScheduleCommit(); | 847 ScheduleCommit(); |
966 | 848 |
967 // Post the notifications including the list of affected keys. | 849 // Post the notifications including the list of affected keys. |
968 // This is sent here so that work resulting from this notification will be | |
969 // done on the DB thread, and not the UI thread. | |
970 content::NotificationService::current()->Notify( | 850 content::NotificationService::current()->Notify( |
971 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 851 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
972 content::Source<WebDataService>(this), | 852 content::Source<WebDataService>(this), |
973 content::Details<AutofillChangeList>(&changes)); | 853 content::Details<AutofillChangeList>(&changes)); |
974 } | 854 } |
975 | 855 } |
976 request->RequestComplete(); | 856 |
977 } | 857 void WebDataService::AddAutofillProfileImpl(const AutofillProfile& profile) { |
978 | 858 if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { |
979 void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request, | 859 NOTREACHED(); |
980 const string16& name, const string16& prefix, int limit) { | 860 return; |
981 InitializeDatabaseIfNecessary(); | 861 } |
982 if (db_ && !request->IsCancelled()) { | 862 ScheduleCommit(); |
983 std::vector<string16> values; | 863 |
984 db_->GetAutofillTable()->GetFormValuesForElementName( | 864 // Send GUID-based notification. |
985 name, prefix, &values, limit); | 865 AutofillProfileChange change(AutofillProfileChange::ADD, |
986 request->SetResult( | 866 profile.guid(), &profile); |
987 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); | 867 content::NotificationService::current()->Notify( |
988 } | 868 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
989 request->RequestComplete(); | 869 content::Source<WebDataService>(this), |
990 } | 870 content::Details<AutofillProfileChange>(&change)); |
991 | 871 } |
992 void WebDataService::RemoveFormElementsAddedBetweenImpl( | 872 |
993 GenericRequest2<Time, Time>* request) { | 873 void WebDataService::UpdateAutofillProfileImpl(const AutofillProfile& profile) { |
994 InitializeDatabaseIfNecessary(); | 874 // Only perform the update if the profile exists. It is currently |
995 if (db_ && !request->IsCancelled()) { | 875 // valid to try to update a missing profile. We simply drop the write and |
996 AutofillChangeList changes; | 876 // the caller will detect this on the next refresh. |
997 if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( | 877 AutofillProfile* original_profile = NULL; |
998 request->arg1(), request->arg2(), &changes)) { | 878 if (!db_->GetAutofillTable()->GetAutofillProfile(profile.guid(), |
999 if (!changes.empty()) { | 879 &original_profile)) { |
1000 request->SetResult( | 880 return; |
1001 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); | 881 } |
1002 | 882 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
1003 // Post the notifications including the list of affected keys. | 883 |
1004 // This is sent here so that work resulting from this notification | 884 if (!db_->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { |
1005 // will be done on the DB thread, and not the UI thread. | 885 NOTREACHED(); |
1006 content::NotificationService::current()->Notify( | 886 return; |
1007 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 887 } |
1008 content::Source<WebDataService>(this), | 888 ScheduleCommit(); |
1009 content::Details<AutofillChangeList>(&changes)); | 889 |
1010 } | 890 // Send GUID-based notification. |
1011 ScheduleCommit(); | 891 AutofillProfileChange change(AutofillProfileChange::UPDATE, |
1012 } | 892 profile.guid(), &profile); |
1013 } | 893 content::NotificationService::current()->Notify( |
1014 request->RequestComplete(); | 894 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
1015 } | 895 content::Source<WebDataService>(this), |
1016 | 896 content::Details<AutofillProfileChange>(&change)); |
1017 void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) { | 897 } |
1018 InitializeDatabaseIfNecessary(); | 898 |
1019 if (db_ && !request->IsCancelled()) { | 899 void WebDataService::RemoveAutofillProfileImpl(const std::string& guid) { |
1020 AutofillChangeList changes; | 900 AutofillProfile* profile = NULL; |
1021 if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { | 901 if (!db_->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { |
1022 if (!changes.empty()) { | 902 NOTREACHED(); |
1023 request->SetResult( | 903 return; |
1024 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); | 904 } |
1025 | 905 scoped_ptr<AutofillProfile> scoped_profile(profile); |
1026 // Post the notifications including the list of affected keys. | 906 |
1027 // This is sent here so that work resulting from this notification | 907 if (!db_->GetAutofillTable()->RemoveAutofillProfile(guid)) { |
1028 // will be done on the DB thread, and not the UI thread. | 908 NOTREACHED(); |
1029 content::NotificationService::current()->Notify( | 909 return; |
1030 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 910 } |
1031 content::Source<WebDataService>(this), | 911 ScheduleCommit(); |
1032 content::Details<AutofillChangeList>(&changes)); | 912 |
1033 } | 913 // Send GUID-based notification. |
1034 ScheduleCommit(); | 914 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
1035 } | 915 content::NotificationService::current()->Notify( |
1036 } | 916 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
1037 request->RequestComplete(); | 917 content::Source<WebDataService>(this), |
1038 } | 918 content::Details<AutofillProfileChange>(&change)); |
1039 | 919 } |
1040 void WebDataService::RemoveFormValueForElementNameImpl( | 920 |
1041 GenericRequest2<string16, string16>* request) { | 921 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl() { |
1042 InitializeDatabaseIfNecessary(); | 922 std::vector<AutofillProfile*> profiles; |
1043 if (db_ && !request->IsCancelled()) { | 923 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
1044 const string16& name = request->arg1(); | 924 return scoped_ptr<WDTypedResult>( |
1045 const string16& value = request->arg2(); | 925 new WDResult<std::vector<AutofillProfile*> >( |
1046 | 926 AUTOFILL_PROFILES_RESULT, |
1047 if (db_->GetAutofillTable()->RemoveFormElement(name, value)) { | 927 base::Bind(&WebDataService::DestroyAutofillProfileResult, |
1048 AutofillChangeList changes; | 928 base::Unretained(this)), |
1049 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 929 profiles)); |
1050 AutofillKey(name, value))); | 930 } |
1051 request->SetResult( | 931 |
1052 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); | 932 void WebDataService::EmptyMigrationTrashImpl(bool notify_sync) { |
1053 ScheduleCommit(); | 933 if (notify_sync) { |
1054 | 934 std::vector<std::string> guids; |
1055 // Post the notifications including the list of affected keys. | 935 if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { |
1056 content::NotificationService::current()->Notify( | |
1057 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | |
1058 content::Source<WebDataService>(this), | |
1059 content::Details<AutofillChangeList>(&changes)); | |
1060 } | |
1061 } | |
1062 request->RequestComplete(); | |
1063 } | |
1064 | |
1065 void WebDataService::AddAutofillProfileImpl( | |
1066 GenericRequest<AutofillProfile>* request) { | |
1067 InitializeDatabaseIfNecessary(); | |
1068 if (db_ && !request->IsCancelled()) { | |
1069 const AutofillProfile& profile = request->arg(); | |
1070 if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { | |
1071 NOTREACHED(); | 936 NOTREACHED(); |
1072 return; | 937 return; |
1073 } | 938 } |
1074 ScheduleCommit(); | 939 |
1075 | 940 for (std::vector<std::string>::const_iterator iter = guids.begin(); |
1076 // Send GUID-based notification. | 941 iter != guids.end(); ++iter) { |
1077 AutofillProfileChange change(AutofillProfileChange::ADD, | 942 // Send GUID-based notification. |
1078 profile.guid(), &profile); | 943 AutofillProfileChange change(AutofillProfileChange::REMOVE, |
1079 content::NotificationService::current()->Notify( | 944 *iter, NULL); |
1080 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 945 content::NotificationService::current()->Notify( |
1081 content::Source<WebDataService>(this), | 946 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
1082 content::Details<AutofillProfileChange>(&change)); | 947 content::Source<WebDataService>(this), |
1083 } | 948 content::Details<AutofillProfileChange>(&change)); |
1084 request->RequestComplete(); | 949 } |
1085 } | 950 |
1086 | 951 // If we trashed any profiles they may have been merged, so send out |
1087 void WebDataService::UpdateAutofillProfileImpl( | 952 // update notifications as well. |
1088 GenericRequest<AutofillProfile>* request) { | 953 if (!guids.empty()) { |
1089 InitializeDatabaseIfNecessary(); | 954 std::vector<AutofillProfile*> profiles; |
1090 if (db_ && !request->IsCancelled()) { | 955 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
1091 const AutofillProfile& profile = request->arg(); | 956 for (std::vector<AutofillProfile*>::const_iterator |
1092 | 957 iter = profiles.begin(); |
1093 // Only perform the update if the profile exists. It is currently | 958 iter != profiles.end(); ++iter) { |
1094 // valid to try to update a missing profile. We simply drop the write and | 959 AutofillProfileChange change(AutofillProfileChange::UPDATE, |
1095 // the caller will detect this on the next refresh. | 960 (*iter)->guid(), *iter); |
1096 AutofillProfile* original_profile = NULL; | |
1097 if (!db_->GetAutofillTable()->GetAutofillProfile(profile.guid(), | |
1098 &original_profile)) { | |
1099 request->RequestComplete(); | |
1100 return; | |
1101 } | |
1102 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | |
1103 | |
1104 if (!db_->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { | |
1105 NOTREACHED(); | |
1106 return; | |
1107 } | |
1108 ScheduleCommit(); | |
1109 | |
1110 // Send GUID-based notification. | |
1111 AutofillProfileChange change(AutofillProfileChange::UPDATE, | |
1112 profile.guid(), &profile); | |
1113 content::NotificationService::current()->Notify( | |
1114 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | |
1115 content::Source<WebDataService>(this), | |
1116 content::Details<AutofillProfileChange>(&change)); | |
1117 } | |
1118 request->RequestComplete(); | |
1119 } | |
1120 | |
1121 void WebDataService::RemoveAutofillProfileImpl( | |
1122 GenericRequest<std::string>* request) { | |
1123 InitializeDatabaseIfNecessary(); | |
1124 if (db_ && !request->IsCancelled()) { | |
1125 const std::string& guid = request->arg(); | |
1126 | |
1127 AutofillProfile* profile = NULL; | |
1128 if (!db_->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { | |
1129 NOTREACHED(); | |
1130 return; | |
1131 } | |
1132 scoped_ptr<AutofillProfile> scoped_profile(profile); | |
1133 | |
1134 if (!db_->GetAutofillTable()->RemoveAutofillProfile(guid)) { | |
1135 NOTREACHED(); | |
1136 return; | |
1137 } | |
1138 ScheduleCommit(); | |
1139 | |
1140 // Send GUID-based notification. | |
1141 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | |
1142 content::NotificationService::current()->Notify( | |
1143 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | |
1144 content::Source<WebDataService>(this), | |
1145 content::Details<AutofillProfileChange>(&change)); | |
1146 } | |
1147 request->RequestComplete(); | |
1148 } | |
1149 | |
1150 void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) { | |
1151 InitializeDatabaseIfNecessary(); | |
1152 if (db_ && !request->IsCancelled()) { | |
1153 std::vector<AutofillProfile*> profiles; | |
1154 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); | |
1155 request->SetResult( | |
1156 new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, | |
1157 base::Bind(&WebDataService::DestroyAutofillProfileResult, | |
1158 base::Unretained(this)), profiles)); | |
1159 } | |
1160 request->RequestComplete(); | |
1161 } | |
1162 | |
1163 void WebDataService::EmptyMigrationTrashImpl( | |
1164 GenericRequest<bool>* request) { | |
1165 InitializeDatabaseIfNecessary(); | |
1166 if (db_ && !request->IsCancelled()) { | |
1167 bool notify_sync = request->arg(); | |
1168 if (notify_sync) { | |
1169 std::vector<std::string> guids; | |
1170 if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { | |
1171 NOTREACHED(); | |
1172 return; | |
1173 } | |
1174 | |
1175 for (std::vector<std::string>::const_iterator iter = guids.begin(); | |
1176 iter != guids.end(); ++iter) { | |
1177 // Send GUID-based notification. | |
1178 AutofillProfileChange change(AutofillProfileChange::REMOVE, | |
1179 *iter, NULL); | |
1180 content::NotificationService::current()->Notify( | 961 content::NotificationService::current()->Notify( |
1181 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 962 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
1182 content::Source<WebDataService>(this), | 963 content::Source<WebDataService>(this), |
1183 content::Details<AutofillProfileChange>(&change)); | 964 content::Details<AutofillProfileChange>(&change)); |
1184 } | 965 } |
1185 | 966 STLDeleteElements(&profiles); |
1186 // If we trashed any profiles they may have been merged, so send out | 967 } |
1187 // update notifications as well. | 968 } |
1188 if (!guids.empty()) { | 969 |
1189 std::vector<AutofillProfile*> profiles; | 970 if (!db_->GetAutofillTable()->EmptyAutofillProfilesTrash()) { |
1190 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); | 971 NOTREACHED(); |
1191 for (std::vector<AutofillProfile*>::const_iterator | 972 return; |
1192 iter = profiles.begin(); | 973 } |
1193 iter != profiles.end(); ++iter) { | 974 ScheduleCommit(); |
1194 AutofillProfileChange change(AutofillProfileChange::UPDATE, | 975 } |
1195 (*iter)->guid(), *iter); | 976 |
1196 content::NotificationService::current()->Notify( | 977 void WebDataService::AddCreditCardImpl(const CreditCard& credit_card) { |
1197 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 978 if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { |
1198 content::Source<WebDataService>(this), | 979 NOTREACHED(); |
1199 content::Details<AutofillProfileChange>(&change)); | 980 return; |
1200 } | 981 } |
1201 STLDeleteElements(&profiles); | 982 ScheduleCommit(); |
1202 } | 983 |
1203 } | 984 // Send GUID-based notification. |
1204 | 985 AutofillCreditCardChange change(AutofillCreditCardChange::ADD, |
1205 if (!db_->GetAutofillTable()->EmptyAutofillProfilesTrash()) { | 986 credit_card.guid(), &credit_card); |
1206 NOTREACHED(); | 987 content::NotificationService::current()->Notify( |
1207 return; | 988 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
1208 } | 989 content::Source<WebDataService>(this), |
| 990 content::Details<AutofillCreditCardChange>(&change)); |
| 991 } |
| 992 |
| 993 void WebDataService::UpdateCreditCardImpl(const CreditCard& credit_card) { |
| 994 // It is currently valid to try to update a missing profile. We simply drop |
| 995 // the write and the caller will detect this on the next refresh. |
| 996 CreditCard* original_credit_card = NULL; |
| 997 if (!db_->GetAutofillTable()->GetCreditCard(credit_card.guid(), |
| 998 &original_credit_card)) { |
| 999 return; |
| 1000 } |
| 1001 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
| 1002 |
| 1003 if (!db_->GetAutofillTable()->UpdateCreditCard(credit_card)) { |
| 1004 NOTREACHED(); |
| 1005 return; |
| 1006 } |
| 1007 ScheduleCommit(); |
| 1008 |
| 1009 // Send GUID-based notification. |
| 1010 AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, |
| 1011 credit_card.guid(), &credit_card); |
| 1012 content::NotificationService::current()->Notify( |
| 1013 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 1014 content::Source<WebDataService>(this), |
| 1015 content::Details<AutofillCreditCardChange>(&change)); |
| 1016 } |
| 1017 |
| 1018 void WebDataService::RemoveCreditCardImpl(const std::string& guid) { |
| 1019 if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { |
| 1020 NOTREACHED(); |
| 1021 return; |
| 1022 } |
| 1023 ScheduleCommit(); |
| 1024 |
| 1025 // Send GUID-based notification. |
| 1026 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, |
| 1027 NULL); |
| 1028 content::NotificationService::current()->Notify( |
| 1029 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 1030 content::Source<WebDataService>(this), |
| 1031 content::Details<AutofillCreditCardChange>(&change)); |
| 1032 } |
| 1033 |
| 1034 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl() { |
| 1035 std::vector<CreditCard*> credit_cards; |
| 1036 db_->GetAutofillTable()->GetCreditCards(&credit_cards); |
| 1037 return scoped_ptr<WDTypedResult>( |
| 1038 new WDResult<std::vector<CreditCard*> >( |
| 1039 AUTOFILL_CREDITCARDS_RESULT, |
| 1040 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, |
| 1041 base::Unretained(this)), |
| 1042 credit_cards)); |
| 1043 } |
| 1044 |
| 1045 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
| 1046 const base::Time& delete_begin, const base::Time& delete_end) { |
| 1047 std::vector<std::string> profile_guids; |
| 1048 std::vector<std::string> credit_card_guids; |
| 1049 if (db_->GetAutofillTable()-> |
| 1050 RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| 1051 delete_begin, |
| 1052 delete_end, |
| 1053 &profile_guids, |
| 1054 &credit_card_guids)) { |
| 1055 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| 1056 iter != profile_guids.end(); ++iter) { |
| 1057 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, |
| 1058 NULL); |
| 1059 content::NotificationService::current()->Notify( |
| 1060 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 1061 content::Source<WebDataService>(this), |
| 1062 content::Details<AutofillProfileChange>(&change)); |
| 1063 } |
| 1064 |
| 1065 for (std::vector<std::string>::iterator iter = credit_card_guids.begin(); |
| 1066 iter != credit_card_guids.end(); ++iter) { |
| 1067 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, |
| 1068 *iter, NULL); |
| 1069 content::NotificationService::current()->Notify( |
| 1070 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 1071 content::Source<WebDataService>(this), |
| 1072 content::Details<AutofillCreditCardChange>(&change)); |
| 1073 } |
| 1074 // Note: It is the caller's responsibility to post notifications for any |
| 1075 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
1209 ScheduleCommit(); | 1076 ScheduleCommit(); |
1210 } | 1077 } |
1211 request->RequestComplete(); | |
1212 } | |
1213 | |
1214 void WebDataService::AddCreditCardImpl( | |
1215 GenericRequest<CreditCard>* request) { | |
1216 InitializeDatabaseIfNecessary(); | |
1217 if (db_ && !request->IsCancelled()) { | |
1218 const CreditCard& credit_card = request->arg(); | |
1219 if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { | |
1220 NOTREACHED(); | |
1221 return; | |
1222 } | |
1223 ScheduleCommit(); | |
1224 | |
1225 // Send GUID-based notification. | |
1226 AutofillCreditCardChange change(AutofillCreditCardChange::ADD, | |
1227 credit_card.guid(), &credit_card); | |
1228 content::NotificationService::current()->Notify( | |
1229 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | |
1230 content::Source<WebDataService>(this), | |
1231 content::Details<AutofillCreditCardChange>(&change)); | |
1232 } | |
1233 request->RequestComplete(); | |
1234 } | |
1235 | |
1236 void WebDataService::UpdateCreditCardImpl( | |
1237 GenericRequest<CreditCard>* request) { | |
1238 InitializeDatabaseIfNecessary(); | |
1239 if (db_ && !request->IsCancelled()) { | |
1240 const CreditCard& credit_card = request->arg(); | |
1241 | |
1242 // It is currently valid to try to update a missing profile. We simply drop | |
1243 // the write and the caller will detect this on the next refresh. | |
1244 CreditCard* original_credit_card = NULL; | |
1245 if (!db_->GetAutofillTable()->GetCreditCard(credit_card.guid(), | |
1246 &original_credit_card)) { | |
1247 request->RequestComplete(); | |
1248 return; | |
1249 } | |
1250 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); | |
1251 | |
1252 if (!db_->GetAutofillTable()->UpdateCreditCard(credit_card)) { | |
1253 NOTREACHED(); | |
1254 return; | |
1255 } | |
1256 ScheduleCommit(); | |
1257 | |
1258 // Send GUID-based notification. | |
1259 AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, | |
1260 credit_card.guid(), &credit_card); | |
1261 content::NotificationService::current()->Notify( | |
1262 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | |
1263 content::Source<WebDataService>(this), | |
1264 content::Details<AutofillCreditCardChange>(&change)); | |
1265 } | |
1266 request->RequestComplete(); | |
1267 } | |
1268 | |
1269 void WebDataService::RemoveCreditCardImpl( | |
1270 GenericRequest<std::string>* request) { | |
1271 InitializeDatabaseIfNecessary(); | |
1272 if (db_ && !request->IsCancelled()) { | |
1273 const std::string& guid = request->arg(); | |
1274 if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { | |
1275 NOTREACHED(); | |
1276 return; | |
1277 } | |
1278 ScheduleCommit(); | |
1279 | |
1280 // Send GUID-based notification. | |
1281 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, | |
1282 NULL); | |
1283 content::NotificationService::current()->Notify( | |
1284 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | |
1285 content::Source<WebDataService>(this), | |
1286 content::Details<AutofillCreditCardChange>(&change)); | |
1287 } | |
1288 request->RequestComplete(); | |
1289 } | |
1290 | |
1291 void WebDataService::GetCreditCardsImpl(WebDataRequest* request) { | |
1292 InitializeDatabaseIfNecessary(); | |
1293 if (db_ && !request->IsCancelled()) { | |
1294 std::vector<CreditCard*> credit_cards; | |
1295 db_->GetAutofillTable()->GetCreditCards(&credit_cards); | |
1296 request->SetResult( | |
1297 new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT, | |
1298 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, | |
1299 base::Unretained(this)), credit_cards)); | |
1300 } | |
1301 request->RequestComplete(); | |
1302 } | |
1303 | |
1304 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | |
1305 GenericRequest2<Time, Time>* request) { | |
1306 InitializeDatabaseIfNecessary(); | |
1307 if (db_ && !request->IsCancelled()) { | |
1308 std::vector<std::string> profile_guids; | |
1309 std::vector<std::string> credit_card_guids; | |
1310 if (db_->GetAutofillTable()-> | |
1311 RemoveAutofillProfilesAndCreditCardsModifiedBetween( | |
1312 request->arg1(), | |
1313 request->arg2(), | |
1314 &profile_guids, | |
1315 &credit_card_guids)) { | |
1316 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | |
1317 iter != profile_guids.end(); ++iter) { | |
1318 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, | |
1319 NULL); | |
1320 content::NotificationService::current()->Notify( | |
1321 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | |
1322 content::Source<WebDataService>(this), | |
1323 content::Details<AutofillProfileChange>(&change)); | |
1324 } | |
1325 | |
1326 for (std::vector<std::string>::iterator iter = credit_card_guids.begin(); | |
1327 iter != credit_card_guids.end(); ++iter) { | |
1328 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, | |
1329 *iter, NULL); | |
1330 content::NotificationService::current()->Notify( | |
1331 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | |
1332 content::Source<WebDataService>(this), | |
1333 content::Details<AutofillCreditCardChange>(&change)); | |
1334 } | |
1335 // Note: It is the caller's responsibility to post notifications for any | |
1336 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | |
1337 ScheduleCommit(); | |
1338 } | |
1339 } | |
1340 request->RequestComplete(); | |
1341 } | 1078 } |
1342 | 1079 |
1343 AutofillProfileSyncableService* | 1080 AutofillProfileSyncableService* |
1344 WebDataService::GetAutofillProfileSyncableService() const { | 1081 WebDataService::GetAutofillProfileSyncableService() const { |
1345 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 1082 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
1346 DCHECK(autofill_profile_syncable_service_); // Make sure we're initialized. | 1083 DCHECK(autofill_profile_syncable_service_); // Make sure we're initialized. |
1347 | 1084 |
1348 return autofill_profile_syncable_service_; | 1085 return autofill_profile_syncable_service_; |
1349 } | 1086 } |
1350 | 1087 |
(...skipping 15 matching lines...) Expand all Loading... |
1366 | 1103 |
1367 void WebDataService::DestroyAutofillCreditCardResult( | 1104 void WebDataService::DestroyAutofillCreditCardResult( |
1368 const WDTypedResult* result) { | 1105 const WDTypedResult* result) { |
1369 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 1106 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
1370 const WDResult<std::vector<CreditCard*> >* r = | 1107 const WDResult<std::vector<CreditCard*> >* r = |
1371 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 1108 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
1372 | 1109 |
1373 std::vector<CreditCard*> credit_cards = r->GetValue(); | 1110 std::vector<CreditCard*> credit_cards = r->GetValue(); |
1374 STLDeleteElements(&credit_cards); | 1111 STLDeleteElements(&credit_cards); |
1375 } | 1112 } |
OLD | NEW |