[Android] Make telemetry use am force-stop instead of kill on user builds.
[chromium-blink-merge.git] / components / webdata_services / web_data_service_wrapper.cc
blobc1c5deb12dbe062554692a3de79fa149995056c6
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"
7 #include "base/bind.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/autocomplete_syncable_service.h"
12 #include "components/autofill/core/browser/webdata/autofill_profile_syncable_service.h"
13 #include "components/autofill/core/browser/webdata/autofill_table.h"
14 #include "components/autofill/core/browser/webdata/autofill_wallet_syncable_service.h"
15 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
16 #include "components/password_manager/core/browser/webdata/logins_table.h"
17 #include "components/search_engines/keyword_table.h"
18 #include "components/search_engines/keyword_web_data_service.h"
19 #include "components/signin/core/browser/webdata/token_service_table.h"
20 #include "components/signin/core/browser/webdata/token_web_data.h"
21 #include "components/webdata/common/web_database_service.h"
22 #include "components/webdata/common/webdata_constants.h"
24 #if defined(OS_WIN)
25 #include "components/password_manager/core/browser/webdata/password_web_data_service_win.h"
26 #endif
28 namespace {
30 void InitSyncableServicesOnDBThread(
31 const scoped_refptr<base::MessageLoopProxy>& db_thread,
32 const syncer::SyncableService::StartSyncFlare& sync_flare,
33 const scoped_refptr<autofill::AutofillWebDataService>& autofill_web_data,
34 const base::FilePath& context_path,
35 const std::string& app_locale,
36 autofill::AutofillWebDataBackend* autofill_backend) {
37 DCHECK(db_thread->BelongsToCurrentThread());
39 // Currently only Autocomplete and Autofill profiles use the new Sync API, but
40 // all the database data should migrate to this API over time.
41 autofill::AutocompleteSyncableService::CreateForWebDataServiceAndBackend(
42 autofill_web_data.get(), autofill_backend);
43 autofill::AutocompleteSyncableService::FromWebDataService(
44 autofill_web_data.get())->InjectStartSyncFlare(sync_flare);
46 autofill::AutofillProfileSyncableService::CreateForWebDataServiceAndBackend(
47 autofill_web_data.get(), autofill_backend, app_locale);
48 autofill::AutofillWalletSyncableService::CreateForWebDataServiceAndBackend(
49 autofill_web_data.get(), autofill_backend, app_locale);
51 autofill::AutofillProfileSyncableService::FromWebDataService(
52 autofill_web_data.get())->InjectStartSyncFlare(sync_flare);
53 autofill::AutofillWalletSyncableService::FromWebDataService(
54 autofill_web_data.get())->InjectStartSyncFlare(sync_flare);
57 } // namespace
59 WebDataServiceWrapper::WebDataServiceWrapper() {
62 WebDataServiceWrapper::WebDataServiceWrapper(
63 const base::FilePath& context_path,
64 const std::string& application_locale,
65 const scoped_refptr<base::MessageLoopProxy>& ui_thread,
66 const scoped_refptr<base::MessageLoopProxy>& db_thread,
67 const syncer::SyncableService::StartSyncFlare& flare,
68 ShowErrorCallback show_error_callback) {
69 base::FilePath path = context_path.Append(kWebDataFilename);
70 web_database_ = new WebDatabaseService(path, ui_thread, db_thread);
72 // All tables objects that participate in managing the database must
73 // be added here.
74 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(
75 new autofill::AutofillTable(application_locale)));
76 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new KeywordTable()));
77 // TODO(mdm): We only really need the LoginsTable on Windows for IE7 password
78 // access, but for now, we still create it on all platforms since it deletes
79 // the old logins table. We can remove this after a while, e.g. in M22 or so.
80 web_database_->AddTable(scoped_ptr<WebDatabaseTable>(new LoginsTable()));
81 web_database_->AddTable(
82 scoped_ptr<WebDatabaseTable>(new TokenServiceTable()));
83 web_database_->LoadDatabase();
85 autofill_web_data_ = new autofill::AutofillWebDataService(
86 web_database_, ui_thread, db_thread,
87 base::Bind(show_error_callback, ERROR_LOADING_AUTOFILL));
88 autofill_web_data_->Init();
90 keyword_web_data_ = new KeywordWebDataService(
91 web_database_, ui_thread,
92 base::Bind(show_error_callback, ERROR_LOADING_KEYWORD));
93 keyword_web_data_->Init();
95 token_web_data_ = new TokenWebData(
96 web_database_, ui_thread, db_thread,
97 base::Bind(show_error_callback, ERROR_LOADING_TOKEN));
98 token_web_data_->Init();
100 #if defined(OS_WIN)
101 password_web_data_ = new PasswordWebDataService(
102 web_database_, ui_thread,
103 base::Bind(show_error_callback, ERROR_LOADING_PASSWORD));
104 password_web_data_->Init();
105 #endif
107 autofill_web_data_->GetAutofillBackend(
108 base::Bind(&InitSyncableServicesOnDBThread, db_thread, flare,
109 autofill_web_data_, context_path, application_locale));
112 WebDataServiceWrapper::~WebDataServiceWrapper() {
115 void WebDataServiceWrapper::Shutdown() {
116 autofill_web_data_->ShutdownOnUIThread();
117 keyword_web_data_->ShutdownOnUIThread();
118 token_web_data_->ShutdownOnUIThread();
120 #if defined(OS_WIN)
121 password_web_data_->ShutdownOnUIThread();
122 #endif
124 web_database_->ShutdownDatabase();
127 scoped_refptr<autofill::AutofillWebDataService>
128 WebDataServiceWrapper::GetAutofillWebData() {
129 return autofill_web_data_.get();
132 scoped_refptr<KeywordWebDataService>
133 WebDataServiceWrapper::GetKeywordWebData() {
134 return keyword_web_data_.get();
137 scoped_refptr<TokenWebData> WebDataServiceWrapper::GetTokenWebData() {
138 return token_web_data_.get();
141 #if defined(OS_WIN)
142 scoped_refptr<PasswordWebDataService>
143 WebDataServiceWrapper::GetPasswordWebData() {
144 return password_web_data_.get();
146 #endif