OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/password_manager/password_store_factory.h" | 5 #include "chrome/browser/password_manager/password_store_factory.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "base/metrics/histogram_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 } | 139 } |
140 return id; | 140 return id; |
141 } | 141 } |
142 #endif | 142 #endif |
143 | 143 |
144 KeyedService* PasswordStoreFactory::BuildServiceInstanceFor( | 144 KeyedService* PasswordStoreFactory::BuildServiceInstanceFor( |
145 content::BrowserContext* context) const { | 145 content::BrowserContext* context) const { |
146 DelayReportOsPassword(); | 146 DelayReportOsPassword(); |
147 Profile* profile = static_cast<Profile*>(context); | 147 Profile* profile = static_cast<Profile*>(context); |
148 | 148 |
| 149 // Given that LoginDatabase::Init() takes ~100ms on average; it will be called |
| 150 // by PasswordStore::Init() on the background thread to avoid UI jank. |
149 base::FilePath login_db_file_path = profile->GetPath(); | 151 base::FilePath login_db_file_path = profile->GetPath(); |
150 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); | 152 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); |
151 scoped_ptr<password_manager::LoginDatabase> login_db( | 153 scoped_ptr<password_manager::LoginDatabase> login_db( |
152 new password_manager::LoginDatabase()); | 154 new password_manager::LoginDatabase(login_db_file_path)); |
153 { | |
154 // TODO(paivanof@gmail.com): execution of login_db->Init() should go | |
155 // to DB thread. http://crbug.com/138903 | |
156 base::ThreadRestrictions::ScopedAllowIO allow_io; | |
157 if (!login_db->Init(login_db_file_path)) { | |
158 LOG(ERROR) << "Could not initialize login database."; | |
159 return NULL; | |
160 } | |
161 } | |
162 | 155 |
163 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner( | 156 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner( |
164 base::MessageLoopProxy::current()); | 157 base::MessageLoopProxy::current()); |
165 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner( | 158 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner( |
166 content::BrowserThread::GetMessageLoopProxyForThread( | 159 content::BrowserThread::GetMessageLoopProxyForThread( |
167 content::BrowserThread::DB)); | 160 content::BrowserThread::DB)); |
168 | 161 |
169 scoped_refptr<PasswordStore> ps; | 162 scoped_refptr<PasswordStore> ps; |
170 #if defined(OS_WIN) | 163 #if defined(OS_WIN) |
171 ps = new PasswordStoreWin(main_thread_runner, | 164 ps = new PasswordStoreWin(main_thread_runner, db_thread_runner, |
172 db_thread_runner, | 165 login_db.Pass(), |
173 login_db.release(), | |
174 WebDataServiceFactory::GetPasswordWebDataForProfile( | 166 WebDataServiceFactory::GetPasswordWebDataForProfile( |
175 profile, ServiceAccessType::EXPLICIT_ACCESS)); | 167 profile, ServiceAccessType::EXPLICIT_ACCESS)); |
176 #elif defined(OS_MACOSX) | 168 #elif defined(OS_MACOSX) |
177 crypto::AppleKeychain* keychain = | 169 scoped_ptr<crypto::AppleKeychain> keychain( |
178 base::CommandLine::ForCurrentProcess()->HasSwitch( | 170 base::CommandLine::ForCurrentProcess()->HasSwitch( |
179 os_crypt::switches::kUseMockKeychain) | 171 os_crypt::switches::kUseMockKeychain) |
180 ? new crypto::MockAppleKeychain() | 172 ? new crypto::MockAppleKeychain() |
181 : new crypto::AppleKeychain(); | 173 : new crypto::AppleKeychain()); |
182 ps = new PasswordStoreMac( | 174 ps = new PasswordStoreMac(main_thread_runner, db_thread_runner, |
183 main_thread_runner, db_thread_runner, keychain, login_db.release()); | 175 keychain.Pass(), login_db.Pass()); |
184 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) | 176 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) |
185 // For now, we use PasswordStoreDefault. We might want to make a native | 177 // For now, we use PasswordStoreDefault. We might want to make a native |
186 // backend for PasswordStoreX (see below) in the future though. | 178 // backend for PasswordStoreX (see below) in the future though. |
187 ps = new password_manager::PasswordStoreDefault( | 179 ps = new password_manager::PasswordStoreDefault( |
188 main_thread_runner, db_thread_runner, login_db.release()); | 180 main_thread_runner, db_thread_runner, login_db.Pass()); |
189 #elif defined(USE_X11) | 181 #elif defined(USE_X11) |
190 // On POSIX systems, we try to use the "native" password management system of | 182 // On POSIX systems, we try to use the "native" password management system of |
191 // the desktop environment currently running, allowing GNOME Keyring in XFCE. | 183 // the desktop environment currently running, allowing GNOME Keyring in XFCE. |
192 // (In all cases we fall back on the basic store in case of failure.) | 184 // (In all cases we fall back on the basic store in case of failure.) |
193 base::nix::DesktopEnvironment desktop_env; | 185 base::nix::DesktopEnvironment desktop_env; |
194 std::string store_type = | 186 std::string store_type = |
195 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 187 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
196 switches::kPasswordStore); | 188 switches::kPasswordStore); |
197 if (store_type == "kwallet") { | 189 if (store_type == "kwallet") { |
198 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; | 190 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 backend.reset(); | 225 backend.reset(); |
234 #endif // defined(USE_GNOME_KEYRING) | 226 #endif // defined(USE_GNOME_KEYRING) |
235 } | 227 } |
236 | 228 |
237 if (!backend.get()) { | 229 if (!backend.get()) { |
238 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " | 230 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " |
239 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " | 231 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " |
240 "more information about password storage options."; | 232 "more information about password storage options."; |
241 } | 233 } |
242 | 234 |
243 ps = new PasswordStoreX(main_thread_runner, | 235 ps = new PasswordStoreX(main_thread_runner, db_thread_runner, login_db.Pass(), |
244 db_thread_runner, | |
245 login_db.release(), | |
246 backend.release()); | 236 backend.release()); |
247 #elif defined(USE_OZONE) | 237 #elif defined(USE_OZONE) |
248 ps = new password_manager::PasswordStoreDefault( | 238 ps = new password_manager::PasswordStoreDefault( |
249 main_thread_runner, db_thread_runner, login_db.release()); | 239 main_thread_runner, db_thread_runner, login_db.Pass()); |
250 #else | 240 #else |
251 NOTIMPLEMENTED(); | 241 NOTIMPLEMENTED(); |
252 #endif | 242 #endif |
253 if (!ps.get() || | 243 if (!ps.get() || |
254 !ps->Init( | 244 !ps->Init( |
255 sync_start_util::GetFlareForSyncableService(profile->GetPath()))) { | 245 sync_start_util::GetFlareForSyncableService(profile->GetPath()))) { |
256 NOTREACHED() << "Could not initialize password manager."; | 246 NOTREACHED() << "Could not initialize password manager."; |
257 return NULL; | 247 return NULL; |
258 } | 248 } |
259 | 249 |
(...skipping 13 matching lines...) Expand all Loading... |
273 } | 263 } |
274 | 264 |
275 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse( | 265 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse( |
276 content::BrowserContext* context) const { | 266 content::BrowserContext* context) const { |
277 return chrome::GetBrowserContextRedirectedInIncognito(context); | 267 return chrome::GetBrowserContextRedirectedInIncognito(context); |
278 } | 268 } |
279 | 269 |
280 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const { | 270 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const { |
281 return true; | 271 return true; |
282 } | 272 } |
OLD | NEW |