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

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

Issue 777863002: Introduce new component webdata_services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Compile as static_library instead of component Created 6 years 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
« no previous file with comments | « chrome/browser/webdata/web_data_service_factory.h ('k') | chrome/chrome_browser.gypi » ('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) 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 "base/memory/singleton.h"
9 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/incognito_helpers.h" 11 #include "chrome/browser/profiles/incognito_helpers.h"
11 #include "chrome/browser/sync/glue/sync_start_util.h" 12 #include "chrome/browser/sync/glue/sync_start_util.h"
12 #include "chrome/browser/ui/profile_error_dialog.h" 13 #include "chrome/browser/ui/profile_error_dialog.h"
13 #include "chrome/browser/webdata/autocomplete_syncable_service.h" 14 #include "chrome/browser/webdata/autocomplete_syncable_service.h"
14 #include "chrome/grit/chromium_strings.h" 15 #include "chrome/grit/chromium_strings.h"
15 #include "chrome/grit/generated_resources.h" 16 #include "chrome/grit/generated_resources.h"
16 #include "components/autofill/core/browser/autofill_country.h"
17 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser vice.h" 17 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_ser vice.h"
18 #include "components/autofill/core/browser/webdata/autofill_table.h"
19 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
20 #include "components/keyed_service/content/browser_context_dependency_manager.h" 18 #include "components/keyed_service/content/browser_context_dependency_manager.h"
21 #include "components/password_manager/core/browser/webdata/logins_table.h"
22 #include "components/search_engines/keyword_table.h"
23 #include "components/search_engines/keyword_web_data_service.h" 19 #include "components/search_engines/keyword_web_data_service.h"
24 #include "components/signin/core/browser/webdata/token_service_table.h"
25 #include "components/signin/core/browser/webdata/token_web_data.h" 20 #include "components/signin/core/browser/webdata/token_web_data.h"
26 #include "components/webdata/common/webdata_constants.h" 21 #include "components/webdata_services/web_data_service_wrapper.h"
27 #include "content/public/browser/browser_thread.h" 22 #include "content/public/browser/browser_thread.h"
28 23
29 #if defined(OS_WIN) 24 #if defined(OS_WIN)
30 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h" 25 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h"
31 #endif 26 #endif
32 27
33 using autofill::AutofillWebDataService;
34 using autofill::AutofillProfileSyncableService; 28 using autofill::AutofillProfileSyncableService;
35 using content::BrowserThread; 29 using content::BrowserThread;
36 30
37 namespace { 31 namespace {
38 32
33 // Converts a WebDataServiceWrapper::ErrorType to ProfileErrorType.
34 ProfileErrorType ProfileErrorFromWebDataServiceWrapperError(
35 WebDataServiceWrapper::ErrorType error_type) {
36 switch (error_type) {
37 case WebDataServiceWrapper::ERROR_LOADING_AUTOFILL:
38 return PROFILE_ERROR_DB_AUTOFILL_WEB_DATA;
39
40 case WebDataServiceWrapper::ERROR_LOADING_KEYWORD:
41 return PROFILE_ERROR_DB_KEYWORD_WEB_DATA;
42
43 case WebDataServiceWrapper::ERROR_LOADING_TOKEN:
44 return PROFILE_ERROR_DB_TOKEN_WEB_DATA;
45
46 case WebDataServiceWrapper::ERROR_LOADING_PASSWORD:
47 return PROFILE_ERROR_DB_WEB_DATA;
48
49 default:
50 NOTREACHED()
51 << "Unknown WebDataServiceWrapper::ErrorType: " << error_type;
52 return PROFILE_ERROR_DB_WEB_DATA;
53 }
54 }
55
39 // Callback to show error dialog on profile load error. 56 // Callback to show error dialog on profile load error.
40 void ProfileErrorCallback(ProfileErrorType type, sql::InitStatus status) { 57 void ProfileErrorCallback(WebDataServiceWrapper::ErrorType error_type,
58 sql::InitStatus status) {
41 ShowProfileErrorDialog( 59 ShowProfileErrorDialog(
42 type, 60 ProfileErrorFromWebDataServiceWrapperError(error_type),
43 (status == sql::INIT_FAILURE) ? 61 (status == sql::INIT_FAILURE) ?
44 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR); 62 IDS_COULDNT_OPEN_PROFILE_ERROR : IDS_PROFILE_TOO_NEW_ERROR);
45 } 63 }
46 64
65 } // namespace
66
47 void InitSyncableServicesOnDBThread( 67 void InitSyncableServicesOnDBThread(
48 scoped_refptr<AutofillWebDataService> autofill_web_data, 68 scoped_refptr<autofill::AutofillWebDataService> autofill_web_data,
49 const base::FilePath& profile_path, 69 const base::FilePath& profile_path,
50 const std::string& app_locale, 70 const std::string& app_locale,
51 autofill::AutofillWebDataBackend* autofill_backend) { 71 autofill::AutofillWebDataBackend* autofill_backend) {
52 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); 72 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB));
53 73
54 // Currently only Autocomplete and Autofill profiles use the new Sync API, but 74 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
55 // all the database data should migrate to this API over time. 75 // all the database data should migrate to this API over time.
56 AutocompleteSyncableService::CreateForWebDataServiceAndBackend( 76 AutocompleteSyncableService::CreateForWebDataServiceAndBackend(
57 autofill_web_data.get(), autofill_backend); 77 autofill_web_data.get(), autofill_backend);
58 AutocompleteSyncableService::FromWebDataService(autofill_web_data.get()) 78 AutocompleteSyncableService::FromWebDataService(autofill_web_data.get())
59 ->InjectStartSyncFlare( 79 ->InjectStartSyncFlare(
60 sync_start_util::GetFlareForSyncableService(profile_path)); 80 sync_start_util::GetFlareForSyncableService(profile_path));
61 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend( 81 AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
62 autofill_web_data.get(), autofill_backend, app_locale); 82 autofill_web_data.get(), autofill_backend, app_locale);
63 AutofillProfileSyncableService::FromWebDataService(autofill_web_data.get()) 83 AutofillProfileSyncableService::FromWebDataService(autofill_web_data.get())
64 ->InjectStartSyncFlare( 84 ->InjectStartSyncFlare(
65 sync_start_util::GetFlareForSyncableService(profile_path)); 85 sync_start_util::GetFlareForSyncableService(profile_path));
66 } 86 }
67 87
68 } // namespace
69
70 WebDataServiceWrapper::WebDataServiceWrapper() {
71 }
72
73 WebDataServiceWrapper::WebDataServiceWrapper(Profile* profile) {
74 base::FilePath profile_path = profile->GetPath();
75 base::FilePath path = profile_path.Append(kWebDataFilename);
76
77 scoped_refptr<base::MessageLoopProxy> ui_thread =
78 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
79 scoped_refptr<base::MessageLoopProxy> db_thread =
80 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB);
81 web_database_ = new WebDatabaseService(path, ui_thread, db_thread);
82
83 // All tables objects that participate in managing the database must
84 // be added here.
85 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(
86 new autofill::AutofillTable(g_browser_process->GetApplicationLocale())));
87 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new KeywordTable()));
88 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
89 // access, but for now, we still create it on all platforms since it deletes
90 // the old logins table. We can remove this after a while, e.g. in M22 or so.
91 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new LoginsTable()));
92 web_database_->AddTable(
93 scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
94
95 web_database_->LoadDatabase();
96
97 autofill_web_data_ = new AutofillWebDataService(
98 web_database_,
99 ui_thread,
100 db_thread,
101 base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_AUTOFILL_WEB_DATA));
102 autofill_web_data_->Init();
103
104 keyword_web_data_ = new KeywordWebDataService(
105 web_database_,
106 ui_thread,
107 base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_KEYWORD_WEB_DATA));
108 keyword_web_data_->Init();
109
110 token_web_data_ = new TokenWebData(
111 web_database_,
112 ui_thread,
113 db_thread,
114 base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_TOKEN_WEB_DATA));
115 token_web_data_->Init();
116
117 #if defined(OS_WIN)
118 password_web_data_ = new PasswordWebDataService(
119 web_database_,
120 ui_thread,
121 base::Bind(&ProfileErrorCallback, PROFILE_ERROR_DB_WEB_DATA));
122 password_web_data_->Init();
123 #endif
124
125 autofill_web_data_->GetAutofillBackend(
126 base::Bind(&InitSyncableServicesOnDBThread,
127 autofill_web_data_,
128 profile_path,
129 g_browser_process->GetApplicationLocale()));
130 }
131
132 WebDataServiceWrapper::~WebDataServiceWrapper() {
133 }
134
135 void WebDataServiceWrapper::Shutdown() {
136 autofill_web_data_->ShutdownOnUIThread();
137 keyword_web_data_->ShutdownOnUIThread();
138 token_web_data_->ShutdownOnUIThread();
139
140 #if defined(OS_WIN)
141 password_web_data_->ShutdownOnUIThread();
142 #endif
143 web_database_->ShutdownDatabase();
144 }
145
146 scoped_refptr<AutofillWebDataService>
147 WebDataServiceWrapper::GetAutofillWebData() {
148 return autofill_web_data_.get();
149 }
150
151 scoped_refptr<KeywordWebDataService>
152 WebDataServiceWrapper::GetKeywordWebData() {
153 return keyword_web_data_.get();
154 }
155
156 scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() {
157 return token_web_data_.get();
158 }
159
160 #if defined(OS_WIN)
161 scoped_refptr<PasswordWebDataService>
162 WebDataServiceWrapper::GetPasswordWebData() {
163 return password_web_data_.get();
164 }
165 #endif
166
167 WebDataServiceFactory::WebDataServiceFactory() 88 WebDataServiceFactory::WebDataServiceFactory()
168 : BrowserContextKeyedServiceFactory( 89 : BrowserContextKeyedServiceFactory(
169 "WebDataService", 90 "WebDataService",
170 BrowserContextDependencyManager::GetInstance()) { 91 BrowserContextDependencyManager::GetInstance()) {
171 // WebDataServiceFactory has no dependecies. 92 // WebDataServiceFactory has no dependecies.
172 } 93 }
173 94
174 WebDataServiceFactory::~WebDataServiceFactory() { 95 WebDataServiceFactory::~WebDataServiceFactory() {
175 } 96 }
176 97
(...skipping 15 matching lines...) Expand all
192 Profile::ServiceAccessType access_type) { 113 Profile::ServiceAccessType access_type) {
193 // If |access_type| starts being used for anything other than this 114 // If |access_type| starts being used for anything other than this
194 // DCHECK, we need to start taking it as a parameter to 115 // DCHECK, we need to start taking it as a parameter to
195 // the *WebDataService::FromBrowserContext() functions (see above). 116 // the *WebDataService::FromBrowserContext() functions (see above).
196 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord()); 117 DCHECK(access_type != Profile::IMPLICIT_ACCESS || !profile->IsOffTheRecord());
197 return static_cast<WebDataServiceWrapper*>( 118 return static_cast<WebDataServiceWrapper*>(
198 GetInstance()->GetServiceForBrowserContext(profile, false)); 119 GetInstance()->GetServiceForBrowserContext(profile, false));
199 } 120 }
200 121
201 // static 122 // static
202 scoped_refptr<AutofillWebDataService> 123 scoped_refptr<autofill::AutofillWebDataService>
203 WebDataServiceFactory::GetAutofillWebDataForProfile( 124 WebDataServiceFactory::GetAutofillWebDataForProfile(
204 Profile* profile, 125 Profile* profile,
205 Profile::ServiceAccessType access_type) { 126 Profile::ServiceAccessType access_type) {
206 WebDataServiceWrapper* wrapper = 127 WebDataServiceWrapper* wrapper =
207 WebDataServiceFactory::GetForProfile(profile, access_type); 128 WebDataServiceFactory::GetForProfile(profile, access_type);
208 // |wrapper| can be NULL in Incognito mode. 129 // |wrapper| can be null in Incognito mode.
209 return wrapper ? 130 return wrapper ?
210 wrapper->GetAutofillWebData() : 131 wrapper->GetAutofillWebData() :
211 scoped_refptr<AutofillWebDataService>(NULL); 132 scoped_refptr<autofill::AutofillWebDataService>(nullptr);
212 } 133 }
213 134
214 // static 135 // static
215 scoped_refptr<KeywordWebDataService> 136 scoped_refptr<KeywordWebDataService>
216 WebDataServiceFactory::GetKeywordWebDataForProfile( 137 WebDataServiceFactory::GetKeywordWebDataForProfile(
217 Profile* profile, 138 Profile* profile,
218 Profile::ServiceAccessType access_type) { 139 Profile::ServiceAccessType access_type) {
219 WebDataServiceWrapper* wrapper = 140 WebDataServiceWrapper* wrapper =
220 WebDataServiceFactory::GetForProfile(profile, access_type); 141 WebDataServiceFactory::GetForProfile(profile, access_type);
221 // |wrapper| can be NULL in Incognito mode. 142 // |wrapper| can be null in Incognito mode.
222 return wrapper ? 143 return wrapper ?
223 wrapper->GetKeywordWebData() : scoped_refptr<KeywordWebDataService>(NULL); 144 wrapper->GetKeywordWebData() :
145 scoped_refptr<KeywordWebDataService>(nullptr);
224 } 146 }
225 147
226 // static 148 // static
227 scoped_refptr<TokenWebData> WebDataServiceFactory::GetTokenWebDataForProfile( 149 scoped_refptr<TokenWebData> WebDataServiceFactory::GetTokenWebDataForProfile(
228 Profile* profile, 150 Profile* profile,
229 Profile::ServiceAccessType access_type) { 151 Profile::ServiceAccessType access_type) {
230 WebDataServiceWrapper* wrapper = 152 WebDataServiceWrapper* wrapper =
231 WebDataServiceFactory::GetForProfile(profile, access_type); 153 WebDataServiceFactory::GetForProfile(profile, access_type);
232 // |wrapper| can be NULL in Incognito mode. 154 // |wrapper| can be null in Incognito mode.
233 return wrapper ? 155 return wrapper ?
234 wrapper->GetTokenWebData() : scoped_refptr<TokenWebData>(NULL); 156 wrapper->GetTokenWebData() : scoped_refptr<TokenWebData>(nullptr);
235 } 157 }
236 158
237 #if defined(OS_WIN) 159 #if defined(OS_WIN)
238 // static 160 // static
239 scoped_refptr<PasswordWebDataService> 161 scoped_refptr<PasswordWebDataService>
240 WebDataServiceFactory::GetPasswordWebDataForProfile( 162 WebDataServiceFactory::GetPasswordWebDataForProfile(
241 Profile* profile, 163 Profile* profile,
242 Profile::ServiceAccessType access_type) { 164 Profile::ServiceAccessType access_type) {
243 WebDataServiceWrapper* wrapper = 165 WebDataServiceWrapper* wrapper =
244 WebDataServiceFactory::GetForProfile(profile, access_type); 166 WebDataServiceFactory::GetForProfile(profile, access_type);
245 // |wrapper| can be NULL in Incognito mode. 167 // |wrapper| can be null in Incognito mode.
246 return wrapper ? 168 return wrapper ?
247 wrapper->GetPasswordWebData() : 169 wrapper->GetPasswordWebData() :
248 scoped_refptr<PasswordWebDataService>(NULL); 170 scoped_refptr<PasswordWebDataService>(nullptr);
249 } 171 }
250 #endif 172 #endif
251 173
252 // static 174 // static
253 WebDataServiceFactory* WebDataServiceFactory::GetInstance() { 175 WebDataServiceFactory* WebDataServiceFactory::GetInstance() {
254 return Singleton<WebDataServiceFactory>::get(); 176 return Singleton<WebDataServiceFactory>::get();
255 } 177 }
256 178
257 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse( 179 content::BrowserContext* WebDataServiceFactory::GetBrowserContextToUse(
258 content::BrowserContext* context) const { 180 content::BrowserContext* context) const {
259 return chrome::GetBrowserContextRedirectedInIncognito(context); 181 return chrome::GetBrowserContextRedirectedInIncognito(context);
260 } 182 }
261 183
262 KeyedService* WebDataServiceFactory::BuildServiceInstanceFor( 184 KeyedService* WebDataServiceFactory::BuildServiceInstanceFor(
263 content::BrowserContext* profile) const { 185 content::BrowserContext* profile) const {
264 return new WebDataServiceWrapper(static_cast<Profile*>(profile)); 186 WebDataServiceWrapper* web_data_service_wrapper = new WebDataServiceWrapper(
187 static_cast<Profile*>(profile)->GetPath(),
188 g_browser_process->GetApplicationLocale(),
189 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
190 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
191 &ProfileErrorCallback);
192 web_data_service_wrapper->GetAutofillWebData()->GetAutofillBackend(
193 base::Bind(&InitSyncableServicesOnDBThread,
194 web_data_service_wrapper->GetAutofillWebData(),
195 static_cast<Profile*>(profile)->GetPath(),
196 g_browser_process->GetApplicationLocale()));
197 return web_data_service_wrapper;
265 } 198 }
266 199
267 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const { 200 bool WebDataServiceFactory::ServiceIsNULLWhileTesting() const {
268 return true; 201 return true;
269 } 202 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_data_service_factory.h ('k') | chrome/chrome_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698