| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 WDKeywordsResult::WDKeywordsResult() | 73 WDKeywordsResult::WDKeywordsResult() |
| 74 : default_search_provider_id(0), | 74 : default_search_provider_id(0), |
| 75 builtin_keyword_version(0) { | 75 builtin_keyword_version(0) { |
| 76 } | 76 } |
| 77 | 77 |
| 78 WDKeywordsResult::~WDKeywordsResult() {} | 78 WDKeywordsResult::~WDKeywordsResult() {} |
| 79 | 79 |
| 80 WebDataService::WebDataService() | 80 WebDataService::WebDataService() |
| 81 : is_running_(false), | 81 : is_running_(false), |
| 82 db_(NULL), | 82 db_(NULL), |
| 83 request_manager_(new WebDataRequestManager()), |
| 83 app_locale_(AutofillCountry::ApplicationLocale()), | 84 app_locale_(AutofillCountry::ApplicationLocale()), |
| 84 autocomplete_syncable_service_(NULL), | 85 autocomplete_syncable_service_(NULL), |
| 85 autofill_profile_syncable_service_(NULL), | 86 autofill_profile_syncable_service_(NULL), |
| 86 failed_init_(false), | 87 failed_init_(false), |
| 87 should_commit_(false), | 88 should_commit_(false), |
| 88 main_loop_(MessageLoop::current()) { | 89 main_loop_(MessageLoop::current()) { |
| 89 // WebDataService requires DB thread if instantiated. | 90 // WebDataService requires DB thread if instantiated. |
| 90 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) | 91 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL) |
| 91 // if you do not want to instantiate WebDataService in your test. | 92 // if you do not want to instantiate WebDataService in your test. |
| 92 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); | 93 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB)); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 120 | 121 |
| 121 bool WebDataService::IsRunning() const { | 122 bool WebDataService::IsRunning() const { |
| 122 return is_running_; | 123 return is_running_; |
| 123 } | 124 } |
| 124 | 125 |
| 125 void WebDataService::UnloadDatabase() { | 126 void WebDataService::UnloadDatabase() { |
| 126 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this)); | 127 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this)); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void WebDataService::CancelRequest(Handle h) { | 130 void WebDataService::CancelRequest(Handle h) { |
| 130 request_manager_.CancelRequest(h); | 131 request_manager_->CancelRequest(h); |
| 131 } | 132 } |
| 132 | 133 |
| 133 content::NotificationSource WebDataService::GetNotificationSource() { | 134 content::NotificationSource WebDataService::GetNotificationSource() { |
| 134 return content::Source<WebDataService>(this); | 135 return content::Source<WebDataService>(this); |
| 135 } | 136 } |
| 136 | 137 |
| 137 bool WebDataService::IsDatabaseLoaded() { | 138 bool WebDataService::IsDatabaseLoaded() { |
| 138 return db_ != NULL; | 139 return db_ != NULL; |
| 139 } | 140 } |
| 140 | 141 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 path_ = path; | 416 path_ = path; |
| 416 is_running_ = true; | 417 is_running_ = true; |
| 417 | 418 |
| 418 ScheduleTask(FROM_HERE, | 419 ScheduleTask(FROM_HERE, |
| 419 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); | 420 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); |
| 420 ScheduleTask(FROM_HERE, | 421 ScheduleTask(FROM_HERE, |
| 421 Bind(&WebDataService::InitializeSyncableServices, this)); | 422 Bind(&WebDataService::InitializeSyncableServices, this)); |
| 422 return true; | 423 return true; |
| 423 } | 424 } |
| 424 | 425 |
| 425 void WebDataService::RequestCompleted(Handle h) { | |
| 426 request_manager_.RequestCompleted(h); | |
| 427 } | |
| 428 | |
| 429 //////////////////////////////////////////////////////////////////////////////// | 426 //////////////////////////////////////////////////////////////////////////////// |
| 430 // | 427 // |
| 431 // The following methods are executed in Chrome_WebDataThread. | 428 // The following methods are executed in Chrome_WebDataThread. |
| 432 // | 429 // |
| 433 //////////////////////////////////////////////////////////////////////////////// | 430 //////////////////////////////////////////////////////////////////////////////// |
| 434 | 431 |
| 435 void WebDataService::DBInitFailed(sql::InitStatus init_status) { | 432 void WebDataService::DBInitFailed(sql::InitStatus init_status) { |
| 436 ShowProfileErrorDialog( | 433 ShowProfileErrorDialog( |
| 437 (init_status == sql::INIT_FAILURE) ? | 434 (init_status == sql::INIT_FAILURE) ? |
| 438 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 435 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 const base::Closure& task) { | 516 const base::Closure& task) { |
| 520 if (is_running_) | 517 if (is_running_) |
| 521 BrowserThread::PostTask(BrowserThread::DB, from_here, task); | 518 BrowserThread::PostTask(BrowserThread::DB, from_here, task); |
| 522 else | 519 else |
| 523 NOTREACHED() << "Task scheduled after Shutdown()"; | 520 NOTREACHED() << "Task scheduled after Shutdown()"; |
| 524 } | 521 } |
| 525 | 522 |
| 526 void WebDataService::ScheduleDBTask( | 523 void WebDataService::ScheduleDBTask( |
| 527 const tracked_objects::Location& from_here, | 524 const tracked_objects::Location& from_here, |
| 528 const base::Closure& task) { | 525 const base::Closure& task) { |
| 529 WebDataRequest* request = | 526 scoped_ptr<WebDataRequest> request( |
| 530 new WebDataRequest(this, NULL, &request_manager_); | 527 new WebDataRequest(NULL, request_manager_.get())); |
| 531 if (is_running_) { | 528 if (is_running_) { |
| 532 BrowserThread::PostTask(BrowserThread::DB, from_here, | 529 BrowserThread::PostTask(BrowserThread::DB, from_here, |
| 533 base::Bind(&WebDataService::DBTaskWrapper, this, task, request)); | 530 base::Bind(&WebDataService::DBTaskWrapper, this, task, |
| 531 base::Passed(&request))); |
| 534 } else { | 532 } else { |
| 535 NOTREACHED() << "Task scheduled after Shutdown()"; | 533 NOTREACHED() << "Task scheduled after Shutdown()"; |
| 536 } | 534 } |
| 537 } | 535 } |
| 538 | 536 |
| 539 WebDataService::Handle WebDataService::ScheduleDBTaskWithResult( | 537 WebDataService::Handle WebDataService::ScheduleDBTaskWithResult( |
| 540 const tracked_objects::Location& from_here, | 538 const tracked_objects::Location& from_here, |
| 541 const ResultTask& task, | 539 const ResultTask& task, |
| 542 WebDataServiceConsumer* consumer) { | 540 WebDataServiceConsumer* consumer) { |
| 543 DCHECK(consumer); | 541 DCHECK(consumer); |
| 544 WebDataRequest* request = | 542 scoped_ptr<WebDataRequest> request( |
| 545 new WebDataRequest(this, consumer, &request_manager_); | 543 new WebDataRequest(consumer, request_manager_.get())); |
| 544 WebDataService::Handle handle = request->GetHandle(); |
| 546 if (is_running_) { | 545 if (is_running_) { |
| 547 BrowserThread::PostTask(BrowserThread::DB, from_here, | 546 BrowserThread::PostTask(BrowserThread::DB, from_here, |
| 548 base::Bind(&WebDataService::DBResultTaskWrapper, this, task, request)); | 547 base::Bind(&WebDataService::DBResultTaskWrapper, this, task, |
| 548 base::Passed(&request))); |
| 549 } else { | 549 } else { |
| 550 NOTREACHED() << "Task scheduled after Shutdown()"; | 550 NOTREACHED() << "Task scheduled after Shutdown()"; |
| 551 } | 551 } |
| 552 return request->GetHandle(); | 552 return handle; |
| 553 } | 553 } |
| 554 | 554 |
| 555 void WebDataService::DBTaskWrapper(const base::Closure& task, | 555 void WebDataService::DBTaskWrapper(const base::Closure& task, |
| 556 WebDataRequest* request) { | 556 scoped_ptr<WebDataRequest> request) { |
| 557 InitializeDatabaseIfNecessary(); | 557 InitializeDatabaseIfNecessary(); |
| 558 if (db_ && !request->IsCancelled()) { | 558 if (db_ && !request->IsCancelled()) { |
| 559 task.Run(); | 559 task.Run(); |
| 560 } | 560 } |
| 561 request->RequestComplete(); | 561 request_manager_->RequestCompleted(request.Pass()); |
| 562 } | 562 } |
| 563 | 563 |
| 564 void WebDataService::DBResultTaskWrapper(const ResultTask& task, | 564 void WebDataService::DBResultTaskWrapper(const ResultTask& task, |
| 565 WebDataRequest* request) { | 565 scoped_ptr<WebDataRequest> request) { |
| 566 InitializeDatabaseIfNecessary(); | 566 InitializeDatabaseIfNecessary(); |
| 567 if (db_ && !request->IsCancelled()) { | 567 if (db_ && !request->IsCancelled()) { |
| 568 request->SetResult(task.Run().Pass()); | 568 request->SetResult(task.Run()); |
| 569 } | 569 } |
| 570 request->RequestComplete(); | 570 request_manager_->RequestCompleted(request.Pass()); |
| 571 } | 571 } |
| 572 | 572 |
| 573 void WebDataService::ScheduleCommit() { | 573 void WebDataService::ScheduleCommit() { |
| 574 if (should_commit_ == false) { | 574 if (should_commit_ == false) { |
| 575 should_commit_ = true; | 575 should_commit_ = true; |
| 576 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); | 576 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); |
| 577 } | 577 } |
| 578 } | 578 } |
| 579 | 579 |
| 580 //////////////////////////////////////////////////////////////////////////////// | 580 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 content::NotificationService::current()->Notify( | 915 content::NotificationService::current()->Notify( |
| 916 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 916 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 917 content::Source<WebDataService>(this), | 917 content::Source<WebDataService>(this), |
| 918 content::Details<AutofillProfileChange>(&change)); | 918 content::Details<AutofillProfileChange>(&change)); |
| 919 } | 919 } |
| 920 | 920 |
| 921 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl() { | 921 scoped_ptr<WDTypedResult> WebDataService::GetAutofillProfilesImpl() { |
| 922 std::vector<AutofillProfile*> profiles; | 922 std::vector<AutofillProfile*> profiles; |
| 923 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); | 923 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
| 924 return scoped_ptr<WDTypedResult>( | 924 return scoped_ptr<WDTypedResult>( |
| 925 new WDResult<std::vector<AutofillProfile*> >( | 925 new WDDestroyableResult<std::vector<AutofillProfile*> >( |
| 926 AUTOFILL_PROFILES_RESULT, | 926 AUTOFILL_PROFILES_RESULT, |
| 927 profiles, |
| 927 base::Bind(&WebDataService::DestroyAutofillProfileResult, | 928 base::Bind(&WebDataService::DestroyAutofillProfileResult, |
| 928 base::Unretained(this)), | 929 base::Unretained(this)))); |
| 929 profiles)); | |
| 930 } | 930 } |
| 931 | 931 |
| 932 void WebDataService::EmptyMigrationTrashImpl(bool notify_sync) { | 932 void WebDataService::EmptyMigrationTrashImpl(bool notify_sync) { |
| 933 if (notify_sync) { | 933 if (notify_sync) { |
| 934 std::vector<std::string> guids; | 934 std::vector<std::string> guids; |
| 935 if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { | 935 if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { |
| 936 NOTREACHED(); | 936 NOTREACHED(); |
| 937 return; | 937 return; |
| 938 } | 938 } |
| 939 | 939 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 content::NotificationService::current()->Notify( | 1028 content::NotificationService::current()->Notify( |
| 1029 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | 1029 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 1030 content::Source<WebDataService>(this), | 1030 content::Source<WebDataService>(this), |
| 1031 content::Details<AutofillCreditCardChange>(&change)); | 1031 content::Details<AutofillCreditCardChange>(&change)); |
| 1032 } | 1032 } |
| 1033 | 1033 |
| 1034 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl() { | 1034 scoped_ptr<WDTypedResult> WebDataService::GetCreditCardsImpl() { |
| 1035 std::vector<CreditCard*> credit_cards; | 1035 std::vector<CreditCard*> credit_cards; |
| 1036 db_->GetAutofillTable()->GetCreditCards(&credit_cards); | 1036 db_->GetAutofillTable()->GetCreditCards(&credit_cards); |
| 1037 return scoped_ptr<WDTypedResult>( | 1037 return scoped_ptr<WDTypedResult>( |
| 1038 new WDResult<std::vector<CreditCard*> >( | 1038 new WDDestroyableResult<std::vector<CreditCard*> >( |
| 1039 AUTOFILL_CREDITCARDS_RESULT, | 1039 AUTOFILL_CREDITCARDS_RESULT, |
| 1040 credit_cards, |
| 1040 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, | 1041 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, |
| 1041 base::Unretained(this)), | 1042 base::Unretained(this)))); |
| 1042 credit_cards)); | |
| 1043 } | 1043 } |
| 1044 | 1044 |
| 1045 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 1045 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
| 1046 const base::Time& delete_begin, const base::Time& delete_end) { | 1046 const base::Time& delete_begin, const base::Time& delete_end) { |
| 1047 std::vector<std::string> profile_guids; | 1047 std::vector<std::string> profile_guids; |
| 1048 std::vector<std::string> credit_card_guids; | 1048 std::vector<std::string> credit_card_guids; |
| 1049 if (db_->GetAutofillTable()-> | 1049 if (db_->GetAutofillTable()-> |
| 1050 RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 1050 RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| 1051 delete_begin, | 1051 delete_begin, |
| 1052 delete_end, | 1052 delete_end, |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 | 1103 |
| 1104 void WebDataService::DestroyAutofillCreditCardResult( | 1104 void WebDataService::DestroyAutofillCreditCardResult( |
| 1105 const WDTypedResult* result) { | 1105 const WDTypedResult* result) { |
| 1106 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 1106 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
| 1107 const WDResult<std::vector<CreditCard*> >* r = | 1107 const WDResult<std::vector<CreditCard*> >* r = |
| 1108 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 1108 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
| 1109 | 1109 |
| 1110 std::vector<CreditCard*> credit_cards = r->GetValue(); | 1110 std::vector<CreditCard*> credit_cards = r->GetValue(); |
| 1111 STLDeleteElements(&credit_cards); | 1111 STLDeleteElements(&credit_cards); |
| 1112 } | 1112 } |
| OLD | NEW |