Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: chrome/browser/webdata/web_data_service.cc

Issue 8184001: The AutofillProfileSyncableService's lifetime should be managed by the WebDataService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile after http://crrev.com/104990 Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/webdata/web_data_service.h ('k') | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_profile.h" 11 #include "chrome/browser/autofill/autofill_profile.h"
12 #include "chrome/browser/autofill/credit_card.h" 12 #include "chrome/browser/autofill/credit_card.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/search_engines/template_url.h" 14 #include "chrome/browser/search_engines/template_url.h"
15 #include "chrome/browser/ui/profile_error_dialog.h" 15 #include "chrome/browser/ui/profile_error_dialog.h"
16 #include "chrome/browser/webdata/autofill_change.h" 16 #include "chrome/browser/webdata/autofill_change.h"
17 #include "chrome/browser/webdata/autofill_entry.h" 17 #include "chrome/browser/webdata/autofill_entry.h"
18 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
18 #include "chrome/browser/webdata/autofill_table.h" 19 #include "chrome/browser/webdata/autofill_table.h"
19 #include "chrome/browser/webdata/keyword_table.h" 20 #include "chrome/browser/webdata/keyword_table.h"
20 #include "chrome/browser/webdata/logins_table.h" 21 #include "chrome/browser/webdata/logins_table.h"
21 #include "chrome/browser/webdata/token_service_table.h" 22 #include "chrome/browser/webdata/token_service_table.h"
22 #include "chrome/browser/webdata/web_apps_table.h" 23 #include "chrome/browser/webdata/web_apps_table.h"
23 #include "chrome/browser/webdata/web_intents_table.h" 24 #include "chrome/browser/webdata/web_intents_table.h"
24 #include "chrome/browser/webdata/web_database.h" 25 #include "chrome/browser/webdata/web_database.h"
25 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
26 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
27 #include "content/common/notification_details.h" 28 #include "content/common/notification_details.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 WDKeywordsResult::WDKeywordsResult() 68 WDKeywordsResult::WDKeywordsResult()
68 : default_search_provider_id(0), 69 : default_search_provider_id(0),
69 builtin_keyword_version(0) { 70 builtin_keyword_version(0) {
70 } 71 }
71 72
72 WDKeywordsResult::~WDKeywordsResult() {} 73 WDKeywordsResult::~WDKeywordsResult() {}
73 74
74 WebDataService::WebDataService() 75 WebDataService::WebDataService()
75 : is_running_(false), 76 : is_running_(false),
76 db_(NULL), 77 db_(NULL),
78 autofill_profile_syncable_service_(NULL),
77 failed_init_(false), 79 failed_init_(false),
78 should_commit_(false), 80 should_commit_(false),
79 next_request_handle_(1), 81 next_request_handle_(1),
80 main_loop_(MessageLoop::current()) { 82 main_loop_(MessageLoop::current()) {
81 } 83 }
82 84
83 // static 85 // static
84 void WebDataService::NotifyOfMultipleAutofillChanges( 86 void WebDataService::NotifyOfMultipleAutofillChanges(
85 WebDataService* web_data_service) { 87 WebDataService* web_data_service) {
86 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 88 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
87 89
88 if (!web_data_service) 90 if (!web_data_service)
89 return; 91 return;
90 92
91 BrowserThread::PostTask( 93 BrowserThread::PostTask(
92 BrowserThread::UI, FROM_HERE, 94 BrowserThread::UI, FROM_HERE,
93 Bind(&NotifyOfMultipleAutofillChangesTask, 95 Bind(&NotifyOfMultipleAutofillChangesTask,
94 make_scoped_refptr(web_data_service))); 96 make_scoped_refptr(web_data_service)));
95 } 97 }
96 98
97 bool WebDataService::Init(const FilePath& profile_path) { 99 bool WebDataService::Init(const FilePath& profile_path) {
98 FilePath path = profile_path; 100 FilePath path = profile_path;
99 path = path.Append(chrome::kWebDataFilename); 101 path = path.Append(chrome::kWebDataFilename);
100 return InitWithPath(path); 102 return InitWithPath(path);
101 } 103 }
102 104
103 void WebDataService::Shutdown() { 105 void WebDataService::Shutdown() {
106 ScheduleTask(Bind(&WebDataService::ShutdownSyncableServices, this));
104 UnloadDatabase(); 107 UnloadDatabase();
105 } 108 }
106 109
107 bool WebDataService::IsRunning() const { 110 bool WebDataService::IsRunning() const {
108 return is_running_; 111 return is_running_;
109 } 112 }
110 113
111 void WebDataService::UnloadDatabase() { 114 void WebDataService::UnloadDatabase() {
112 ScheduleTask(Bind(&WebDataService::ShutdownDatabase, this)); 115 ScheduleTask(Bind(&WebDataService::ShutdownDatabase, this));
113 } 116 }
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 WebDataService::~WebDataService() { 534 WebDataService::~WebDataService() {
532 if (is_running_ && db_) { 535 if (is_running_ && db_) {
533 DLOG_ASSERT("WebDataService dtor called without Shutdown"); 536 DLOG_ASSERT("WebDataService dtor called without Shutdown");
534 } 537 }
535 } 538 }
536 539
537 bool WebDataService::InitWithPath(const FilePath& path) { 540 bool WebDataService::InitWithPath(const FilePath& path) {
538 path_ = path; 541 path_ = path;
539 is_running_ = true; 542 is_running_ = true;
540 ScheduleTask(Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); 543 ScheduleTask(Bind(&WebDataService::InitializeDatabaseIfNecessary, this));
544 ScheduleTask(Bind(&WebDataService::InitializeSyncableServices, this));
541 return true; 545 return true;
542 } 546 }
543 547
544 void WebDataService::RequestCompleted(Handle h) { 548 void WebDataService::RequestCompleted(Handle h) {
545 pending_lock_.Acquire(); 549 pending_lock_.Acquire();
546 RequestMap::iterator i = pending_requests_.find(h); 550 RequestMap::iterator i = pending_requests_.find(h);
547 if (i == pending_requests_.end()) { 551 if (i == pending_requests_.end()) {
548 NOTREACHED() << "Request completed called for an unknown request"; 552 NOTREACHED() << "Request completed called for an unknown request";
549 pending_lock_.Release(); 553 pending_lock_.Release();
550 return; 554 return;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 } 625 }
622 626
623 BrowserThread::PostTask( 627 BrowserThread::PostTask(
624 BrowserThread::UI, FROM_HERE, 628 BrowserThread::UI, FROM_HERE,
625 NewRunnableMethod(this, &WebDataService::NotifyDatabaseLoadedOnUIThread)); 629 NewRunnableMethod(this, &WebDataService::NotifyDatabaseLoadedOnUIThread));
626 630
627 db_ = db; 631 db_ = db;
628 db_->BeginTransaction(); 632 db_->BeginTransaction();
629 } 633 }
630 634
635 void WebDataService::InitializeSyncableServices() {
636 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
637 DCHECK(!autofill_profile_syncable_service_);
638
639 autofill_profile_syncable_service_ = new AutofillProfileSyncableService(this);
640 }
641
631 void WebDataService::NotifyDatabaseLoadedOnUIThread() { 642 void WebDataService::NotifyDatabaseLoadedOnUIThread() {
632 // Notify that the database has been initialized. 643 // Notify that the database has been initialized.
633 NotificationService::current()->Notify( 644 NotificationService::current()->Notify(
634 chrome::NOTIFICATION_WEB_DATABASE_LOADED, Source<WebDataService>(this), 645 chrome::NOTIFICATION_WEB_DATABASE_LOADED, Source<WebDataService>(this),
635 NotificationService::NoDetails()); 646 NotificationService::NoDetails());
636 } 647 }
637 648
638 void WebDataService::ShutdownDatabase() { 649 void WebDataService::ShutdownDatabase() {
639 should_commit_ = false; 650 should_commit_ = false;
640 651
641 if (db_) { 652 if (db_) {
642 db_->CommitTransaction(); 653 db_->CommitTransaction();
643 delete db_; 654 delete db_;
644 db_ = NULL; 655 db_ = NULL;
645 } 656 }
646 } 657 }
647 658
659 void WebDataService::ShutdownSyncableServices() {
660 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
661
662 delete autofill_profile_syncable_service_;
663 autofill_profile_syncable_service_ = NULL;
664 }
665
648 void WebDataService::Commit() { 666 void WebDataService::Commit() {
649 if (should_commit_) { 667 if (should_commit_) {
650 should_commit_ = false; 668 should_commit_ = false;
651 669
652 if (db_) { 670 if (db_) {
653 db_->CommitTransaction(); 671 db_->CommitTransaction();
654 db_->BeginTransaction(); 672 db_->BeginTransaction();
655 } 673 }
656 } 674 }
657 } 675 }
(...skipping 695 matching lines...) Expand 10 before | Expand all | Expand 10 after
1353 Details<AutofillCreditCardChange>(&change)); 1371 Details<AutofillCreditCardChange>(&change));
1354 } 1372 }
1355 // Note: It is the caller's responsibility to post notifications for any 1373 // Note: It is the caller's responsibility to post notifications for any
1356 // changes, e.g. by calling the Refresh() method of PersonalDataManager. 1374 // changes, e.g. by calling the Refresh() method of PersonalDataManager.
1357 ScheduleCommit(); 1375 ScheduleCommit();
1358 } 1376 }
1359 } 1377 }
1360 request->RequestComplete(); 1378 request->RequestComplete();
1361 } 1379 }
1362 1380
1381 AutofillProfileSyncableService*
1382 WebDataService::GetAutofillProfileSyncableService() const {
1383 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
1384 DCHECK(autofill_profile_syncable_service_); // Make sure we're initialized.
1385
1386 return autofill_profile_syncable_service_;
1387 }
1388
1363 //////////////////////////////////////////////////////////////////////////////// 1389 ////////////////////////////////////////////////////////////////////////////////
1364 // 1390 //
1365 // WebDataRequest implementation. 1391 // WebDataRequest implementation.
1366 // 1392 //
1367 //////////////////////////////////////////////////////////////////////////////// 1393 ////////////////////////////////////////////////////////////////////////////////
1368 1394
1369 WebDataService::WebDataRequest::WebDataRequest(WebDataService* service, 1395 WebDataService::WebDataRequest::WebDataRequest(WebDataService* service,
1370 Handle handle, 1396 Handle handle,
1371 WebDataServiceConsumer* consumer) 1397 WebDataServiceConsumer* consumer)
1372 : service_(service), 1398 : service_(service),
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 } 1430 }
1405 1431
1406 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { 1432 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const {
1407 return result_; 1433 return result_;
1408 } 1434 }
1409 1435
1410 void WebDataService::WebDataRequest::RequestComplete() { 1436 void WebDataService::WebDataRequest::RequestComplete() {
1411 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, 1437 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted,
1412 service_.get(), handle_)); 1438 service_.get(), handle_));
1413 } 1439 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service.h ('k') | tools/heapcheck/suppressions.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698