| 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/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" |
| 11 #include "chrome/browser/autofill/autofill_country.h" | 11 #include "chrome/browser/autofill/autofill_country.h" |
| 12 #include "chrome/browser/autofill/autofill_profile.h" | 12 #include "chrome/browser/autofill/autofill_profile.h" |
| 13 #include "chrome/browser/autofill/credit_card.h" | 13 #include "chrome/browser/autofill/credit_card.h" |
| 14 #include "chrome/browser/intents/default_web_intent_service.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
| 16 #include "chrome/browser/ui/profile_error_dialog.h" | 17 #include "chrome/browser/ui/profile_error_dialog.h" |
| 17 #include "chrome/browser/webdata/autocomplete_syncable_service.h" | 18 #include "chrome/browser/webdata/autocomplete_syncable_service.h" |
| 18 #include "chrome/browser/webdata/autofill_change.h" | 19 #include "chrome/browser/webdata/autofill_change.h" |
| 19 #include "chrome/browser/webdata/autofill_entry.h" | 20 #include "chrome/browser/webdata/autofill_entry.h" |
| 20 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" | 21 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" |
| 21 #include "chrome/browser/webdata/autofill_table.h" | 22 #include "chrome/browser/webdata/autofill_table.h" |
| 22 #include "chrome/browser/webdata/keyword_table.h" | 23 #include "chrome/browser/webdata/keyword_table.h" |
| 23 #include "chrome/browser/webdata/logins_table.h" | 24 #include "chrome/browser/webdata/logins_table.h" |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 304 WebDataServiceConsumer* consumer) { | 305 WebDataServiceConsumer* consumer) { |
| 305 DCHECK(consumer); | 306 DCHECK(consumer); |
| 306 GenericRequest<std::string>* request = new GenericRequest<std::string>( | 307 GenericRequest<std::string>* request = new GenericRequest<std::string>( |
| 307 this, GetNextRequestHandle(), consumer, std::string()); | 308 this, GetNextRequestHandle(), consumer, std::string()); |
| 308 RegisterRequest(request); | 309 RegisterRequest(request); |
| 309 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, | 310 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, |
| 310 this, request)); | 311 this, request)); |
| 311 return request->GetHandle(); | 312 return request->GetHandle(); |
| 312 } | 313 } |
| 313 | 314 |
| 315 void WebDataService::AddDefaultWebIntentService( |
| 316 const DefaultWebIntentService& service) { |
| 317 GenericRequest<DefaultWebIntentService>* request = |
| 318 new GenericRequest<DefaultWebIntentService>( |
| 319 this, GetNextRequestHandle(), NULL, service); |
| 320 RegisterRequest(request); |
| 321 ScheduleTask(FROM_HERE, |
| 322 Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, |
| 323 request)); |
| 324 } |
| 325 |
| 326 void WebDataService::RemoveDefaultWebIntentService( |
| 327 const DefaultWebIntentService& service) { |
| 328 GenericRequest<DefaultWebIntentService>* request = |
| 329 new GenericRequest<DefaultWebIntentService>( |
| 330 this, GetNextRequestHandle(), NULL, service); |
| 331 RegisterRequest(request); |
| 332 ScheduleTask(FROM_HERE, |
| 333 Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, |
| 334 request)); |
| 335 } |
| 336 |
| 337 WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( |
| 338 const string16& action, |
| 339 WebDataServiceConsumer* consumer) { |
| 340 DCHECK(consumer); |
| 341 GenericRequest<string16>* request = new GenericRequest<string16>( |
| 342 this, GetNextRequestHandle(), consumer, action); |
| 343 RegisterRequest(request); |
| 344 ScheduleTask(FROM_HERE, |
| 345 Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, |
| 346 this, request)); |
| 347 return request->GetHandle(); |
| 348 } |
| 349 |
| 350 WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( |
| 351 WebDataServiceConsumer* consumer) { |
| 352 DCHECK(consumer); |
| 353 GenericRequest<std::string>* request = new GenericRequest<std::string>( |
| 354 this, GetNextRequestHandle(), consumer, std::string()); |
| 355 RegisterRequest(request); |
| 356 ScheduleTask(FROM_HERE, |
| 357 Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, |
| 358 this, request)); |
| 359 return request->GetHandle(); |
| 360 } |
| 361 |
| 314 //////////////////////////////////////////////////////////////////////////////// | 362 //////////////////////////////////////////////////////////////////////////////// |
| 315 // | 363 // |
| 316 // Token Service | 364 // Token Service |
| 317 // | 365 // |
| 318 //////////////////////////////////////////////////////////////////////////////// | 366 //////////////////////////////////////////////////////////////////////////////// |
| 319 | 367 |
| 320 void WebDataService::SetTokenForService(const std::string& service, | 368 void WebDataService::SetTokenForService(const std::string& service, |
| 321 const std::string& token) { | 369 const std::string& token) { |
| 322 GenericRequest2<std::string, std::string>* request = | 370 GenericRequest2<std::string, std::string>* request = |
| 323 new GenericRequest2<std::string, std::string>( | 371 new GenericRequest2<std::string, std::string>( |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 if (db_ && !request->IsCancelled(NULL)) { | 1005 if (db_ && !request->IsCancelled(NULL)) { |
| 958 std::vector<WebIntentServiceData> result; | 1006 std::vector<WebIntentServiceData> result; |
| 959 db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); | 1007 db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); |
| 960 request->SetResult( | 1008 request->SetResult( |
| 961 new WDResult<std::vector<WebIntentServiceData> >( | 1009 new WDResult<std::vector<WebIntentServiceData> >( |
| 962 WEB_INTENTS_RESULT, result)); | 1010 WEB_INTENTS_RESULT, result)); |
| 963 } | 1011 } |
| 964 request->RequestComplete(); | 1012 request->RequestComplete(); |
| 965 } | 1013 } |
| 966 | 1014 |
| 1015 void WebDataService::AddDefaultWebIntentServiceImpl( |
| 1016 GenericRequest<DefaultWebIntentService>* request) { |
| 1017 InitializeDatabaseIfNecessary(); |
| 1018 if (db_ && !request->IsCancelled(NULL)) { |
| 1019 const DefaultWebIntentService& service = request->arg(); |
| 1020 db_->GetWebIntentsTable()->SetDefaultService(service); |
| 1021 ScheduleCommit(); |
| 1022 } |
| 1023 request->RequestComplete(); |
| 1024 } |
| 1025 |
| 1026 void WebDataService::RemoveDefaultWebIntentServiceImpl( |
| 1027 GenericRequest<DefaultWebIntentService>* request) { |
| 1028 InitializeDatabaseIfNecessary(); |
| 1029 if (db_ && !request->IsCancelled(NULL)) { |
| 1030 const DefaultWebIntentService& service = request->arg(); |
| 1031 db_->GetWebIntentsTable()->RemoveDefaultService(service); |
| 1032 ScheduleCommit(); |
| 1033 } |
| 1034 request->RequestComplete(); |
| 1035 } |
| 1036 |
| 1037 void WebDataService::GetDefaultWebIntentServicesForActionImpl( |
| 1038 GenericRequest<string16>* request) { |
| 1039 InitializeDatabaseIfNecessary(); |
| 1040 if (db_ && !request->IsCancelled(NULL)) { |
| 1041 std::vector<DefaultWebIntentService> result; |
| 1042 db_->GetWebIntentsTable()->GetDefaultServices( |
| 1043 request->arg(), &result); |
| 1044 request->SetResult( |
| 1045 new WDResult<std::vector<DefaultWebIntentService> >( |
| 1046 WEB_INTENTS_DEFAULTS_RESULT, result)); |
| 1047 } |
| 1048 request->RequestComplete(); |
| 1049 } |
| 1050 |
| 1051 void WebDataService::GetAllDefaultWebIntentServicesImpl( |
| 1052 GenericRequest<std::string>* request) { |
| 1053 InitializeDatabaseIfNecessary(); |
| 1054 if (db_ && !request->IsCancelled(NULL)) { |
| 1055 std::vector<DefaultWebIntentService> result; |
| 1056 db_->GetWebIntentsTable()->GetAllDefaultServices(&result); |
| 1057 request->SetResult( |
| 1058 new WDResult<std::vector<DefaultWebIntentService> >( |
| 1059 WEB_INTENTS_DEFAULTS_RESULT, result)); |
| 1060 } |
| 1061 request->RequestComplete(); |
| 1062 } |
| 1063 |
| 967 //////////////////////////////////////////////////////////////////////////////// | 1064 //////////////////////////////////////////////////////////////////////////////// |
| 968 // | 1065 // |
| 969 // Token Service implementation. | 1066 // Token Service implementation. |
| 970 // | 1067 // |
| 971 //////////////////////////////////////////////////////////////////////////////// | 1068 //////////////////////////////////////////////////////////////////////////////// |
| 972 | 1069 |
| 973 // argument std::string is unused | 1070 // argument std::string is unused |
| 974 void WebDataService::RemoveAllTokensImpl( | 1071 void WebDataService::RemoveAllTokensImpl( |
| 975 GenericRequest<std::string>* request) { | 1072 GenericRequest<std::string>* request) { |
| 976 InitializeDatabaseIfNecessary(); | 1073 InitializeDatabaseIfNecessary(); |
| (...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1527 } | 1624 } |
| 1528 | 1625 |
| 1529 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { | 1626 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { |
| 1530 return result_; | 1627 return result_; |
| 1531 } | 1628 } |
| 1532 | 1629 |
| 1533 void WebDataService::WebDataRequest::RequestComplete() { | 1630 void WebDataService::WebDataRequest::RequestComplete() { |
| 1534 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, | 1631 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, |
| 1535 service_.get(), handle_)); | 1632 service_.get(), handle_)); |
| 1536 } | 1633 } |
| OLD | NEW |