OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/task.h" | 8 #include "base/task.h" |
9 #include "base/thread.h" | 9 #include "base/thread.h" |
10 #include "chrome/browser/autofill/autofill_profile.h" | 10 #include "chrome/browser/autofill/autofill_profile.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 void WebDataService::UpdateAutoFillProfile(const AutoFillProfile& profile) { | 153 void WebDataService::UpdateAutoFillProfile(const AutoFillProfile& profile) { |
154 GenericRequest<AutoFillProfile>* request = | 154 GenericRequest<AutoFillProfile>* request = |
155 new GenericRequest<AutoFillProfile>( | 155 new GenericRequest<AutoFillProfile>( |
156 this, GetNextRequestHandle(), NULL, profile); | 156 this, GetNextRequestHandle(), NULL, profile); |
157 RegisterRequest(request); | 157 RegisterRequest(request); |
158 ScheduleTask(NewRunnableMethod(this, | 158 ScheduleTask(NewRunnableMethod(this, |
159 &WebDataService::UpdateAutoFillProfileImpl, | 159 &WebDataService::UpdateAutoFillProfileImpl, |
160 request)); | 160 request)); |
161 } | 161 } |
162 | 162 |
163 void WebDataService::RemoveAutoFillProfile(const AutoFillProfile& profile) { | 163 void WebDataService::RemoveAutoFillProfile(int profile_id) { |
164 GenericRequest<AutoFillProfile>* request = | 164 GenericRequest<int>* request = |
165 new GenericRequest<AutoFillProfile>( | 165 new GenericRequest<int>( |
166 this, GetNextRequestHandle(), NULL, profile); | 166 this, GetNextRequestHandle(), NULL, profile_id); |
167 RegisterRequest(request); | 167 RegisterRequest(request); |
168 ScheduleTask(NewRunnableMethod(this, | 168 ScheduleTask(NewRunnableMethod(this, |
169 &WebDataService::RemoveAutoFillProfileImpl, | 169 &WebDataService::RemoveAutoFillProfileImpl, |
170 request)); | 170 request)); |
171 } | 171 } |
172 | 172 |
173 WebDataService::Handle WebDataService::GetAutoFillProfileForLabel( | 173 WebDataService::Handle WebDataService::GetAutoFillProfileForLabel( |
174 const string16& label, WebDataServiceConsumer* consumer) { | 174 const string16& label, WebDataServiceConsumer* consumer) { |
175 WebDataRequest* request = | 175 WebDataRequest* request = |
176 new WebDataRequest(this, GetNextRequestHandle(), consumer); | 176 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
177 RegisterRequest(request); | 177 RegisterRequest(request); |
178 ScheduleTask( | 178 ScheduleTask( |
179 NewRunnableMethod(this, | 179 NewRunnableMethod(this, |
180 &WebDataService::GetAutoFillProfileForLabelImpl, | 180 &WebDataService::GetAutoFillProfileForLabelImpl, |
181 request, | 181 request, |
182 label)); | 182 label)); |
183 return request->GetHandle(); | 183 return request->GetHandle(); |
184 } | 184 } |
185 | 185 |
| 186 WebDataService::Handle WebDataService::GetAutoFillProfiles( |
| 187 WebDataServiceConsumer* consumer) { |
| 188 WebDataRequest* request = |
| 189 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
| 190 RegisterRequest(request); |
| 191 ScheduleTask( |
| 192 NewRunnableMethod(this, |
| 193 &WebDataService::GetAutoFillProfilesImpl, |
| 194 request)); |
| 195 return request->GetHandle(); |
| 196 } |
| 197 |
186 void WebDataService::RequestCompleted(Handle h) { | 198 void WebDataService::RequestCompleted(Handle h) { |
187 pending_lock_.Acquire(); | 199 pending_lock_.Acquire(); |
188 RequestMap::iterator i = pending_requests_.find(h); | 200 RequestMap::iterator i = pending_requests_.find(h); |
189 if (i == pending_requests_.end()) { | 201 if (i == pending_requests_.end()) { |
190 NOTREACHED() << "Request completed called for an unknown request"; | 202 NOTREACHED() << "Request completed called for an unknown request"; |
191 pending_lock_.Release(); | 203 pending_lock_.Release(); |
192 return; | 204 return; |
193 } | 205 } |
194 | 206 |
195 // Take ownership of the request object and remove it from the map. | 207 // Take ownership of the request object and remove it from the map. |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
465 NOTREACHED() << "Cannot initialize the web database"; | 477 NOTREACHED() << "Cannot initialize the web database"; |
466 failed_init_ = true; | 478 failed_init_ = true; |
467 delete db; | 479 delete db; |
468 if (main_loop_) { | 480 if (main_loop_) { |
469 main_loop_->PostTask(FROM_HERE, | 481 main_loop_->PostTask(FROM_HERE, |
470 NewRunnableMethod(this, &WebDataService::DBInitFailed, init_status)); | 482 NewRunnableMethod(this, &WebDataService::DBInitFailed, init_status)); |
471 } | 483 } |
472 return; | 484 return; |
473 } | 485 } |
474 | 486 |
| 487 ChromeThread::PostTask( |
| 488 ChromeThread::UI, FROM_HERE, |
| 489 NewRunnableMethod(this, &WebDataService::NotifyDatabaseLoadedOnUIThread)); |
| 490 |
475 db_ = db; | 491 db_ = db; |
476 db_->BeginTransaction(); | 492 db_->BeginTransaction(); |
477 } | 493 } |
478 | 494 |
| 495 void WebDataService::NotifyDatabaseLoadedOnUIThread() { |
| 496 // Notify that the database has been initialized. |
| 497 NotificationService::current()->Notify(NotificationType::WEB_DATABASE_LOADED, |
| 498 NotificationService::AllSources(), |
| 499 NotificationService::NoDetails()); |
| 500 } |
| 501 |
479 void WebDataService::ShutdownDatabase() { | 502 void WebDataService::ShutdownDatabase() { |
480 should_commit_ = false; | 503 should_commit_ = false; |
481 | 504 |
482 if (db_) { | 505 if (db_) { |
483 db_->CommitTransaction(); | 506 db_->CommitTransaction(); |
484 delete db_; | 507 delete db_; |
485 db_ = NULL; | 508 db_ = NULL; |
486 } | 509 } |
487 } | 510 } |
488 | 511 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
727 if (db_ && !request->IsCancelled()) { | 750 if (db_ && !request->IsCancelled()) { |
728 const AutoFillProfile& profile = request->GetArgument(); | 751 const AutoFillProfile& profile = request->GetArgument(); |
729 if (!db_->UpdateAutoFillProfile(profile)) | 752 if (!db_->UpdateAutoFillProfile(profile)) |
730 NOTREACHED(); | 753 NOTREACHED(); |
731 ScheduleCommit(); | 754 ScheduleCommit(); |
732 } | 755 } |
733 request->RequestComplete(); | 756 request->RequestComplete(); |
734 } | 757 } |
735 | 758 |
736 void WebDataService::RemoveAutoFillProfileImpl( | 759 void WebDataService::RemoveAutoFillProfileImpl( |
737 GenericRequest<AutoFillProfile>* request) { | 760 GenericRequest<int>* request) { |
738 InitializeDatabaseIfNecessary(); | 761 InitializeDatabaseIfNecessary(); |
739 if (db_ && !request->IsCancelled()) { | 762 if (db_ && !request->IsCancelled()) { |
740 const AutoFillProfile& profile = request->GetArgument(); | 763 int profile_id = request->GetArgument(); |
741 if (!db_->RemoveAutoFillProfile(profile)) | 764 if (!db_->RemoveAutoFillProfile(profile_id)) |
742 NOTREACHED(); | 765 NOTREACHED(); |
743 ScheduleCommit(); | 766 ScheduleCommit(); |
744 } | 767 } |
745 request->RequestComplete(); | 768 request->RequestComplete(); |
746 } | 769 } |
747 | 770 |
748 void WebDataService::GetAutoFillProfileForLabelImpl(WebDataRequest* request, | 771 void WebDataService::GetAutoFillProfileForLabelImpl(WebDataRequest* request, |
749 const string16& label) { | 772 const string16& label) { |
750 InitializeDatabaseIfNecessary(); | 773 InitializeDatabaseIfNecessary(); |
751 if (db_ && !request->IsCancelled()) { | 774 if (db_ && !request->IsCancelled()) { |
752 AutoFillProfile* profile; | 775 AutoFillProfile* profile; |
753 db_->GetAutoFillProfileForLabel(label, &profile); | 776 db_->GetAutoFillProfileForLabel(label, &profile); |
754 request->SetResult( | 777 request->SetResult( |
755 new WDResult<AutoFillProfile>(AUTOFILL_PROFILE_RESULT, *profile)); | 778 new WDResult<AutoFillProfile>(AUTOFILL_PROFILE_RESULT, *profile)); |
756 delete profile; | 779 delete profile; |
757 } | 780 } |
758 request->RequestComplete(); | 781 request->RequestComplete(); |
759 } | 782 } |
760 | 783 |
| 784 void WebDataService::GetAutoFillProfilesImpl(WebDataRequest* request) { |
| 785 InitializeDatabaseIfNecessary(); |
| 786 if (db_ && !request->IsCancelled()) { |
| 787 std::vector<AutoFillProfile*> profiles; |
| 788 db_->GetAutoFillProfiles(&profiles); |
| 789 request->SetResult( |
| 790 new WDResult<std::vector<AutoFillProfile*> >(AUTOFILL_PROFILES_RESULT, |
| 791 profiles)); |
| 792 } |
| 793 request->RequestComplete(); |
| 794 } |
| 795 |
761 //////////////////////////////////////////////////////////////////////////////// | 796 //////////////////////////////////////////////////////////////////////////////// |
762 // | 797 // |
763 // Web Apps implementation. | 798 // Web Apps implementation. |
764 // | 799 // |
765 //////////////////////////////////////////////////////////////////////////////// | 800 //////////////////////////////////////////////////////////////////////////////// |
766 | 801 |
767 void WebDataService::SetWebAppImageImpl( | 802 void WebDataService::SetWebAppImageImpl( |
768 GenericRequest2<GURL, SkBitmap>* request) { | 803 GenericRequest2<GURL, SkBitmap>* request) { |
769 InitializeDatabaseIfNecessary(); | 804 InitializeDatabaseIfNecessary(); |
770 if (db_ && !request->IsCancelled()) { | 805 if (db_ && !request->IsCancelled()) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 Task* t = NewRunnableMethod(s, | 892 Task* t = NewRunnableMethod(s, |
858 &WebDataService::RequestCompleted, | 893 &WebDataService::RequestCompleted, |
859 handle_); | 894 handle_); |
860 message_loop_->PostTask(FROM_HERE, t); | 895 message_loop_->PostTask(FROM_HERE, t); |
861 } | 896 } |
862 | 897 |
863 int WebDataService::GetNextRequestHandle() { | 898 int WebDataService::GetNextRequestHandle() { |
864 AutoLock l(pending_lock_); | 899 AutoLock l(pending_lock_); |
865 return ++next_request_handle_; | 900 return ++next_request_handle_; |
866 } | 901 } |
OLD | NEW |