1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Copyright 2014 Samsung Electronics. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
6 #if defined(TIZEN_AUTOFILL_SUPPORT)
8 #include "browser/webdata/web_data_service_factory.h"
10 #include "eweb_view.h"
11 #include "base/bind.h"
12 #include "base/path_service.h"
13 #include "base/files/file_path.h"
14 #include "components/autofill/core/browser/autofill_country.h"
15 #include "components/autofill/core/browser/webdata/autofill_table.h"
16 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
17 #include "components/webdata/common/webdata_constants.h"
18 #include "content/common/paths_efl.h"
19 #include "content/public/browser/browser_thread.h"
21 using autofill::AutofillWebDataService;
22 using content::BrowserThread;
26 // Callback to show error dialog on profile load error.
27 void ProfileErrorCallback(int type, sql::InitStatus status) {
28 //TODO:Need to check what type of error to show
32 void InitSyncableServicesOnDBThread(
33 scoped_refptr<AutofillWebDataService> autofill_web_data,
34 const base::FilePath& profile_path,
35 const std::string& app_locale,
36 autofill::AutofillWebDataBackend* autofill_backend) {
37 //TODO:Need to check if syncable service is needed
42 WebDataServiceWrapper* WebDataServiceWrapper::GetInstance(){
43 return base::Singleton<WebDataServiceWrapper>::get();
46 WebDataServiceWrapper::WebDataServiceWrapper() {
47 base::FilePath db_path;
48 PathService::Get(PathsEfl::WEB_DATABASE_DIR, &db_path);
49 base::FilePath path = db_path.Append(FILE_PATH_LITERAL(".FormData.db"));
52 new WebDatabaseService(
54 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
55 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB));
57 // All tables objects that participate in managing the database must
59 web_database_->AddTable(make_scoped_ptr(new autofill::AutofillTable));
60 web_database_->LoadDatabase();
63 new AutofillWebDataService(
65 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI),
66 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB),
67 base::Bind(&ProfileErrorCallback, 0));
68 autofill_web_data_->Init();
70 web_data_ = new WebDataService(
71 web_database_, base::Bind(&ProfileErrorCallback,0));
74 autofill_web_data_->GetAutofillBackend(
75 base::Bind(&InitSyncableServicesOnDBThread,
78 EWebView::GetPlatformLocale()));
81 WebDataServiceWrapper::~WebDataServiceWrapper() {
84 scoped_refptr<AutofillWebDataService>
85 WebDataServiceWrapper::GetAutofillWebData() {
86 return autofill_web_data_.get();
89 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
90 return web_data_.get();
95 scoped_refptr<WebDataService> WebDataService::FromBrowserContext(
96 content::BrowserContext* context) {
97 WebDataServiceWrapper* wrapper = WebDataServiceFactory::GetDataService();
99 return wrapper->GetWebData();
100 // |wrapper| can be NULL in Incognito mode.
101 return scoped_refptr<WebDataService>(NULL);
104 WebDataServiceFactory::WebDataServiceFactory(){
105 // WebDataServiceFactory has no dependecies.
108 WebDataServiceFactory::~WebDataServiceFactory() {}
111 WebDataServiceWrapper* WebDataServiceFactory::GetDataService() {
112 return WebDataServiceWrapper::GetInstance();
116 scoped_refptr<AutofillWebDataService>
117 WebDataServiceFactory::GetAutofillWebDataForProfile() {
118 WebDataServiceWrapper* wrapper =
119 WebDataServiceFactory::GetDataService();
120 // |wrapper| can be NULL in Incognito mode.
122 wrapper->GetAutofillWebData() :
123 scoped_refptr<AutofillWebDataService>(NULL);
127 WebDataServiceFactory* WebDataServiceFactory::GetInstance() {
128 return base::Singleton<WebDataServiceFactory>::get();
131 #endif // TIZEN_AUTOFILL_SUPPORT