X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fchrome%2Fbrowser%2Fpassword_manager%2Fpassword_store_factory.cc;h=2ad9819032f8143aa94e16c5e3222698d6d65a2f;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=c7b50a1bdcd2b81322531cec1ca8881a0bdabdab;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/chrome/browser/password_manager/password_store_factory.cc b/src/chrome/browser/password_manager/password_store_factory.cc index c7b50a1..2ad9819 100644 --- a/src/chrome/browser/password_manager/password_store_factory.cc +++ b/src/chrome/browser/password_manager/password_store_factory.cc @@ -7,9 +7,6 @@ #include "base/command_line.h" #include "base/environment.h" #include "base/prefs/pref_service.h" -#include "chrome/browser/password_manager/login_database.h" -#include "chrome/browser/password_manager/password_store.h" -#include "chrome/browser/password_manager/password_store_default.h" #include "chrome/browser/profiles/incognito_helpers.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/browser/webdata/web_data_service_factory.h" @@ -17,7 +14,11 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "components/browser_context_keyed_service/browser_context_dependency_manager.h" +#include "components/password_manager/core/browser/login_database.h" +#include "components/password_manager/core/browser/password_store.h" +#include "components/password_manager/core/browser/password_store_default.h" #include "components/user_prefs/pref_registry_syncable.h" +#include "content/public/browser/browser_thread.h" #if defined(OS_WIN) #include "chrome/browser/password_manager/password_store_win.h" @@ -45,6 +46,22 @@ const LocalProfileId kInvalidLocalProfileId = } // namespace #endif +PasswordStoreService::PasswordStoreService( + scoped_refptr password_store) + : password_store_(password_store) {} + +PasswordStoreService::~PasswordStoreService() {} + +scoped_refptr PasswordStoreService::GetPasswordStore() { + return password_store_; +} + +void PasswordStoreService::Shutdown() { + if (password_store_) + password_store_->Shutdown(); +} + +// static scoped_refptr PasswordStoreFactory::GetForProfile( Profile* profile, Profile::ServiceAccessType sat) { @@ -53,8 +70,12 @@ scoped_refptr PasswordStoreFactory::GetForProfile( return NULL; } - return static_cast( - GetInstance()->GetServiceForBrowserContext(profile, true).get()); + PasswordStoreFactory* factory = GetInstance(); + PasswordStoreService* service = static_cast( + factory->GetServiceForBrowserContext(profile, true)); + if (!service) + return NULL; + return service->GetPasswordStore(); } // static @@ -63,7 +84,7 @@ PasswordStoreFactory* PasswordStoreFactory::GetInstance() { } PasswordStoreFactory::PasswordStoreFactory() - : RefcountedBrowserContextKeyedServiceFactory( + : BrowserContextKeyedServiceFactory( "PasswordStore", BrowserContextDependencyManager::GetInstance()) { DependsOn(WebDataServiceFactory::GetInstance()); @@ -93,39 +114,46 @@ LocalProfileId PasswordStoreFactory::GetLocalProfileId( } #endif -scoped_refptr -PasswordStoreFactory::BuildServiceInstanceFor( +BrowserContextKeyedService* PasswordStoreFactory::BuildServiceInstanceFor( content::BrowserContext* context) const { Profile* profile = static_cast(context); - scoped_refptr ps; base::FilePath login_db_file_path = profile->GetPath(); login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); - LoginDatabase* login_db = new LoginDatabase(); + scoped_ptr login_db(new LoginDatabase()); { // TODO(paivanof@gmail.com): execution of login_db->Init() should go // to DB thread. http://crbug.com/138903 base::ThreadRestrictions::ScopedAllowIO allow_io; if (!login_db->Init(login_db_file_path)) { LOG(ERROR) << "Could not initialize login database."; - delete login_db; return NULL; } } + + scoped_refptr main_thread_runner( + base::MessageLoopProxy::current()); + scoped_refptr db_thread_runner( + content::BrowserThread::GetMessageLoopProxyForThread( + content::BrowserThread::DB)); + + scoped_refptr ps; #if defined(OS_WIN) - ps = new PasswordStoreWin( - login_db, profile, - WebDataService::FromBrowserContext(profile)); + ps = new PasswordStoreWin(main_thread_runner, + db_thread_runner, + login_db.release(), + WebDataService::FromBrowserContext(profile)); #elif defined(OS_MACOSX) - if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain)) { - ps = new PasswordStoreMac(new crypto::MockAppleKeychain(), login_db); - } else { - ps = new PasswordStoreMac(new crypto::AppleKeychain(), login_db); - } + crypto::AppleKeychain* keychain = + CommandLine::ForCurrentProcess()->HasSwitch(switches::kUseMockKeychain) ? + new crypto::MockAppleKeychain() : new crypto::AppleKeychain(); + ps = new PasswordStoreMac( + main_thread_runner, db_thread_runner, keychain, login_db.release()); #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) // For now, we use PasswordStoreDefault. We might want to make a native // backend for PasswordStoreX (see below) in the future though. - ps = new PasswordStoreDefault(login_db, profile); + ps = new PasswordStoreDefault( + main_thread_runner, db_thread_runner, login_db.release()); #elif defined(USE_X11) // On POSIX systems, we try to use the "native" password management system of // the desktop environment currently running, allowing GNOME Keyring in XFCE. @@ -180,21 +208,22 @@ PasswordStoreFactory::BuildServiceInstanceFor( "more information about password storage options."; } - ps = new PasswordStoreX(login_db, profile, backend.release()); + ps = new PasswordStoreX(main_thread_runner, + db_thread_runner, + login_db.release(), + backend.release()); #elif defined(USE_OZONE) - ps = new PasswordStoreDefault(login_db, profile); + ps = new PasswordStoreDefault( + main_thread_runner, db_thread_runner, login_db.release()); #else NOTIMPLEMENTED(); #endif - if (!ps.get()) - delete login_db; - - if (!ps.get() || !ps->Init()) { + if (!ps || !ps->Init()) { NOTREACHED() << "Could not initialize password manager."; return NULL; } - return ps; + return new PasswordStoreService(ps); } void PasswordStoreFactory::RegisterProfilePrefs(