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

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

Issue 10006037: Moved WebDataService to ProfileKeyedService (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed compile Created 8 years, 8 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
OLDNEW
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 10 matching lines...) Expand all
21 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 21 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
22 #include "chrome/browser/webdata/autofill_table.h" 22 #include "chrome/browser/webdata/autofill_table.h"
23 #include "chrome/browser/webdata/keyword_table.h" 23 #include "chrome/browser/webdata/keyword_table.h"
24 #include "chrome/browser/webdata/logins_table.h" 24 #include "chrome/browser/webdata/logins_table.h"
25 #include "chrome/browser/webdata/token_service_table.h" 25 #include "chrome/browser/webdata/token_service_table.h"
26 #include "chrome/browser/webdata/web_apps_table.h" 26 #include "chrome/browser/webdata/web_apps_table.h"
27 #include "chrome/browser/webdata/web_database.h" 27 #include "chrome/browser/webdata/web_database.h"
28 #include "chrome/browser/webdata/web_intents_table.h" 28 #include "chrome/browser/webdata/web_intents_table.h"
29 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
30 #include "chrome/common/chrome_notification_types.h" 30 #include "chrome/common/chrome_notification_types.h"
31 #ifdef DEBUG
32 #include "content/public/browser/browser_thread.h"
33 #endif
31 #include "content/public/browser/notification_details.h" 34 #include "content/public/browser/notification_details.h"
32 #include "content/public/browser/notification_service.h" 35 #include "content/public/browser/notification_service.h"
33 #include "content/public/browser/notification_source.h" 36 #include "content/public/browser/notification_source.h"
34 #include "grit/chromium_strings.h" 37 #include "grit/chromium_strings.h"
35 #include "grit/generated_resources.h" 38 #include "grit/generated_resources.h"
36 #include "third_party/skia/include/core/SkBitmap.h" 39 #include "third_party/skia/include/core/SkBitmap.h"
37 #include "webkit/forms/form_field.h" 40 #include "webkit/forms/form_field.h"
38 #include "webkit/forms/password_form.h" 41 #include "webkit/forms/password_form.h"
39 42
40 //////////////////////////////////////////////////////////////////////////////// 43 ////////////////////////////////////////////////////////////////////////////////
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 WDKeywordsResult::WDKeywordsResult() 76 WDKeywordsResult::WDKeywordsResult()
74 : default_search_provider_id(0), 77 : default_search_provider_id(0),
75 builtin_keyword_version(0), 78 builtin_keyword_version(0),
76 backup_valid(false), 79 backup_valid(false),
77 did_default_search_provider_change(false) { 80 did_default_search_provider_change(false) {
78 } 81 }
79 82
80 WDKeywordsResult::~WDKeywordsResult() {} 83 WDKeywordsResult::~WDKeywordsResult() {}
81 84
82 WebDataService::WebDataService() 85 WebDataService::WebDataService()
83 : is_running_(false), 86 : RefcountedProfileKeyedService(BrowserThread::UI),
84 db_(NULL), 87 is_running_(false),
85 autocomplete_syncable_service_(NULL), 88 db_(NULL),
86 autofill_profile_syncable_service_(NULL), 89 autocomplete_syncable_service_(NULL),
87 failed_init_(false), 90 autofill_profile_syncable_service_(NULL),
88 should_commit_(false), 91 failed_init_(false),
89 next_request_handle_(1), 92 should_commit_(false),
90 main_loop_(MessageLoop::current()) { 93 next_request_handle_(1),
94 main_loop_(MessageLoop::current()) {
95 // WebDataService requires DB thread if instantiated.
96 // Set WebDataServiceFactory::GetInstance()->SetTestingFactory(&profile, NULL)
97 // if you do not want to instantiate WebDataService in your test.
98 DCHECK(BrowserThread::IsWellKnownThread(BrowserThread::DB));
91 } 99 }
92 100
93 // static 101 // static
94 void WebDataService::NotifyOfMultipleAutofillChanges( 102 void WebDataService::NotifyOfMultipleAutofillChanges(
95 WebDataService* web_data_service) { 103 WebDataService* web_data_service) {
96 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 104 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
97 105
98 if (!web_data_service) 106 if (!web_data_service)
99 return; 107 return;
100 108
101 BrowserThread::PostTask( 109 BrowserThread::PostTask(
102 BrowserThread::UI, FROM_HERE, 110 BrowserThread::UI, FROM_HERE,
103 Bind(&NotifyOfMultipleAutofillChangesTask, 111 Bind(&NotifyOfMultipleAutofillChangesTask,
104 make_scoped_refptr(web_data_service))); 112 make_scoped_refptr(web_data_service)));
105 } 113 }
106 114
115 void WebDataService::ShutdownOnUIThread() {
116 ScheduleTask(FROM_HERE,
117 Bind(&WebDataService::ShutdownSyncableServices, this));
118 UnloadDatabase();
119 }
120
107 bool WebDataService::Init(const FilePath& profile_path) { 121 bool WebDataService::Init(const FilePath& profile_path) {
108 FilePath path = profile_path; 122 FilePath path = profile_path;
109 path = path.Append(chrome::kWebDataFilename); 123 path = path.Append(chrome::kWebDataFilename);
110 return InitWithPath(path); 124 return InitWithPath(path);
111 } 125 }
112 126
113 void WebDataService::Shutdown() {
114 ScheduleTask(FROM_HERE,
115 Bind(&WebDataService::ShutdownSyncableServices, this));
116 UnloadDatabase();
117 }
118
119 bool WebDataService::IsRunning() const { 127 bool WebDataService::IsRunning() const {
120 return is_running_; 128 return is_running_;
121 } 129 }
122 130
123 void WebDataService::UnloadDatabase() { 131 void WebDataService::UnloadDatabase() {
124 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this)); 132 ScheduleTask(FROM_HERE, Bind(&WebDataService::ShutdownDatabase, this));
125 } 133 }
126 134
127 void WebDataService::CancelRequest(Handle h) { 135 void WebDataService::CancelRequest(Handle h) {
128 base::AutoLock l(pending_lock_); 136 base::AutoLock l(pending_lock_);
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 delete_end); 641 delete_end);
634 RegisterRequest(request); 642 RegisterRequest(request);
635 ScheduleTask(FROM_HERE, Bind( 643 ScheduleTask(FROM_HERE, Bind(
636 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, 644 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl,
637 this, request)); 645 this, request));
638 } 646 }
639 647
640 WebDataService::~WebDataService() { 648 WebDataService::~WebDataService() {
641 if (is_running_ && db_) { 649 if (is_running_ && db_) {
642 DLOG_ASSERT("WebDataService dtor called without Shutdown"); 650 DLOG_ASSERT("WebDataService dtor called without Shutdown");
651 NOTREACHED();
643 } 652 }
644 } 653 }
645 654
646 bool WebDataService::InitWithPath(const FilePath& path) { 655 bool WebDataService::InitWithPath(const FilePath& path) {
647 path_ = path; 656 path_ = path;
648 is_running_ = true; 657 is_running_ = true;
649 658
650 // TODO(isherman): For now, to avoid a data race on shutdown 659 // TODO(isherman): For now, to avoid a data race on shutdown
651 // [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to 660 // [ http://crbug.com/100745 ], call |AutofillCountry::ApplicationLocale()| to
652 // cache the application locale before we try to access it on the DB thread. 661 // cache the application locale before we try to access it on the DB thread.
653 // This should be safe to remove once [ http://crbug.com/100845 ] is fixed. 662 // This should be safe to remove once [ http://crbug.com/100845 ] is fixed.
654 AutofillCountry::ApplicationLocale(); 663 // Do not do it if the thread is not UI (can happen only in some tests).
664 if (BrowserThread::CurrentlyOn(BrowserThread::UI))
665 AutofillCountry::ApplicationLocale();
655 666
656 ScheduleTask(FROM_HERE, 667 ScheduleTask(FROM_HERE,
657 Bind(&WebDataService::InitializeDatabaseIfNecessary, this)); 668 Bind(&WebDataService::InitializeDatabaseIfNecessary, this));
658 ScheduleTask(FROM_HERE, 669 ScheduleTask(FROM_HERE,
659 Bind(&WebDataService::InitializeSyncableServices, this)); 670 Bind(&WebDataService::InitializeSyncableServices, this));
660 return true; 671 return true;
661 } 672 }
662 673
663 void WebDataService::RequestCompleted(Handle h) { 674 void WebDataService::RequestCompleted(Handle h) {
664 pending_lock_.Acquire(); 675 pending_lock_.Acquire();
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after
1652 } 1663 }
1653 1664
1654 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const { 1665 const WDTypedResult* WebDataService::WebDataRequest::GetResult() const {
1655 return result_; 1666 return result_;
1656 } 1667 }
1657 1668
1658 void WebDataService::WebDataRequest::RequestComplete() { 1669 void WebDataService::WebDataRequest::RequestComplete() {
1659 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted, 1670 message_loop_->PostTask(FROM_HERE, Bind(&WebDataService::RequestCompleted,
1660 service_.get(), handle_)); 1671 service_.get(), handle_));
1661 } 1672 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service.h ('k') | chrome/browser/webdata/web_data_service_factory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698