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

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

Issue 12957002: wd4-ui for try only (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wd4-ui_with_windows_fix 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/web_data_service.h" 5 #include "chrome/browser/webdata/web_data_service.h"
6 6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/message_loop.h"
10 #include "base/stl_util.h"
11 #include "base/threading/thread.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_manager.h"
14 #include "chrome/browser/search_engines/template_url.h" 7 #include "chrome/browser/search_engines/template_url.h"
15 #include "chrome/browser/ui/profile_error_dialog.h"
16 #include "chrome/browser/webdata/autocomplete_syncable_service.h" 8 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
17 #include "chrome/browser/webdata/autofill_change.h" 9 #include "chrome/browser/webdata/autofill_change.h"
18 #include "chrome/browser/webdata/autofill_entry.h" 10 #include "chrome/browser/webdata/autofill_entry.h"
19 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 11 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
20 #include "chrome/browser/webdata/autofill_table.h" 12 #include "chrome/browser/webdata/autofill_table.h"
21 #include "chrome/browser/webdata/keyword_table.h" 13 #include "chrome/browser/webdata/keyword_table.h"
22 #include "chrome/browser/webdata/logins_table.h" 14 #include "chrome/browser/webdata/logins_table.h"
23 #include "chrome/browser/webdata/token_service_table.h" 15 #include "chrome/browser/webdata/token_service_table.h"
24 #include "chrome/browser/webdata/web_apps_table.h" 16 #include "chrome/browser/webdata/web_apps_table.h"
25 #include "chrome/browser/webdata/web_database_service.h" 17 #include "chrome/browser/webdata/web_database_service.h"
26 #include "chrome/browser/webdata/web_intents_table.h" 18 #include "chrome/browser/webdata/web_intents_table.h"
27 #include "chrome/common/chrome_constants.h"
28 #include "chrome/common/chrome_notification_types.h" 19 #include "chrome/common/chrome_notification_types.h"
29 #include "components/autofill/browser/autofill_country.h" 20 #include "components/autofill/browser/autofill_country.h"
30 #include "components/autofill/browser/autofill_profile.h" 21 #include "components/autofill/browser/autofill_profile.h"
31 #include "components/autofill/browser/credit_card.h" 22 #include "components/autofill/browser/credit_card.h"
32 #include "components/autofill/common/form_field_data.h" 23 #include "components/autofill/common/form_field_data.h"
33 #ifdef DEBUG
34 #include "content/public/browser/browser_thread.h"
35 #endif
36 #include "content/public/browser/notification_details.h" 24 #include "content/public/browser/notification_details.h"
37 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
38 #include "content/public/browser/notification_source.h" 26 #include "content/public/browser/notification_source.h"
39 #include "grit/chromium_strings.h"
40 #include "grit/generated_resources.h"
41 #include "third_party/skia/include/core/SkBitmap.h" 27 #include "third_party/skia/include/core/SkBitmap.h"
42 28
43 //////////////////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////////////////
44 // 30 //
45 // WebDataService implementation. 31 // WebDataService implementation.
46 // 32 //
47 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
48 34
49 using base::Bind; 35 using base::Bind;
50 using base::Time; 36 using base::Time;
(...skipping 19 matching lines...) Expand all
70 56
71 WDAppImagesResult::~WDAppImagesResult() {} 57 WDAppImagesResult::~WDAppImagesResult() {}
72 58
73 WDKeywordsResult::WDKeywordsResult() 59 WDKeywordsResult::WDKeywordsResult()
74 : default_search_provider_id(0), 60 : default_search_provider_id(0),
75 builtin_keyword_version(0) { 61 builtin_keyword_version(0) {
76 } 62 }
77 63
78 WDKeywordsResult::~WDKeywordsResult() {} 64 WDKeywordsResult::~WDKeywordsResult() {}
79 65
80 WebDataService::WebDataService() 66 WebDataService::WebDataService(const ProfileErrorCallback& callback)
81 : db_loaded_(false), 67 : WebDataServiceBase(callback),
82 autocomplete_syncable_service_(NULL), 68 autocomplete_syncable_service_(NULL),
83 autofill_profile_syncable_service_(NULL) { 69 autofill_profile_syncable_service_(NULL) {
84 // WebDataService requires DB thread if instantiated.
85 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL)
86 // if you do not want to instantiate WebDataService in your test.
87 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB));
88 } 70 }
89 71
90 // static 72 // static
91 void WebDataService::NotifyOfMultipleAutofillChanges( 73 void WebDataService::NotifyOfMultipleAutofillChanges(
92 WebDataService* web_data_service) { 74 WebDataService* web_data_service) {
93 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 75 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
94 76
95 if (!web_data_service) 77 if (!web_data_service)
96 return; 78 return;
97 79
98 BrowserThread::PostTask( 80 BrowserThread::PostTask(
99 BrowserThread::UI, FROM_HERE, 81 BrowserThread::UI, FROM_HERE,
100 Bind(&NotifyOfMultipleAutofillChangesTask, 82 Bind(&NotifyOfMultipleAutofillChangesTask,
101 make_scoped_refptr(web_data_service))); 83 make_scoped_refptr(web_data_service)));
102 } 84 }
103 85
104 void WebDataService::ShutdownOnUIThread() { 86 void WebDataService::ShutdownOnUIThread() {
105 db_loaded_ = false;
106 ShutdownDatabase();
107 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 87 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
108 Bind(&WebDataService::ShutdownSyncableServices, this)); 88 Bind(&WebDataService::ShutdownSyncableServices, this));
89 WebDataServiceBase::ShutdownOnUIThread();
109 } 90 }
110 91
111 void WebDataService::Init(const base::FilePath& path) { 92 void WebDataService::Init(const base::FilePath& path) {
112 wdbs_.reset(new WebDatabaseService(path)); 93 WebDataServiceBase::Init(path);
113 wdbs_->LoadDatabase(Bind(&WebDataService::DatabaseInitOnDB, this));
114
115 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 94 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
116 Bind(&WebDataService::InitializeSyncableServices, this)); 95 Bind(&WebDataService::InitializeSyncableServices, this));
117 } 96 }
118 97
119 void WebDataService::UnloadDatabase() {
120 if (!wdbs_)
121 return;
122 wdbs_->UnloadDatabase();
123 }
124
125 void WebDataService::ShutdownDatabase() {
126 if (!wdbs_)
127 return;
128 wdbs_->ShutdownDatabase();
129 }
130
131 void WebDataService::CancelRequest(Handle h) {
132 if (!wdbs_)
133 return;
134 wdbs_->CancelRequest(h);
135 }
136
137 content::NotificationSource WebDataService::GetNotificationSource() {
138 return content::Source<WebDataService>(this);
139 }
140
141 bool WebDataService::IsDatabaseLoaded() {
142 return db_loaded_;
143 }
144
145 WebDatabase* WebDataService::GetDatabase() {
146 if (!wdbs_)
147 return NULL;
148 return wdbs_->GetDatabaseOnDB();
149 }
150
151 ////////////////////////////////////////////////////////////////////////////// 98 //////////////////////////////////////////////////////////////////////////////
152 // 99 //
153 // Keywords. 100 // Keywords.
154 // 101 //
155 ////////////////////////////////////////////////////////////////////////////// 102 //////////////////////////////////////////////////////////////////////////////
156 103
157 void WebDataService::AddKeyword(const TemplateURLData& data) { 104 void WebDataService::AddKeyword(const TemplateURLData& data) {
158 wdbs_->ScheduleDBTask( 105 wdbs_->ScheduleDBTask(
159 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data)); 106 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data));
160 } 107 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 } 269 }
323 270
324 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( 271 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween(
325 const Time& delete_begin, 272 const Time& delete_begin,
326 const Time& delete_end) { 273 const Time& delete_end) {
327 wdbs_->ScheduleDBTask(FROM_HERE, Bind( 274 wdbs_->ScheduleDBTask(FROM_HERE, Bind(
328 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, 275 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl,
329 this, delete_begin, delete_end)); 276 this, delete_begin, delete_end));
330 } 277 }
331 278
279 WebDataService::WebDataService()
280 : WebDataServiceBase(ProfileErrorCallback()),
281 autocomplete_syncable_service_(NULL),
282 autofill_profile_syncable_service_(NULL) {
283 }
284
332 WebDataService::~WebDataService() { 285 WebDataService::~WebDataService() {
333 wdbs_.reset();
334 DCHECK(!autocomplete_syncable_service_); 286 DCHECK(!autocomplete_syncable_service_);
335 DCHECK(!autofill_profile_syncable_service_); 287 DCHECK(!autofill_profile_syncable_service_);
336 } 288 }
337 289
338 //////////////////////////////////////////////////////////////////////////////// 290 ////////////////////////////////////////////////////////////////////////////////
339 // 291 //
340 // The following methods are executed on the DB thread. 292 // The following methods are executed on the DB thread.
341 // 293 //
342 //////////////////////////////////////////////////////////////////////////////// 294 ////////////////////////////////////////////////////////////////////////////////
343 295
344 void WebDataService::DBInitFailed(sql::InitStatus sql_status) {
345 ShowProfileErrorDialog(
346 (sql_status == sql::INIT_FAILURE) ?
347 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
348 }
349
350 void WebDataService::NotifyDatabaseLoadedOnUIThread() {
351 db_loaded_ = true;
352 // Notify that the database has been initialized.
353 content::NotificationService::current()->Notify(
354 chrome::NOTIFICATION_WEB_DATABASE_LOADED,
355 content::Source<WebDataService>(this),
356 content::NotificationService::NoDetails());
357 }
358
359 void WebDataService::DatabaseInitOnDB(sql::InitStatus status) {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
361 if (status == sql::INIT_OK) {
362 BrowserThread::PostTask(
363 BrowserThread::UI, FROM_HERE,
364 base::Bind(&WebDataService::NotifyDatabaseLoadedOnUIThread, this));
365 } else {
366 BrowserThread::PostTask(
367 BrowserThread::UI, FROM_HERE,
368 base::Bind(&WebDataService::DBInitFailed, this, status));
369 }
370 }
371
372 void WebDataService::InitializeSyncableServices() { 296 void WebDataService::InitializeSyncableServices() {
373 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 297 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
374 DCHECK(!autocomplete_syncable_service_); 298 DCHECK(!autocomplete_syncable_service_);
375 DCHECK(!autofill_profile_syncable_service_); 299 DCHECK(!autofill_profile_syncable_service_);
376 300
377 autocomplete_syncable_service_ = new AutocompleteSyncableService(this); 301 autocomplete_syncable_service_ = new AutocompleteSyncableService(this);
378 autofill_profile_syncable_service_ = new AutofillProfileSyncableService(this); 302 autofill_profile_syncable_service_ = new AutofillProfileSyncableService(this);
379 } 303 }
380 304
381 void WebDataService::ShutdownSyncableServices() { 305 void WebDataService::ShutdownSyncableServices() {
382 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
383 307
384 delete autocomplete_syncable_service_; 308 delete autocomplete_syncable_service_;
385 autocomplete_syncable_service_ = NULL; 309 autocomplete_syncable_service_ = NULL;
386 delete autofill_profile_syncable_service_; 310 delete autofill_profile_syncable_service_;
387 autofill_profile_syncable_service_ = NULL; 311 autofill_profile_syncable_service_ = NULL;
388 } 312 }
389 313
390 //////////////////////////////////////////////////////////////////////////////// 314 ////////////////////////////////////////////////////////////////////////////////
391 // 315 //
392 // Keywords implementation. 316 // Keywords implementation.
393 // 317 //
394 //////////////////////////////////////////////////////////////////////////////// 318 ////////////////////////////////////////////////////////////////////////////////
395 319
396 WebDatabase::State WebDataService::AddKeywordImpl( 320 WebDatabase::State WebDataService::AddKeywordImpl(
397 const TemplateURLData& data, WebDatabase* db) { 321 const TemplateURLData& data, WebDatabase* db) {
398 db->GetKeywordTable()->AddKeyword(data); 322 KeywordTable::FromWebDatabase(db)->AddKeyword(data);
399 return WebDatabase::COMMIT_NEEDED; 323 return WebDatabase::COMMIT_NEEDED;
400 } 324 }
401 325
402 WebDatabase::State WebDataService::RemoveKeywordImpl( 326 WebDatabase::State WebDataService::RemoveKeywordImpl(
403 TemplateURLID id, WebDatabase* db) { 327 TemplateURLID id, WebDatabase* db) {
404 DCHECK(id); 328 DCHECK(id);
405 db->GetKeywordTable()->RemoveKeyword(id); 329 KeywordTable::FromWebDatabase(db)->RemoveKeyword(id);
406 return WebDatabase::COMMIT_NEEDED; 330 return WebDatabase::COMMIT_NEEDED;
407 } 331 }
408 332
409 WebDatabase::State WebDataService::UpdateKeywordImpl( 333 WebDatabase::State WebDataService::UpdateKeywordImpl(
410 const TemplateURLData& data, WebDatabase* db) { 334 const TemplateURLData& data, WebDatabase* db) {
411 if (!db->GetKeywordTable()->UpdateKeyword(data)) { 335 if (!KeywordTable::FromWebDatabase(db)->UpdateKeyword(data)) {
412 NOTREACHED(); 336 NOTREACHED();
413 return WebDatabase::COMMIT_NOT_NEEDED; 337 return WebDatabase::COMMIT_NOT_NEEDED;
414 } 338 }
415 return WebDatabase::COMMIT_NEEDED; 339 return WebDatabase::COMMIT_NEEDED;
416 } 340 }
417 341
418 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) { 342 scoped_ptr<WDTypedResult> WebDataService::GetKeywordsImpl(WebDatabase* db) {
419 WDKeywordsResult result; 343 WDKeywordsResult result;
420 db->GetKeywordTable()->GetKeywords(&result.keywords); 344 KeywordTable::FromWebDatabase(db)->GetKeywords(&result.keywords);
421 result.default_search_provider_id = 345 result.default_search_provider_id =
422 db->GetKeywordTable()->GetDefaultSearchProviderID(); 346 KeywordTable::FromWebDatabase(db)->GetDefaultSearchProviderID();
423 result.builtin_keyword_version = 347 result.builtin_keyword_version =
424 db->GetKeywordTable()->GetBuiltinKeywordVersion(); 348 KeywordTable::FromWebDatabase(db)->GetBuiltinKeywordVersion();
425 return scoped_ptr<WDTypedResult>( 349 return scoped_ptr<WDTypedResult>(
426 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); 350 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result));
427 } 351 }
428 352
429 WebDatabase::State WebDataService::SetDefaultSearchProviderImpl( 353 WebDatabase::State WebDataService::SetDefaultSearchProviderImpl(
430 TemplateURLID id, WebDatabase* db) { 354 TemplateURLID id, WebDatabase* db) {
431 if (!db->GetKeywordTable()->SetDefaultSearchProviderID(id)) { 355 if (!KeywordTable::FromWebDatabase(db)->SetDefaultSearchProviderID(id)) {
432 NOTREACHED(); 356 NOTREACHED();
433 return WebDatabase::COMMIT_NOT_NEEDED; 357 return WebDatabase::COMMIT_NOT_NEEDED;
434 } 358 }
435 return WebDatabase::COMMIT_NEEDED; 359 return WebDatabase::COMMIT_NEEDED;
436 } 360 }
437 361
438 WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl( 362 WebDatabase::State WebDataService::SetBuiltinKeywordVersionImpl(
439 int version, WebDatabase* db) { 363 int version, WebDatabase* db) {
440 if (!db->GetKeywordTable()->SetBuiltinKeywordVersion(version)) { 364 if (!KeywordTable::FromWebDatabase(db)->SetBuiltinKeywordVersion(version)) {
441 NOTREACHED(); 365 NOTREACHED();
442 return WebDatabase::COMMIT_NOT_NEEDED; 366 return WebDatabase::COMMIT_NOT_NEEDED;
443 } 367 }
444 return WebDatabase::COMMIT_NEEDED; 368 return WebDatabase::COMMIT_NEEDED;
445 } 369 }
446 370
447 //////////////////////////////////////////////////////////////////////////////// 371 ////////////////////////////////////////////////////////////////////////////////
448 // 372 //
449 // Web Apps implementation. 373 // Web Apps implementation.
450 // 374 //
451 //////////////////////////////////////////////////////////////////////////////// 375 ////////////////////////////////////////////////////////////////////////////////
452 376
453 WebDatabase::State WebDataService::SetWebAppImageImpl( 377 WebDatabase::State WebDataService::SetWebAppImageImpl(
454 const GURL& app_url, const SkBitmap& image, WebDatabase* db) { 378 const GURL& app_url, const SkBitmap& image, WebDatabase* db) {
455 db->GetWebAppsTable()->SetWebAppImage(app_url, image); 379 WebAppsTable::FromWebDatabase(db)->SetWebAppImage(app_url, image);
456 return WebDatabase::COMMIT_NEEDED; 380 return WebDatabase::COMMIT_NEEDED;
457 } 381 }
458 382
459 WebDatabase::State WebDataService::SetWebAppHasAllImagesImpl( 383 WebDatabase::State WebDataService::SetWebAppHasAllImagesImpl(
460 const GURL& app_url, bool has_all_images, WebDatabase* db) { 384 const GURL& app_url, bool has_all_images, WebDatabase* db) {
461 db->GetWebAppsTable()-> 385 WebAppsTable::FromWebDatabase(db)->SetWebAppHasAllImages(app_url,
462 SetWebAppHasAllImages(app_url, has_all_images); 386 has_all_images);
463 return WebDatabase::COMMIT_NEEDED; 387 return WebDatabase::COMMIT_NEEDED;
464 } 388 }
465 389
466 WebDatabase::State WebDataService::RemoveWebAppImpl( 390 WebDatabase::State WebDataService::RemoveWebAppImpl(
467 const GURL& app_url, WebDatabase* db) { 391 const GURL& app_url, WebDatabase* db) {
468 db->GetWebAppsTable()->RemoveWebApp(app_url); 392 WebAppsTable::FromWebDatabase(db)->RemoveWebApp(app_url);
469 return WebDatabase::COMMIT_NEEDED; 393 return WebDatabase::COMMIT_NEEDED;
470 } 394 }
471 395
472 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl( 396 scoped_ptr<WDTypedResult> WebDataService::GetWebAppImagesImpl(
473 const GURL& app_url, WebDatabase* db) { 397 const GURL& app_url, WebDatabase* db) {
474 WDAppImagesResult result; 398 WDAppImagesResult result;
475 result.has_all_images = db->GetWebAppsTable()->GetWebAppHasAllImages(app_url); 399 result.has_all_images =
476 db->GetWebAppsTable()->GetWebAppImages(app_url, &result.images); 400 WebAppsTable::FromWebDatabase(db)->GetWebAppHasAllImages(app_url);
401 WebAppsTable::FromWebDatabase(db)->GetWebAppImages(app_url, &result.images);
477 return scoped_ptr<WDTypedResult>( 402 return scoped_ptr<WDTypedResult>(
478 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); 403 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result));
479 } 404 }
480 405
481 //////////////////////////////////////////////////////////////////////////////// 406 ////////////////////////////////////////////////////////////////////////////////
482 // 407 //
483 // Token Service implementation. 408 // Token Service implementation.
484 // 409 //
485 //////////////////////////////////////////////////////////////////////////////// 410 ////////////////////////////////////////////////////////////////////////////////
486 411
487 WebDatabase::State WebDataService::RemoveAllTokensImpl(WebDatabase* db) { 412 WebDatabase::State WebDataService::RemoveAllTokensImpl(WebDatabase* db) {
488 if (db->GetTokenServiceTable()->RemoveAllTokens()) { 413 if (TokenServiceTable::FromWebDatabase(db)->RemoveAllTokens()) {
489 return WebDatabase::COMMIT_NEEDED; 414 return WebDatabase::COMMIT_NEEDED;
490 } 415 }
491 return WebDatabase::COMMIT_NOT_NEEDED; 416 return WebDatabase::COMMIT_NOT_NEEDED;
492 } 417 }
493 418
494 WebDatabase::State WebDataService::SetTokenForServiceImpl( 419 WebDatabase::State WebDataService::SetTokenForServiceImpl(
495 const std::string& service, const std::string& token, WebDatabase* db) { 420 const std::string& service, const std::string& token, WebDatabase* db) {
496 if (db->GetTokenServiceTable()->SetTokenForService(service, token)) { 421 if (TokenServiceTable::FromWebDatabase(db)->SetTokenForService(service,
422 token)) {
497 return WebDatabase::COMMIT_NEEDED; 423 return WebDatabase::COMMIT_NEEDED;
498 } 424 }
499 return WebDatabase::COMMIT_NOT_NEEDED; 425 return WebDatabase::COMMIT_NOT_NEEDED;
500 } 426 }
501 427
502 scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) { 428 scoped_ptr<WDTypedResult> WebDataService::GetAllTokensImpl(WebDatabase* db) {
503 std::map<std::string, std::string> map; 429 std::map<std::string, std::string> map;
504 db->GetTokenServiceTable()->GetAllTokens(&map); 430 TokenServiceTable::FromWebDatabase(db)->GetAllTokens(&map);
505 return scoped_ptr<WDTypedResult>( 431 return scoped_ptr<WDTypedResult>(
506 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); 432 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map));
507 } 433 }
508 434
509 //////////////////////////////////////////////////////////////////////////////// 435 ////////////////////////////////////////////////////////////////////////////////
510 // 436 //
511 // Autofill implementation. 437 // Autofill implementation.
512 // 438 //
513 //////////////////////////////////////////////////////////////////////////////// 439 ////////////////////////////////////////////////////////////////////////////////
514 440
515 WebDatabase::State WebDataService::AddFormElementsImpl( 441 WebDatabase::State WebDataService::AddFormElementsImpl(
516 const std::vector<FormFieldData>& fields, WebDatabase* db) { 442 const std::vector<FormFieldData>& fields, WebDatabase* db) {
517 AutofillChangeList changes; 443 AutofillChangeList changes;
518 if (!db->GetAutofillTable()->AddFormFieldValues(fields, &changes)) { 444 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues(
445 fields, &changes)) {
519 NOTREACHED(); 446 NOTREACHED();
520 return WebDatabase::COMMIT_NOT_NEEDED; 447 return WebDatabase::COMMIT_NOT_NEEDED;
521 } 448 }
522 449
523 // Post the notifications including the list of affected keys. 450 // Post the notifications including the list of affected keys.
524 // This is sent here so that work resulting from this notification will be 451 // This is sent here so that work resulting from this notification will be
525 // done on the DB thread, and not the UI thread. 452 // done on the DB thread, and not the UI thread.
526 content::NotificationService::current()->Notify( 453 content::NotificationService::current()->Notify(
527 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 454 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
528 content::Source<WebDataService>(this), 455 content::Source<WebDataService>(this),
529 content::Details<AutofillChangeList>(&changes)); 456 content::Details<AutofillChangeList>(&changes));
530 457
531 return WebDatabase::COMMIT_NEEDED; 458 return WebDatabase::COMMIT_NEEDED;
532 } 459 }
533 460
534 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl( 461 scoped_ptr<WDTypedResult> WebDataService::GetFormValuesForElementNameImpl(
535 const string16& name, const string16& prefix, int limit, WebDatabase* db) { 462 const string16& name, const string16& prefix, int limit, WebDatabase* db) {
536 std::vector<string16> values; 463 std::vector<string16> values;
537 db->GetAutofillTable()->GetFormValuesForElementName( 464 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName(
538 name, prefix, &values, limit); 465 name, prefix, &values, limit);
539 return scoped_ptr<WDTypedResult>( 466 return scoped_ptr<WDTypedResult>(
540 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); 467 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values));
541 } 468 }
542 469
543 WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl( 470 WebDatabase::State WebDataService::RemoveFormElementsAddedBetweenImpl(
544 const base::Time& delete_begin, const base::Time& delete_end, 471 const base::Time& delete_begin, const base::Time& delete_end,
545 WebDatabase* db) { 472 WebDatabase* db) {
546 AutofillChangeList changes; 473 AutofillChangeList changes;
547 474
548 if (db->GetAutofillTable()->RemoveFormElementsAddedBetween( 475 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween(
549 delete_begin, delete_end, &changes)) { 476 delete_begin, delete_end, &changes)) {
550 if (!changes.empty()) { 477 if (!changes.empty()) {
551 // Post the notifications including the list of affected keys. 478 // Post the notifications including the list of affected keys.
552 // This is sent here so that work resulting from this notification 479 // This is sent here so that work resulting from this notification
553 // will be done on the DB thread, and not the UI thread. 480 // will be done on the DB thread, and not the UI thread.
554 content::NotificationService::current()->Notify( 481 content::NotificationService::current()->Notify(
555 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 482 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
556 content::Source<WebDataService>(this), 483 content::Source<WebDataService>(this),
557 content::Details<AutofillChangeList>(&changes)); 484 content::Details<AutofillChangeList>(&changes));
558 } 485 }
559 return WebDatabase::COMMIT_NEEDED; 486 return WebDatabase::COMMIT_NEEDED;
560 } 487 }
561 return WebDatabase::COMMIT_NOT_NEEDED; 488 return WebDatabase::COMMIT_NOT_NEEDED;
562 } 489 }
563 490
564 WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl( 491 WebDatabase::State WebDataService::RemoveExpiredFormElementsImpl(
565 WebDatabase* db) { 492 WebDatabase* db) {
566 AutofillChangeList changes; 493 AutofillChangeList changes;
567 494
568 if (db->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { 495 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) {
569 if (!changes.empty()) { 496 if (!changes.empty()) {
570 // Post the notifications including the list of affected keys. 497 // Post the notifications including the list of affected keys.
571 // This is sent here so that work resulting from this notification 498 // This is sent here so that work resulting from this notification
572 // will be done on the DB thread, and not the UI thread. 499 // will be done on the DB thread, and not the UI thread.
573 content::NotificationService::current()->Notify( 500 content::NotificationService::current()->Notify(
574 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 501 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
575 content::Source<WebDataService>(this), 502 content::Source<WebDataService>(this),
576 content::Details<AutofillChangeList>(&changes)); 503 content::Details<AutofillChangeList>(&changes));
577 } 504 }
578 return WebDatabase::COMMIT_NEEDED; 505 return WebDatabase::COMMIT_NEEDED;
579 } 506 }
580 return WebDatabase::COMMIT_NOT_NEEDED; 507 return WebDatabase::COMMIT_NOT_NEEDED;
581 } 508 }
582 509
583 WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl( 510 WebDatabase::State WebDataService::RemoveFormValueForElementNameImpl(
584 const string16& name, const string16& value, WebDatabase* db) { 511 const string16& name, const string16& value, WebDatabase* db) {
585 512
586 if (db->GetAutofillTable()->RemoveFormElement(name, value)) { 513 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) {
587 AutofillChangeList changes; 514 AutofillChangeList changes;
588 changes.push_back(AutofillChange(AutofillChange::REMOVE, 515 changes.push_back(AutofillChange(AutofillChange::REMOVE,
589 AutofillKey(name, value))); 516 AutofillKey(name, value)));
590 517
591 // Post the notifications including the list of affected keys. 518 // Post the notifications including the list of affected keys.
592 content::NotificationService::current()->Notify( 519 content::NotificationService::current()->Notify(
593 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, 520 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED,
594 content::Source<WebDataService>(this), 521 content::Source<WebDataService>(this),
595 content::Details<AutofillChangeList>(&changes)); 522 content::Details<AutofillChangeList>(&changes));
596 523
597 return WebDatabase::COMMIT_NEEDED; 524 return WebDatabase::COMMIT_NEEDED;
598 } 525 }
599 return WebDatabase::COMMIT_NOT_NEEDED; 526 return WebDatabase::COMMIT_NOT_NEEDED;
600 } 527 }
601 528
602 WebDatabase::State WebDataService::AddAutofillProfileImpl( 529 WebDatabase::State WebDataService::AddAutofillProfileImpl(
603 const AutofillProfile& profile, WebDatabase* db) { 530 const AutofillProfile& profile, WebDatabase* db) {
604 if (!db->GetAutofillTable()->AddAutofillProfile(profile)) { 531 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) {
605 NOTREACHED(); 532 NOTREACHED();
606 return WebDatabase::COMMIT_NOT_NEEDED; 533 return WebDatabase::COMMIT_NOT_NEEDED;
607 } 534 }
608 535
609 // Send GUID-based notification. 536 // Send GUID-based notification.
610 AutofillProfileChange change(AutofillProfileChange::ADD, 537 AutofillProfileChange change(AutofillProfileChange::ADD,
611 profile.guid(), &profile); 538 profile.guid(), &profile);
612 content::NotificationService::current()->Notify( 539 content::NotificationService::current()->Notify(
613 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 540 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
614 content::Source<WebDataService>(this), 541 content::Source<WebDataService>(this),
615 content::Details<AutofillProfileChange>(&change)); 542 content::Details<AutofillProfileChange>(&change));
616 543
617 return WebDatabase::COMMIT_NEEDED; 544 return WebDatabase::COMMIT_NEEDED;
618 } 545 }
619 546
620 WebDatabase::State WebDataService::UpdateAutofillProfileImpl( 547 WebDatabase::State WebDataService::UpdateAutofillProfileImpl(
621 const AutofillProfile& profile, WebDatabase* db) { 548 const AutofillProfile& profile, WebDatabase* db) {
622 // Only perform the update if the profile exists. It is currently 549 // Only perform the update if the profile exists. It is currently
623 // valid to try to update a missing profile. We simply drop the write and 550 // valid to try to update a missing profile. We simply drop the write and
624 // the caller will detect this on the next refresh. 551 // the caller will detect this on the next refresh.
625 AutofillProfile* original_profile = NULL; 552 AutofillProfile* original_profile = NULL;
626 if (!db->GetAutofillTable()->GetAutofillProfile(profile.guid(), 553 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(),
627 &original_profile)) { 554 &original_profile)) {
628 return WebDatabase::COMMIT_NOT_NEEDED; 555 return WebDatabase::COMMIT_NOT_NEEDED;
629 } 556 }
630 scoped_ptr<AutofillProfile> scoped_profile(original_profile); 557 scoped_ptr<AutofillProfile> scoped_profile(original_profile);
631 558
632 if (!db->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { 559 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti(
560 profile)) {
633 NOTREACHED(); 561 NOTREACHED();
634 return WebDatabase::COMMIT_NEEDED; 562 return WebDatabase::COMMIT_NEEDED;
635 } 563 }
636 564
637 // Send GUID-based notification. 565 // Send GUID-based notification.
638 AutofillProfileChange change(AutofillProfileChange::UPDATE, 566 AutofillProfileChange change(AutofillProfileChange::UPDATE,
639 profile.guid(), &profile); 567 profile.guid(), &profile);
640 content::NotificationService::current()->Notify( 568 content::NotificationService::current()->Notify(
641 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 569 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
642 content::Source<WebDataService>(this), 570 content::Source<WebDataService>(this),
643 content::Details<AutofillProfileChange>(&change)); 571 content::Details<AutofillProfileChange>(&change));
644 572
645 return WebDatabase::COMMIT_NEEDED; 573 return WebDatabase::COMMIT_NEEDED;
646 } 574 }
647 575
648 WebDatabase::State WebDataService::RemoveAutofillProfileImpl( 576 WebDatabase::State WebDataService::RemoveAutofillProfileImpl(
649 const std::string& guid, WebDatabase* db) { 577 const std::string& guid, WebDatabase* db) {
650 AutofillProfile* profile = NULL; 578 AutofillProfile* profile = NULL;
651 if (!db->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { 579 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) {
652 NOTREACHED(); 580 NOTREACHED();
653 return WebDatabase::COMMIT_NOT_NEEDED; 581 return WebDatabase::COMMIT_NOT_NEEDED;
654 } 582 }
655 scoped_ptr<AutofillProfile> scoped_profile(profile); 583 scoped_ptr<AutofillProfile> scoped_profile(profile);
656 584
657 if (!db->GetAutofillTable()->RemoveAutofillProfile(guid)) { 585 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) {
658 NOTREACHED(); 586 NOTREACHED();
659 return WebDatabase::COMMIT_NOT_NEEDED; 587 return WebDatabase::COMMIT_NOT_NEEDED;
660 } 588 }
661 589
662 // Send GUID-based notification. 590 // Send GUID-based notification.
663 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); 591 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL);
664 content::NotificationService::current()->Notify( 592 content::NotificationService::current()->Notify(
665 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, 593 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED,
666 content::Source<WebDataService>(this), 594 content::Source<WebDataService>(this),
667 content::Details<AutofillProfileChange>(&change)); 595 content::Details<AutofillProfileChange>(&change));
668 596
669 return WebDatabase::COMMIT_NEEDED; 597 return WebDatabase::COMMIT_NEEDED;
670 } 598 }
671 599
672 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl( 600 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl(
673 WebDatabase* db) { 601 WebDatabase* db) {
674 std::vector<AutofillProfile*> profiles; 602 std::vector<AutofillProfile*> profiles;
675 db->GetAutofillTable()->GetAutofillProfiles(&profiles); 603 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles);
676 return scoped_ptr<WDTypedResult>( 604 return scoped_ptr<WDTypedResult>(
677 new WDDestroyableResult<std::vector<AutofillProfile*> >( 605 new WDDestroyableResult<std::vector<AutofillProfile*> >(
678 AUTOFILL_PROFILES_RESULT, 606 AUTOFILL_PROFILES_RESULT,
679 profiles, 607 profiles,
680 base::Bind(&WebDataService::DestroyAutofillProfileResult, 608 base::Bind(&WebDataService::DestroyAutofillProfileResult,
681 base::Unretained(this)))); 609 base::Unretained(this))));
682 } 610 }
683 611
684 WebDatabase::State WebDataService::AddCreditCardImpl( 612 WebDatabase::State WebDataService::AddCreditCardImpl(
685 const CreditCard& credit_card, WebDatabase* db) { 613 const CreditCard& credit_card, WebDatabase* db) {
686 if (!db->GetAutofillTable()->AddCreditCard(credit_card)) { 614 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) {
687 NOTREACHED(); 615 NOTREACHED();
688 return WebDatabase::COMMIT_NOT_NEEDED; 616 return WebDatabase::COMMIT_NOT_NEEDED;
689 } 617 }
690 618
691 return WebDatabase::COMMIT_NEEDED; 619 return WebDatabase::COMMIT_NEEDED;
692 } 620 }
693 621
694 WebDatabase::State WebDataService::UpdateCreditCardImpl( 622 WebDatabase::State WebDataService::UpdateCreditCardImpl(
695 const CreditCard& credit_card, WebDatabase* db) { 623 const CreditCard& credit_card, WebDatabase* db) {
696 // It is currently valid to try to update a missing profile. We simply drop 624 // It is currently valid to try to update a missing profile. We simply drop
697 // the write and the caller will detect this on the next refresh. 625 // the write and the caller will detect this on the next refresh.
698 CreditCard* original_credit_card = NULL; 626 CreditCard* original_credit_card = NULL;
699 if (!db->GetAutofillTable()->GetCreditCard(credit_card.guid(), 627 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(),
700 &original_credit_card)) { 628 &original_credit_card)) {
701 return WebDatabase::COMMIT_NOT_NEEDED; 629 return WebDatabase::COMMIT_NOT_NEEDED;
702 } 630 }
703 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); 631 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card);
704 632
705 if (!db->GetAutofillTable()->UpdateCreditCard(credit_card)) { 633 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) {
706 NOTREACHED(); 634 NOTREACHED();
707 return WebDatabase::COMMIT_NOT_NEEDED; 635 return WebDatabase::COMMIT_NOT_NEEDED;
708 } 636 }
709 return WebDatabase::COMMIT_NEEDED; 637 return WebDatabase::COMMIT_NEEDED;
710 } 638 }
711 639
712 WebDatabase::State WebDataService::RemoveCreditCardImpl( 640 WebDatabase::State WebDataService::RemoveCreditCardImpl(
713 const std::string& guid, WebDatabase* db) { 641 const std::string& guid, WebDatabase* db) {
714 if (!db->GetAutofillTable()->RemoveCreditCard(guid)) { 642 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) {
715 NOTREACHED(); 643 NOTREACHED();
716 return WebDatabase::COMMIT_NOT_NEEDED; 644 return WebDatabase::COMMIT_NOT_NEEDED;
717 } 645 }
718 return WebDatabase::COMMIT_NEEDED; 646 return WebDatabase::COMMIT_NEEDED;
719 } 647 }
720 648
721 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl(WebDatabase* db) { 649 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl(WebDatabase* db) {
722 std::vector<CreditCard*> credit_cards; 650 std::vector<CreditCard*> credit_cards;
723 db->GetAutofillTable()->GetCreditCards(&credit_cards); 651 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards);
724 return scoped_ptr<WDTypedResult>( 652 return scoped_ptr<WDTypedResult>(
725 new WDDestroyableResult<std::vector<CreditCard*> >( 653 new WDDestroyableResult<std::vector<CreditCard*> >(
726 AUTOFILL_CREDITCARDS_RESULT, 654 AUTOFILL_CREDITCARDS_RESULT,
727 credit_cards, 655 credit_cards,
728 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, 656 base::Bind(&WebDataService::DestroyAutofillCreditCardResult,
729 base::Unretained(this)))); 657 base::Unretained(this))));
730 } 658 }
731 659
732 WebDatabase::State 660 WebDatabase::State
733 WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( 661 WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl(
734 const base::Time& delete_begin, const base::Time& delete_end, 662 const base::Time& delete_begin, const base::Time& delete_end,
735 WebDatabase* db) { 663 WebDatabase* db) {
736 std::vector<std::string> profile_guids; 664 std::vector<std::string> profile_guids;
737 std::vector<std::string> credit_card_guids; 665 std::vector<std::string> credit_card_guids;
738 if (db->GetAutofillTable()-> 666 if (AutofillTable::FromWebDatabase(db)->
739 RemoveAutofillProfilesAndCreditCardsModifiedBetween( 667 RemoveAutofillProfilesAndCreditCardsModifiedBetween(
740 delete_begin, 668 delete_begin,
741 delete_end, 669 delete_end,
742 &profile_guids, 670 &profile_guids,
743 &credit_card_guids)) { 671 &credit_card_guids)) {
744 for (std::vector<std::string>::iterator iter = profile_guids.begin(); 672 for (std::vector<std::string>::iterator iter = profile_guids.begin();
745 iter != profile_guids.end(); ++iter) { 673 iter != profile_guids.end(); ++iter) {
746 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, 674 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter,
747 NULL); 675 NULL);
748 content::NotificationService::current()->Notify( 676 content::NotificationService::current()->Notify(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 711
784 void WebDataService::DestroyAutofillCreditCardResult( 712 void WebDataService::DestroyAutofillCreditCardResult(
785 const WDTypedResult* result) { 713 const WDTypedResult* result) {
786 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); 714 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT);
787 const WDResult<std::vector<CreditCard*> >* r = 715 const WDResult<std::vector<CreditCard*> >* r =
788 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); 716 static_cast<const WDResult<std::vector<CreditCard*> >*>(result);
789 717
790 std::vector<CreditCard*> credit_cards = r->GetValue(); 718 std::vector<CreditCard*> credit_cards = r->GetValue();
791 STLDeleteElements(&credit_cards); 719 STLDeleteElements(&credit_cards);
792 } 720 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service.h ('k') | chrome/browser/webdata/web_data_service_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698