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

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: Addressed comments from gcasto@. 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"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
172 db_thread_runner, 165 db_thread_runner,
173 login_db.release(), 166 login_db.release(),
Garrett Casto 2015/01/20 07:14:18 s/release()/Pass()
engedy 2015/01/20 10:49:14 Done. Gotta love platform-dependent conditionally
174 WebDataServiceFactory::GetPasswordWebDataForProfile( 167 WebDataServiceFactory::GetPasswordWebDataForProfile(
175 profile, ServiceAccessType::EXPLICIT_ACCESS)); 168 profile, ServiceAccessType::EXPLICIT_ACCESS));
176 #elif defined(OS_MACOSX) 169 #elif defined(OS_MACOSX)
177 crypto::AppleKeychain* keychain = 170 scoped_ptr<crypto::AppleKeychain> keychain(
178 base::CommandLine::ForCurrentProcess()->HasSwitch( 171 base::CommandLine::ForCurrentProcess()->HasSwitch(
179 os_crypt::switches::kUseMockKeychain) 172 os_crypt::switches::kUseMockKeychain)
180 ? new crypto::MockAppleKeychain() 173 ? new crypto::MockAppleKeychain()
181 : new crypto::AppleKeychain(); 174 : new crypto::AppleKeychain());
182 ps = new PasswordStoreMac( 175 ps = new PasswordStoreMac(
183 main_thread_runner, db_thread_runner, keychain, login_db.release()); 176 main_thread_runner, db_thread_runner, keychain.Pass(), login_db.Pass());
184 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) 177 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID)
185 // For now, we use PasswordStoreDefault. We might want to make a native 178 // For now, we use PasswordStoreDefault. We might want to make a native
186 // backend for PasswordStoreX (see below) in the future though. 179 // backend for PasswordStoreX (see below) in the future though.
187 ps = new password_manager::PasswordStoreDefault( 180 ps = new password_manager::PasswordStoreDefault(
188 main_thread_runner, db_thread_runner, login_db.release()); 181 main_thread_runner, db_thread_runner, login_db.Pass());
189 #elif defined(USE_X11) 182 #elif defined(USE_X11)
190 // On POSIX systems, we try to use the "native" password management system of 183 // On POSIX systems, we try to use the "native" password management system of
191 // the desktop environment currently running, allowing GNOME Keyring in XFCE. 184 // 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.) 185 // (In all cases we fall back on the basic store in case of failure.)
193 base::nix::DesktopEnvironment desktop_env; 186 base::nix::DesktopEnvironment desktop_env;
194 std::string store_type = 187 std::string store_type =
195 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 188 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
196 switches::kPasswordStore); 189 switches::kPasswordStore);
197 if (store_type == "kwallet") { 190 if (store_type == "kwallet") {
198 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; 191 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 228 }
236 229
237 if (!backend.get()) { 230 if (!backend.get()) {
238 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " 231 LOG(WARNING) << "Using basic (unencrypted) store for password storage. "
239 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " 232 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for "
240 "more information about password storage options."; 233 "more information about password storage options.";
241 } 234 }
242 235
243 ps = new PasswordStoreX(main_thread_runner, 236 ps = new PasswordStoreX(main_thread_runner,
244 db_thread_runner, 237 db_thread_runner,
245 login_db.release(), 238 login_db.Pass(),
246 backend.release()); 239 backend.release());
247 #elif defined(USE_OZONE) 240 #elif defined(USE_OZONE)
248 ps = new password_manager::PasswordStoreDefault( 241 ps = new password_manager::PasswordStoreDefault(
249 main_thread_runner, db_thread_runner, login_db.release()); 242 main_thread_runner, db_thread_runner, login_db.Pass());
250 #else 243 #else
251 NOTIMPLEMENTED(); 244 NOTIMPLEMENTED();
252 #endif 245 #endif
253 if (!ps.get() || 246 if (!ps.get() ||
254 !ps->Init( 247 !ps->Init(
255 sync_start_util::GetFlareForSyncableService(profile->GetPath()))) { 248 sync_start_util::GetFlareForSyncableService(profile->GetPath()))) {
256 NOTREACHED() << "Could not initialize password manager."; 249 NOTREACHED() << "Could not initialize password manager.";
257 return NULL; 250 return NULL;
258 } 251 }
259 252
(...skipping 13 matching lines...) Expand all
273 } 266 }
274 267
275 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse( 268 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse(
276 content::BrowserContext* context) const { 269 content::BrowserContext* context) const {
277 return chrome::GetBrowserContextRedirectedInIncognito(context); 270 return chrome::GetBrowserContextRedirectedInIncognito(context);
278 } 271 }
279 272
280 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const { 273 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const {
281 return true; 274 return true;
282 } 275 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698