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/password_manager/password_store_factory.h"
10 #include "base/command_line.h"
11 #include "base/environment.h"
12 #include "base/prefs/pref_service.h"
13 #include "base/path_service.h"
14 #include "base/files/file_path.h"
15 #include "browser/webdata/web_data_service.h"
16 #include "browser/webdata/web_data_service_factory.h"
17 #include "components/password_manager/core/browser/login_database.h"
18 #include "components/password_manager/core/browser/password_store.h"
19 #include "components/password_manager/core/browser/password_store_default.h"
20 #include "content/common/paths_efl.h"
21 #include "content/public/browser/browser_thread.h"
23 using namespace password_manager;
24 using password_manager::PasswordStore;
26 PasswordStoreService::PasswordStoreService(
27 scoped_refptr<PasswordStore> password_store)
28 : password_store_(password_store)
32 PasswordStoreService::~PasswordStoreService()
36 scoped_refptr<PasswordStore> PasswordStoreService::GetPasswordStore()
38 return password_store_;
42 scoped_refptr<PasswordStore> PasswordStoreFactory::GetPasswordStore()
44 PasswordStoreService* service = GetInstance()->GetService();
47 return service->GetPasswordStore();
51 PasswordStoreFactory* PasswordStoreFactory::GetInstance()
53 return base::Singleton<PasswordStoreFactory>::get();
56 PasswordStoreFactory::PasswordStoreFactory()
58 WebDataServiceFactory::GetInstance();
62 PasswordStoreFactory::~PasswordStoreFactory()
66 void PasswordStoreFactory::Init()
68 base::FilePath db_path;
69 if (!PathService::Get(PathsEfl::WEB_DATABASE_DIR, &db_path)) {
70 LOG(ERROR) << "Could not access login database path.";
74 base::FilePath login_db_file_path = db_path.Append(FILE_PATH_LITERAL(".LoginData.db"));
76 scoped_ptr<LoginDatabase> login_db(new LoginDatabase(login_db_file_path));
78 base::ThreadRestrictions::ScopedAllowIO allow_io;
79 if (!login_db->Init()) {
80 LOG(ERROR) << "Could not initialize login database.";
85 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner(
86 base::ThreadTaskRunnerHandle::Get());
87 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner(
88 content::BrowserThread::GetMessageLoopProxyForThread(
89 content::BrowserThread::DB));
91 scoped_refptr<PasswordStore> ps;
93 ps = new PasswordStoreDefault(
94 main_thread_runner, db_thread_runner, login_db.Pass());
95 if (!ps.get() || !ps->Init(syncer::SyncableService::StartSyncFlare())) {
96 NOTREACHED() << "Could not initialize password manager.";
100 service_ = new PasswordStoreService(ps);
103 #endif // TIZEN_AUTOFILL_SUPPORT