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

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

Issue 12695015: Split Autofill webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Win build Created 7 years, 9 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_factory.h" 5 #include "chrome/browser/webdata/web_data_service_factory.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "chrome/browser/profiles/profile_dependency_manager.h" 9 #include "chrome/browser/profiles/profile_dependency_manager.h"
10 #include "chrome/browser/ui/profile_error_dialog.h" 10 #include "chrome/browser/ui/profile_error_dialog.h"
11 #include "chrome/browser/webdata/autocomplete_syncable_service.h" 11 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
12 #include "chrome/browser/webdata/autofill_profile_syncable_service.h" 12 #include "chrome/browser/webdata/autofill_profile_syncable_service.h"
13 #include "chrome/browser/webdata/autofill_table.h" 13 #include "chrome/browser/webdata/autofill_table.h"
14 #include "chrome/browser/webdata/autofill_web_data_service_impl.h" 14 #include "chrome/browser/webdata/autofill_web_data_service_impl.h"
15 #include "chrome/browser/webdata/keyword_table.h" 15 #include "chrome/browser/webdata/keyword_table.h"
16 #include "chrome/browser/webdata/logins_table.h" 16 #include "chrome/browser/webdata/logins_table.h"
17 #include "chrome/browser/webdata/token_service_table.h" 17 #include "chrome/browser/webdata/token_service_table.h"
18 #include "chrome/browser/webdata/web_apps_table.h" 18 #include "chrome/browser/webdata/web_apps_table.h"
19 #include "chrome/browser/webdata/web_data_service.h"
19 #include "chrome/browser/webdata/web_intents_table.h" 20 #include "chrome/browser/webdata/web_intents_table.h"
20 #include "chrome/browser/webdata/webdata_constants.h" 21 #include "chrome/browser/webdata/webdata_constants.h"
21 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
22 #include "grit/chromium_strings.h" 23 #include "grit/chromium_strings.h"
23 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
24 25
25 using content::BrowserThread; 26 using content::BrowserThread;
26 27
27 namespace { 28 namespace {
28 29
29 // Callback to show error dialog on profile load error. 30 // Callback to show error dialog on profile load error.
30 void ProfileErrorCallback(sql::InitStatus status) { 31 void ProfileErrorCallback(sql::InitStatus status) {
31 ShowProfileErrorDialog( 32 ShowProfileErrorDialog(
32 (status == sql::INIT_FAILURE) ? 33 (status == sql::INIT_FAILURE) ?
33 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); 34 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
34 } 35 }
35 36
36 void InitSyncableServicesOnDBThread(scoped_refptr<WebDataService> web_data) { 37 void InitSyncableServicesOnDBThread(
38 scoped_refptr<AutofillWebDataService> autofill_web_data) {
37 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 39 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
38 40
39 // Currently only Autocomplete and Autofill profiles use the new Sync API, but 41 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
40 // all the database data should migrate to this API over time. 42 // all the database data should migrate to this API over time.
41 AutocompleteSyncableService::CreateForWebDataService(web_data); 43 AutocompleteSyncableService::CreateForWebDataService(autofill_web_data);
42 AutofillProfileSyncableService::CreateForWebDataService(web_data); 44 AutofillProfileSyncableService::CreateForWebDataService(autofill_web_data);
43 } 45 }
44 46
45 } // namespace 47 } // namespace
46 48
47 WebDataServiceWrapper::WebDataServiceWrapper() {} 49 WebDataServiceWrapper::WebDataServiceWrapper() {}
48 50
49 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) { 51 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
50 base::FilePath path = profile->GetPath(); 52 base::FilePath path = profile->GetPath();
51 path = path.Append(kWebDataFilename); 53 path = path.Append(kWebDataFilename);
52 web_data_service_ =
53 new WebDataService(path, base::Bind(&ProfileErrorCallback));
54 54
55 // All table objects that participate in managing the database must be added 55 web_database_ = new WebDatabaseService(path);
56 // here. 56
57 web_data_service_->AddTable( 57 // All tables objects that participate in managing the database must
58 // be added here.
59 web_database_->AddTable(
58 scoped_ptr<WebDatabaseTable>(new AutofillTable())); 60 scoped_ptr<WebDatabaseTable>(new AutofillTable()));
59 web_data_service_->AddTable( 61 web_database_->AddTable(
60 scoped_ptr<WebDatabaseTable>(new KeywordTable())); 62 scoped_ptr<WebDatabaseTable>(new KeywordTable()));
61 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password 63 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
62 // access, but for now, we still create it on all platforms since it deletes 64 // access, but for now, we still create it on all platforms since it deletes
63 // the old logins table. We can remove this after a while, e.g. in M22 or so. 65 // the old logins table. We can remove this after a while, e.g. in M22 or so.
64 web_data_service_->AddTable( 66 web_database_->AddTable(
65 scoped_ptr<WebDatabaseTable>(new LoginsTable())); 67 scoped_ptr<WebDatabaseTable>(new LoginsTable()));
66 web_data_service_->AddTable( 68 web_database_->AddTable(
67 scoped_ptr<WebDatabaseTable>(new TokenServiceTable())); 69 scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
68 web_data_service_->AddTable( 70 web_database_->AddTable(
69 scoped_ptr<WebDatabaseTable>(new WebAppsTable())); 71 scoped_ptr<WebDatabaseTable>(new WebAppsTable()));
70 // TODO(thakis): Add a migration to delete the SQL table used by 72 // TODO(thakis): Add a migration to delete the SQL table used by
71 // WebIntentsTable, then remove this. 73 // WebIntentsTable, then remove this.
72 web_data_service_->AddTable( 74 web_database_->AddTable(
73 scoped_ptr<WebDatabaseTable>(new WebIntentsTable())); 75 scoped_ptr<WebDatabaseTable>(new WebIntentsTable()));
74 76
75 web_data_service_->Init(); 77 // TODO (caitkp): Rework the callbacks here. They're ugly.
78
79 web_database_->LoadDatabase(WebDatabaseService::InitCallback());
80
81 autofill_web_data_ = new AutofillWebDataServiceImpl(
82 web_database_, base::Bind(&ProfileErrorCallback));
83 autofill_web_data_->Init();
84
85 web_data_ = new WebDataService(
86 web_database_, base::Bind(&ProfileErrorCallback));
87 web_data_->Init();
76 88
77 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE, 89 BrowserThread::PostTask(BrowserThread::DB, FROM_HERE,
78 base::Bind(&InitSyncableServicesOnDBThread, 90 base::Bind(&InitSyncableServicesOnDBThread,
79 web_data_service_)); 91 autofill_web_data_));
80 } 92 }
81 93
82 WebDataServiceWrapper::~WebDataServiceWrapper() { 94 WebDataServiceWrapper::~WebDataServiceWrapper() {
83 } 95 }
84 96
85 void WebDataServiceWrapper::Shutdown() { 97 void WebDataServiceWrapper::Shutdown() {
86 web_data_service_->ShutdownOnUIThread(); 98 autofill_web_data_->ShutdownOnUIThread();
87 web_data_service_ = NULL; 99 web_data_->ShutdownOnUIThread();
100 web_database_->ShutdownDatabase();
101 }
102
103 scoped_refptr<AutofillWebDataService>
104 WebDataServiceWrapper::GetAutofillWebData() {
105 return autofill_web_data_.get();
88 } 106 }
89 107
90 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() { 108 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
91 return web_data_service_.get(); 109 return web_data_.get();
92 } 110 }
93 111
94 // static 112 // static
95 scoped_refptr<AutofillWebDataService> 113 scoped_refptr<AutofillWebDataService>
96 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) { 114 AutofillWebDataService::FromBrowserContext(content::BrowserContext* context) {
97 // For this service, the implicit/explicit distinction doesn't 115 // For this service, the implicit/explicit distinction doesn't
98 // really matter; it's just used for a DCHECK. So we currently 116 // really matter; it's just used for a DCHECK. So we currently
99 // cheat and always say EXPLICIT_ACCESS. 117 // cheat and always say EXPLICIT_ACCESS.
100 scoped_refptr<WebDataService> service = WebDataServiceFactory::GetForProfile( 118 WebDataServiceWrapper* wrapper =
101 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); 119 WebDataServiceFactory::GetForProfile(
102 120 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
103 if (service.get()) { 121 if (wrapper)
104 return scoped_refptr<AutofillWebDataService>( 122 return wrapper->GetAutofillWebData();
105 new AutofillWebDataServiceImpl(service)); 123 // |wrapper| can be NULL in Incognito mode.
106 } else { 124 return scoped_refptr<AutofillWebDataService>(NULL);
107 return scoped_refptr<AutofillWebDataService>(NULL);
108 }
109 } 125 }
110 126
111 // static 127 // static
112 scoped_refptr<WebDataService> WebDataService::FromBrowserContext( 128 scoped_refptr<WebDataService> WebDataService::FromBrowserContext(
113 content::BrowserContext* context) { 129 content::BrowserContext* context) {
114 // For this service, the implicit/explicit distinction doesn't 130 // For this service, the implicit/explicit distinction doesn't
115 // really matter; it's just used for a DCHECK. So we currently 131 // really matter; it's just used for a DCHECK. So we currently
116 // cheat and always say EXPLICIT_ACCESS. 132 // cheat and always say EXPLICIT_ACCESS.
117 return WebDataServiceFactory::GetForProfile( 133 WebDataServiceWrapper* wrapper =
118 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS); 134 WebDataServiceFactory::GetForProfile(
135 static_cast<Profile*>(context), Profile::EXPLICIT_ACCESS);
136 if (wrapper)
137 return wrapper->GetWebData();
138 // |wrapper| can be NULL in Incognito mode.
139 return scoped_refptr<WebDataService>(NULL);
119 } 140 }
120 141
121 WebDataServiceFactory::WebDataServiceFactory() 142 WebDataServiceFactory::WebDataServiceFactory()
122 : ProfileKeyedServiceFactory( 143 : ProfileKeyedServiceFactory(
123 "WebDataService", 144 "WebDataService",
124 ProfileDependencyManager::GetInstance()) { 145 ProfileDependencyManager::GetInstance()) {
125 // WebDataServiceFactory has no dependecies. 146 // WebDataServiceFactory has no dependecies.
126 } 147 }
127 148
128 WebDataServiceFactory::~WebDataServiceFactory() {} 149 WebDataServiceFactory::~WebDataServiceFactory() {}
129 150
130 // static 151 // static
131 scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfile( 152 WebDataServiceWrapper* WebDataServiceFactory::GetForProfile(
132 Profile* profile, Profile::ServiceAccessType access_type) { 153 Profile* profile, Profile::ServiceAccessType access_type) {
133 // If |access_type| starts being used for anything other than this 154 // If |access_type| starts being used for anything other than this
134 // DCHECK, we need to start taking it as a parameter to 155 // DCHECK, we need to start taking it as a parameter to
135 // AutofillWebDataServiceImpl::FromBrowserContext (see above). 156 // AutofillWebDataServiceImpl::FromBrowserContext (see above).
136 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); 157 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
137 WebDataServiceWrapper* wrapper = 158 return static_cast<WebDataServiceWrapper*>(
138 static_cast<WebDataServiceWrapper*>(
139 GetInstance()->GetServiceForProfile(profile, true)); 159 GetInstance()->GetServiceForProfile(profile, true));
140 if (wrapper)
141 return wrapper->GetWebData();
142 // |wrapper| can be NULL in Incognito mode.
143 return NULL;
144 } 160 }
145 161
146 // static 162 // static
147 scoped_refptr<WebDataService> WebDataServiceFactory::GetForProfileIfExists( 163 WebDataServiceWrapper* WebDataServiceFactory::GetForProfileIfExists(
148 Profile* profile, Profile::ServiceAccessType access_type) { 164 Profile* profile, Profile::ServiceAccessType access_type) {
149 // If |access_type| starts being used for anything other than this 165 // If |access_type| starts being used for anything other than this
150 // DCHECK, we need to start taking it as a parameter to 166 // DCHECK, we need to start taking it as a parameter to
151 // AutofillWebDataServiceImpl::FromBrowserContext (see above). 167 // AutofillWebDataServiceImpl::FromBrowserContext (see above).
152 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); 168 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
153 WebDataServiceWrapper* wrapper = 169 return static_cast<WebDataServiceWrapper*>(
154 static_cast<WebDataServiceWrapper*>( 170 GetInstance()->GetServiceForProfile(profile, false));
155 GetInstance()->GetServiceForProfile(profile, true));
156 if (wrapper)
157 return wrapper->GetWebData();
158 // |wrapper| can be NULL in Incognito mode.
159 return NULL;
160 } 171 }
161 172
162 // static 173 // static
163 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { 174 WebDataServiceFactory* WebDataServiceFactory::GetInstance() {
164 return Singleton<WebDataServiceFactory>::get(); 175 return Singleton<WebDataServiceFactory>::get();
165 } 176 }
166 177
167 bool WebDataServiceFactory::ServiceRedirectedInIncognito() const { 178 bool WebDataServiceFactory::ServiceRedirectedInIncognito() const {
168 return true; 179 return true;
169 } 180 }
170 181
171 ProfileKeyedService* 182 ProfileKeyedService*
172 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const { 183 WebDataServiceFactory::BuildServiceInstanceFor(Profile* profile) const {
173 return new WebDataServiceWrapper(profile); 184 return new WebDataServiceWrapper(profile);
174 } 185 }
175 186
176 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { 187 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
177 return true; 188 return true;
178 } 189 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service_factory.h ('k') | chrome/browser/webdata/web_data_service_test_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698