1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "components/webdata_services/web_data_service_wrapper.h"
8 #include "base/callback.h"
9 #include "base/files/file_path.h"
10 #include "base/message_loop/message_loop_proxy.h"
11 #include "components/autofill/core/browser/webdata/autofill_table.h"
12 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
13 #include "components/password_manager/core/browser/webdata/logins_table.h"
14 #include "components/search_engines/keyword_table.h"
15 #include "components/search_engines/keyword_web_data_service.h"
16 #include "components/signin/core/browser/webdata/token_service_table.h"
17 #include "components/signin/core/browser/webdata/token_web_data.h"
18 #include "components/webdata/common/web_database_service.h"
19 #include "components/webdata/common/webdata_constants.h"
22 #include "components/password_manager/core/browser/webdata/password_web_data_service_win.h"
25 WebDataServiceWrapper::WebDataServiceWrapper() {
28 WebDataServiceWrapper::WebDataServiceWrapper(
29 const base::FilePath
& profile_path
,
30 const std::string
& application_locale
,
31 const scoped_refptr
<base::MessageLoopProxy
>& ui_thread
,
32 const scoped_refptr
<base::MessageLoopProxy
>& db_thread
,
33 ShowErrorCallback show_error_callback
) {
34 base::FilePath path
= profile_path
.Append(kWebDataFilename
);
35 web_database_
= new WebDatabaseService(path
, ui_thread
, db_thread
);
37 // All tables objects that participate in managing the database must
39 web_database_
->AddTable(scoped_ptr
<WebDatabaseTable
>(
40 new autofill::AutofillTable(application_locale
)));
41 web_database_
->AddTable(scoped_ptr
<WebDatabaseTable
>(new KeywordTable()));
42 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
43 // access, but for now, we still create it on all platforms since it deletes
44 // the old logins table. We can remove this after a while, e.g. in M22 or so.
45 web_database_
->AddTable(scoped_ptr
<WebDatabaseTable
>(new LoginsTable()));
46 web_database_
->AddTable(
47 scoped_ptr
<WebDatabaseTable
>(new TokenServiceTable()));
48 web_database_
->LoadDatabase();
50 autofill_web_data_
= new autofill::AutofillWebDataService(
51 web_database_
, ui_thread
, db_thread
,
52 base::Bind(show_error_callback
, ERROR_LOADING_AUTOFILL
));
53 autofill_web_data_
->Init();
55 keyword_web_data_
= new KeywordWebDataService(
56 web_database_
, ui_thread
,
57 base::Bind(show_error_callback
, ERROR_LOADING_KEYWORD
));
58 keyword_web_data_
->Init();
60 token_web_data_
= new TokenWebData(
61 web_database_
, ui_thread
, db_thread
,
62 base::Bind(show_error_callback
, ERROR_LOADING_TOKEN
));
63 token_web_data_
->Init();
66 password_web_data_
= new PasswordWebDataService(
67 web_database_
, ui_thread
,
68 base::Bind(show_error_callback
, ERROR_LOADING_PASSWORD
));
69 password_web_data_
->Init();
73 WebDataServiceWrapper::~WebDataServiceWrapper() {
76 void WebDataServiceWrapper::Shutdown() {
77 autofill_web_data_
->ShutdownOnUIThread();
78 keyword_web_data_
->ShutdownOnUIThread();
79 token_web_data_
->ShutdownOnUIThread();
82 password_web_data_
->ShutdownOnUIThread();
85 web_database_
->ShutdownDatabase();
88 scoped_refptr
<autofill::AutofillWebDataService
>
89 WebDataServiceWrapper::GetAutofillWebData() {
90 return autofill_web_data_
.get();
93 scoped_refptr
<KeywordWebDataService
>
94 WebDataServiceWrapper::GetKeywordWebData() {
95 return keyword_web_data_
.get();
98 scoped_refptr
<TokenWebData
> WebDataServiceWrapper::GetTokenWebData() {
99 return token_web_data_
.get();
103 scoped_refptr
<PasswordWebDataService
>
104 WebDataServiceWrapper::GetPasswordWebData() {
105 return password_web_data_
.get();