b09e564a7309556a7f36a303765dae7c881f0c03
[platform/framework/web/chromium-efl.git] / tizen_src / ewk / efl_integration / browser / webdata / web_data_service_factory.cc
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.
5
6 #if defined(TIZEN_AUTOFILL_SUPPORT)
7
8 #include "browser/webdata/web_data_service_factory.h"
9
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"
20
21 using autofill::AutofillWebDataService;
22 using content::BrowserThread;
23
24 namespace {
25
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
29   NOTIMPLEMENTED();
30 }
31
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
38 }
39
40 }  // namespace
41
42 WebDataServiceWrapper* WebDataServiceWrapper::GetInstance(){
43   return Singleton<WebDataServiceWrapper>::get();
44 }
45
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"));
50
51   scoped_refptr<base::MessageLoopProxy> ui_thread =
52       BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI);
53   scoped_refptr<base::MessageLoopProxy> db_thread =
54       BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB);
55   web_database_ = new WebDatabaseService(path, ui_thread, db_thread);
56
57   // All tables objects that participate in managing the database must
58   // be added here.
59   web_database_->AddTable(
60       scoped_ptr<WebDatabaseTable>(new autofill::AutofillTable(
61           EWebView::GetPlatformLocale())));
62
63   web_database_->LoadDatabase();
64
65   autofill_web_data_ = new AutofillWebDataService(
66       web_database_, ui_thread, db_thread, base::Bind(
67           &ProfileErrorCallback, 0));
68   autofill_web_data_->Init();
69
70   web_data_ = new WebDataService(
71       web_database_, base::Bind(&ProfileErrorCallback,0));
72   web_data_->Init();
73
74   autofill_web_data_->GetAutofillBackend(
75          base::Bind(&InitSyncableServicesOnDBThread,
76                     autofill_web_data_,
77                     db_path,
78                     EWebView::GetPlatformLocale()));
79 }
80
81 WebDataServiceWrapper::~WebDataServiceWrapper() {
82 }
83
84 scoped_refptr<AutofillWebDataService>
85 WebDataServiceWrapper::GetAutofillWebData() {
86   return autofill_web_data_.get();
87 }
88
89 scoped_refptr<WebDataService> WebDataServiceWrapper::GetWebData() {
90   return web_data_.get();
91 }
92
93
94 // static
95 scoped_refptr<WebDataService> WebDataService::FromBrowserContext(
96     content::BrowserContext* context) {
97   WebDataServiceWrapper* wrapper = WebDataServiceFactory::GetDataService();
98   if (wrapper)
99     return wrapper->GetWebData();
100   // |wrapper| can be NULL in Incognito mode.
101   return scoped_refptr<WebDataService>(NULL);
102 }
103
104 WebDataServiceFactory::WebDataServiceFactory(){
105   // WebDataServiceFactory has no dependecies.
106 }
107
108 WebDataServiceFactory::~WebDataServiceFactory() {}
109
110 // static
111 WebDataServiceWrapper* WebDataServiceFactory::GetDataService() {
112   return WebDataServiceWrapper::GetInstance();
113 }
114
115 // static
116 scoped_refptr<AutofillWebDataService>
117 WebDataServiceFactory::GetAutofillWebDataForProfile() {
118   WebDataServiceWrapper* wrapper =
119       WebDataServiceFactory::GetDataService();
120   // |wrapper| can be NULL in Incognito mode.
121   return wrapper ?
122       wrapper->GetAutofillWebData() :
123       scoped_refptr<AutofillWebDataService>(NULL);
124 }
125
126 // static
127 WebDataServiceFactory* WebDataServiceFactory::GetInstance() {
128   return Singleton<WebDataServiceFactory>::get();
129 }
130
131 #endif // TIZEN_AUTOFILL_SUPPORT