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 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 path_ = path; | 415 path_ = path; |
416 is_running_ = true; | 416 is_running_ = true; |
417 | 417 |
418 ScheduleTask(FROM_HERE, | 418 ScheduleTask(FROM_HERE, |
419 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); | 419 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); |
420 ScheduleTask(FROM_HERE, | 420 ScheduleTask(FROM_HERE, |
421 Bind(&WebDataService::InitializeSyncableServices, this)); | 421 Bind(&WebDataService::InitializeSyncableServices, this)); |
422 return true; | 422 return true; |
423 } | 423 } |
424 | 424 |
425 void WebDataService::RequestCompleted(Handle h) { | |
426 request_manager_.RequestCompleted(h); | |
427 } | |
428 | |
429 //////////////////////////////////////////////////////////////////////////////// | 425 //////////////////////////////////////////////////////////////////////////////// |
430 // | 426 // |
431 // The following methods are executed in Chrome_WebDataThread. | 427 // The following methods are executed in Chrome_WebDataThread. |
432 // | 428 // |
433 //////////////////////////////////////////////////////////////////////////////// | 429 //////////////////////////////////////////////////////////////////////////////// |
434 | 430 |
435 void WebDataService::DBInitFailed(sql::InitStatus init_status) { | 431 void WebDataService::DBInitFailed(sql::InitStatus init_status) { |
436 ShowProfileErrorDialog( | 432 ShowProfileErrorDialog( |
437 (init_status == sql::INIT_FAILURE) ? | 433 (init_status == sql::INIT_FAILURE) ? |
438 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); | 434 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) { | 515 const base::Closure& task) { |
520 if (is_running_) | 516 if (is_running_) |
521 BrowserThread::PostTask(BrowserThread::DB, from_here, task); | 517 BrowserThread::PostTask(BrowserThread::DB, from_here, task); |
522 else | 518 else |
523 NOTREACHED() << "Task scheduled after Shutdown()"; | 519 NOTREACHED() << "Task scheduled after Shutdown()"; |
524 } | 520 } |
525 | 521 |
526 void WebDataService::ScheduleDBTask( | 522 void WebDataService::ScheduleDBTask( |
527 const tracked_objects::Location& from_here, | 523 const tracked_objects::Location& from_here, |
528 const base::Closure& task) { | 524 const base::Closure& task) { |
529 WebDataRequest* request = | 525 scoped_ptr<WebDataRequest> request( |
530 new WebDataRequest(this, NULL, &request_manager_); | 526 new WebDataRequest(this, NULL, &request_manager_)); |
531 if (is_running_) { | 527 if (is_running_) { |
532 BrowserThread::PostTask(BrowserThread::DB, from_here, | 528 BrowserThread::PostTask(BrowserThread::DB, from_here, |
533 base::Bind(&WebDataService::DBTaskWrapper, this, task, request)); | 529 base::Bind(&WebDataService::DBTaskWrapper, this, task, |
| 530 base::Passed(&request))); |
534 } else { | 531 } else { |
535 NOTREACHED() << "Task scheduled after Shutdown()"; | 532 NOTREACHED() << "Task scheduled after Shutdown()"; |
536 } | 533 } |
537 } | 534 } |
538 | 535 |
539 WebDataService::Handle WebDataService::ScheduleDBTaskWithResult( | 536 WebDataService::Handle WebDataService::ScheduleDBTaskWithResult( |
540 const tracked_objects::Location& from_here, | 537 const tracked_objects::Location& from_here, |
541 const ResultTask& task, | 538 const ResultTask& task, |
542 WebDataServiceConsumer* consumer) { | 539 WebDataServiceConsumer* consumer) { |
543 DCHECK(consumer); | 540 DCHECK(consumer); |
544 WebDataRequest* request = | 541 scoped_ptr<WebDataRequest> request( |
545 new WebDataRequest(this, consumer, &request_manager_); | 542 new WebDataRequest(this, consumer, &request_manager_)); |
| 543 WebDataService::Handle handle = request->GetHandle(); |
546 if (is_running_) { | 544 if (is_running_) { |
547 BrowserThread::PostTask(BrowserThread::DB, from_here, | 545 BrowserThread::PostTask(BrowserThread::DB, from_here, |
548 base::Bind(&WebDataService::DBResultTaskWrapper, this, task, request)); | 546 base::Bind(&WebDataService::DBResultTaskWrapper, this, task, |
| 547 base::Passed(&request))); |
549 } else { | 548 } else { |
550 NOTREACHED() << "Task scheduled after Shutdown()"; | 549 NOTREACHED() << "Task scheduled after Shutdown()"; |
551 } | 550 } |
552 return request->GetHandle(); | 551 return handle; |
553 } | 552 } |
554 | 553 |
555 void WebDataService::DBTaskWrapper(const base::Closure& task, | 554 void WebDataService::DBTaskWrapper(const base::Closure& task, |
556 WebDataRequest* request) { | 555 scoped_ptr<WebDataRequest> request) { |
557 InitializeDatabaseIfNecessary(); | 556 InitializeDatabaseIfNecessary(); |
558 if (db_ && !request->IsCancelled()) { | 557 if (db_ && !request->IsCancelled()) { |
559 task.Run(); | 558 task.Run(); |
560 } | 559 } |
561 request->RequestComplete(); | 560 request_manager_.RequestCompleted(request.Pass()); |
562 } | 561 } |
563 | 562 |
564 void WebDataService::DBResultTaskWrapper(const ResultTask& task, | 563 void WebDataService::DBResultTaskWrapper(const ResultTask& task, |
565 WebDataRequest* request) { | 564 scoped_ptr<WebDataRequest> request) { |
566 InitializeDatabaseIfNecessary(); | 565 InitializeDatabaseIfNecessary(); |
567 if (db_ && !request->IsCancelled()) { | 566 if (db_ && !request->IsCancelled()) { |
568 request->SetResult(task.Run().Pass()); | 567 request->SetResult(task.Run().Pass()); |
569 } | 568 } |
570 request->RequestComplete(); | 569 request_manager_.RequestCompleted(request.Pass()); |
571 } | 570 } |
572 | 571 |
573 void WebDataService::ScheduleCommit() { | 572 void WebDataService::ScheduleCommit() { |
574 if (should_commit_ == false) { | 573 if (should_commit_ == false) { |
575 should_commit_ = true; | 574 should_commit_ = true; |
576 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); | 575 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); |
577 } | 576 } |
578 } | 577 } |
579 | 578 |
580 //////////////////////////////////////////////////////////////////////////////// | 579 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1103 | 1102 |
1104 void WebDataService::DestroyAutofillCreditCardResult( | 1103 void WebDataService::DestroyAutofillCreditCardResult( |
1105 const WDTypedResult* result) { | 1104 const WDTypedResult* result) { |
1106 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 1105 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
1107 const WDResult<std::vector<CreditCard*> >* r = | 1106 const WDResult<std::vector<CreditCard*> >* r = |
1108 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 1107 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
1109 | 1108 |
1110 std::vector<CreditCard*> credit_cards = r->GetValue(); | 1109 std::vector<CreditCard*> credit_cards = r->GetValue(); |
1111 STLDeleteElements(&credit_cards); | 1110 STLDeleteElements(&credit_cards); |
1112 } | 1111 } |
OLD | NEW |