OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/stl_util-inl.h" | 8 #include "base/stl_util-inl.h" |
9 #include "base/task.h" | 9 #include "base/task.h" |
10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 WebDataRequest* request = | 427 WebDataRequest* request = |
428 new WebDataRequest(this, GetNextRequestHandle(), consumer); | 428 new WebDataRequest(this, GetNextRequestHandle(), consumer); |
429 RegisterRequest(request); | 429 RegisterRequest(request); |
430 ScheduleTask( | 430 ScheduleTask( |
431 NewRunnableMethod(this, | 431 NewRunnableMethod(this, |
432 &WebDataService::GetAutofillProfilesImpl, | 432 &WebDataService::GetAutofillProfilesImpl, |
433 request)); | 433 request)); |
434 return request->GetHandle(); | 434 return request->GetHandle(); |
435 } | 435 } |
436 | 436 |
| 437 void WebDataService::EmptyMigrationTrash(bool notify_sync) { |
| 438 GenericRequest<bool>* request = |
| 439 new GenericRequest<bool>( |
| 440 this, GetNextRequestHandle(), NULL, notify_sync); |
| 441 RegisterRequest(request); |
| 442 ScheduleTask(NewRunnableMethod(this, |
| 443 &WebDataService::EmptyMigrationTrashImpl, |
| 444 request)); |
| 445 } |
| 446 |
437 void WebDataService::AddCreditCard(const CreditCard& credit_card) { | 447 void WebDataService::AddCreditCard(const CreditCard& credit_card) { |
438 GenericRequest<CreditCard>* request = | 448 GenericRequest<CreditCard>* request = |
439 new GenericRequest<CreditCard>( | 449 new GenericRequest<CreditCard>( |
440 this, GetNextRequestHandle(), NULL, credit_card); | 450 this, GetNextRequestHandle(), NULL, credit_card); |
441 RegisterRequest(request); | 451 RegisterRequest(request); |
442 ScheduleTask(NewRunnableMethod(this, | 452 ScheduleTask(NewRunnableMethod(this, |
443 &WebDataService::AddCreditCardImpl, | 453 &WebDataService::AddCreditCardImpl, |
444 request)); | 454 request)); |
445 } | 455 } |
446 | 456 |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1081 if (db_ && !request->IsCancelled()) { | 1091 if (db_ && !request->IsCancelled()) { |
1082 std::vector<AutofillProfile*> profiles; | 1092 std::vector<AutofillProfile*> profiles; |
1083 db_->GetAutofillProfiles(&profiles); | 1093 db_->GetAutofillProfiles(&profiles); |
1084 request->SetResult( | 1094 request->SetResult( |
1085 new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, | 1095 new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, |
1086 profiles)); | 1096 profiles)); |
1087 } | 1097 } |
1088 request->RequestComplete(); | 1098 request->RequestComplete(); |
1089 } | 1099 } |
1090 | 1100 |
| 1101 void WebDataService::EmptyMigrationTrashImpl( |
| 1102 GenericRequest<bool>* request) { |
| 1103 InitializeDatabaseIfNecessary(); |
| 1104 if (db_ && !request->IsCancelled()) { |
| 1105 bool notify_sync = request->GetArgument(); |
| 1106 if (notify_sync) { |
| 1107 std::vector<std::string> guids; |
| 1108 if (!db_->GetAutofillProfilesInTrash(&guids)) { |
| 1109 NOTREACHED(); |
| 1110 return; |
| 1111 } |
| 1112 |
| 1113 for (std::vector<std::string>::const_iterator iter = guids.begin(); |
| 1114 iter != guids.end(); ++iter) { |
| 1115 // Send GUID-based notification. |
| 1116 AutofillProfileChange change(AutofillProfileChange::REMOVE, |
| 1117 *iter, NULL); |
| 1118 NotificationService::current()->Notify( |
| 1119 NotificationType::AUTOFILL_PROFILE_CHANGED, |
| 1120 Source<WebDataService>(this), |
| 1121 Details<AutofillProfileChange>(&change)); |
| 1122 } |
| 1123 } |
| 1124 |
| 1125 if (!db_->EmptyAutofillProfilesTrash()) { |
| 1126 NOTREACHED(); |
| 1127 return; |
| 1128 } |
| 1129 ScheduleCommit(); |
| 1130 } |
| 1131 request->RequestComplete(); |
| 1132 } |
| 1133 |
1091 void WebDataService::AddCreditCardImpl( | 1134 void WebDataService::AddCreditCardImpl( |
1092 GenericRequest<CreditCard>* request) { | 1135 GenericRequest<CreditCard>* request) { |
1093 InitializeDatabaseIfNecessary(); | 1136 InitializeDatabaseIfNecessary(); |
1094 if (db_ && !request->IsCancelled()) { | 1137 if (db_ && !request->IsCancelled()) { |
1095 const CreditCard& credit_card = request->GetArgument(); | 1138 const CreditCard& credit_card = request->GetArgument(); |
1096 if (!db_->AddCreditCard(credit_card)) { | 1139 if (!db_->AddCreditCard(credit_card)) { |
1097 NOTREACHED(); | 1140 NOTREACHED(); |
1098 return; | 1141 return; |
1099 } | 1142 } |
1100 ScheduleCommit(); | 1143 ScheduleCommit(); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1237 return result_; | 1280 return result_; |
1238 } | 1281 } |
1239 | 1282 |
1240 void WebDataService::WebDataRequest::RequestComplete() { | 1283 void WebDataService::WebDataRequest::RequestComplete() { |
1241 WebDataService* s = service_; | 1284 WebDataService* s = service_; |
1242 Task* t = NewRunnableMethod(s, | 1285 Task* t = NewRunnableMethod(s, |
1243 &WebDataService::RequestCompleted, | 1286 &WebDataService::RequestCompleted, |
1244 handle_); | 1287 handle_); |
1245 message_loop_->PostTask(FROM_HERE, t); | 1288 message_loop_->PostTask(FROM_HERE, t); |
1246 } | 1289 } |
OLD | NEW |