Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(289)

Side by Side Diff: chrome/browser/password_manager/password_store_factory.cc

Issue 838453003: Open the LoginDatabase on the DB thread, not the UI thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac namespace fixes. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "chrome/browser/password_manager/password_manager_util.h" 11 #include "chrome/browser/password_manager/password_manager_util.h"
12 #include "chrome/browser/password_manager/sync_metrics.h" 12 #include "chrome/browser/password_manager/sync_metrics.h"
13 #include "chrome/browser/profiles/incognito_helpers.h" 13 #include "chrome/browser/profiles/incognito_helpers.h"
14 #include "chrome/browser/profiles/profile.h" 14 #include "chrome/browser/profiles/profile.h"
15 #include "chrome/browser/sync/glue/sync_start_util.h" 15 #include "chrome/browser/sync/glue/sync_start_util.h"
16 #include "chrome/browser/webdata/web_data_service_factory.h" 16 #include "chrome/browser/webdata/web_data_service_factory.h"
17 #include "chrome/common/chrome_constants.h" 17 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "components/keyed_service/content/browser_context_dependency_manager.h" 19 #include "components/keyed_service/content/browser_context_dependency_manager.h"
20 #include "components/os_crypt/os_crypt_switches.h" 20 #include "components/os_crypt/os_crypt_switches.h"
21 #include "components/password_manager/core/browser/login_database.h"
22 #include "components/password_manager/core/browser/password_store.h" 21 #include "components/password_manager/core/browser/password_store.h"
23 #include "components/password_manager/core/browser/password_store_default.h" 22 #include "components/password_manager/core/browser/password_store_default.h"
24 #include "components/password_manager/core/common/password_manager_pref_names.h" 23 #include "components/password_manager/core/common/password_manager_pref_names.h"
25 #include "components/pref_registry/pref_registry_syncable.h" 24 #include "components/pref_registry/pref_registry_syncable.h"
26 #include "content/public/browser/browser_thread.h" 25 #include "content/public/browser/browser_thread.h"
27 26
28 #if defined(OS_WIN) 27 #if defined(OS_WIN)
29 #include "chrome/browser/password_manager/password_store_win.h" 28 #include "chrome/browser/password_manager/password_store_win.h"
30 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h" 29 #include "components/password_manager/core/browser/webdata/password_web_data_ser vice_win.h"
31 #elif defined(OS_MACOSX) 30 #elif defined(OS_MACOSX)
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 } 140 }
142 #endif 141 #endif
143 142
144 KeyedService* PasswordStoreFactory::BuildServiceInstanceFor( 143 KeyedService* PasswordStoreFactory::BuildServiceInstanceFor(
145 content::BrowserContext* context) const { 144 content::BrowserContext* context) const {
146 DelayReportOsPassword(); 145 DelayReportOsPassword();
147 Profile* profile = static_cast<Profile*>(context); 146 Profile* profile = static_cast<Profile*>(context);
148 147
149 base::FilePath login_db_file_path = profile->GetPath(); 148 base::FilePath login_db_file_path = profile->GetPath();
150 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName); 149 login_db_file_path = login_db_file_path.Append(chrome::kLoginDataFileName);
151 scoped_ptr<password_manager::LoginDatabase> login_db(
152 new password_manager::LoginDatabase());
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 150
163 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner( 151 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner(
164 base::MessageLoopProxy::current()); 152 base::MessageLoopProxy::current());
165 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner( 153 scoped_refptr<base::SingleThreadTaskRunner> db_thread_runner(
166 content::BrowserThread::GetMessageLoopProxyForThread( 154 content::BrowserThread::GetMessageLoopProxyForThread(
167 content::BrowserThread::DB)); 155 content::BrowserThread::DB));
168 156
169 scoped_refptr<PasswordStore> ps; 157 scoped_refptr<PasswordStore> ps;
170 #if defined(OS_WIN) 158 #if defined(OS_WIN)
171 ps = new PasswordStoreWin(main_thread_runner, 159 ps = new PasswordStoreWin(main_thread_runner,
172 db_thread_runner, 160 db_thread_runner,
173 login_db.release(), 161 login_db_file_path,
174 WebDataServiceFactory::GetPasswordWebDataForProfile( 162 WebDataServiceFactory::GetPasswordWebDataForProfile(
175 profile, ServiceAccessType::EXPLICIT_ACCESS)); 163 profile, ServiceAccessType::EXPLICIT_ACCESS));
176 #elif defined(OS_MACOSX) 164 #elif defined(OS_MACOSX)
177 crypto::AppleKeychain* keychain = 165 crypto::AppleKeychain* keychain =
178 base::CommandLine::ForCurrentProcess()->HasSwitch( 166 base::CommandLine::ForCurrentProcess()->HasSwitch(
179 os_crypt::switches::kUseMockKeychain) 167 os_crypt::switches::kUseMockKeychain)
180 ? new crypto::MockAppleKeychain() 168 ? new crypto::MockAppleKeychain()
181 : new crypto::AppleKeychain(); 169 : new crypto::AppleKeychain();
182 ps = new PasswordStoreMac( 170 ps = new PasswordStoreMac(
183 main_thread_runner, db_thread_runner, keychain, login_db.release()); 171 main_thread_runner, db_thread_runner, keychain, login_db_file_path);
184 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) 172 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID)
185 // For now, we use PasswordStoreDefault. We might want to make a native 173 // For now, we use PasswordStoreDefault. We might want to make a native
186 // backend for PasswordStoreX (see below) in the future though. 174 // backend for PasswordStoreX (see below) in the future though.
187 ps = new password_manager::PasswordStoreDefault( 175 ps = new password_manager::PasswordStoreDefault(
188 main_thread_runner, db_thread_runner, login_db.release()); 176 main_thread_runner, db_thread_runner, login_db_file_path);
189 #elif defined(USE_X11) 177 #elif defined(USE_X11)
190 // On POSIX systems, we try to use the "native" password management system of 178 // On POSIX systems, we try to use the "native" password management system of
191 // the desktop environment currently running, allowing GNOME Keyring in XFCE. 179 // 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.) 180 // (In all cases we fall back on the basic store in case of failure.)
193 base::nix::DesktopEnvironment desktop_env; 181 base::nix::DesktopEnvironment desktop_env;
194 std::string store_type = 182 std::string store_type =
195 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 183 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
196 switches::kPasswordStore); 184 switches::kPasswordStore);
197 if (store_type == "kwallet") { 185 if (store_type == "kwallet") {
198 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; 186 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 223 }
236 224
237 if (!backend.get()) { 225 if (!backend.get()) {
238 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " 226 LOG(WARNING) << "Using basic (unencrypted) store for password storage. "
239 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " 227 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for "
240 "more information about password storage options."; 228 "more information about password storage options.";
241 } 229 }
242 230
243 ps = new PasswordStoreX(main_thread_runner, 231 ps = new PasswordStoreX(main_thread_runner,
244 db_thread_runner, 232 db_thread_runner,
245 login_db.release(), 233 login_db_file_path,
246 backend.release()); 234 backend.release());
247 #elif defined(USE_OZONE) 235 #elif defined(USE_OZONE)
248 ps = new password_manager::PasswordStoreDefault( 236 ps = new password_manager::PasswordStoreDefault(
249 main_thread_runner, db_thread_runner, login_db.release()); 237 main_thread_runner, db_thread_runner, login_db.release());
250 #else 238 #else
251 NOTIMPLEMENTED(); 239 NOTIMPLEMENTED();
252 #endif 240 #endif
253 if (!ps.get() || 241 if (!ps.get() ||
254 !ps->Init( 242 !ps->Init(
255 sync_start_util::GetFlareForSyncableService(profile->GetPath()))) { 243 sync_start_util::GetFlareForSyncableService(profile->GetPath()))) {
(...skipping 17 matching lines...) Expand all
273 } 261 }
274 262
275 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse( 263 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse(
276 content::BrowserContext* context) const { 264 content::BrowserContext* context) const {
277 return chrome::GetBrowserContextRedirectedInIncognito(context); 265 return chrome::GetBrowserContextRedirectedInIncognito(context);
278 } 266 }
279 267
280 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const { 268 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const {
281 return true; 269 return true;
282 } 270 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698