Chromium Code Reviews| 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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 keychain.Pass(), login_db.Pass()); | 184 keychain.Pass(), login_db.Pass()); |
| 185 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) | 185 #elif defined(OS_CHROMEOS) || defined(OS_ANDROID) |
| 186 // For now, we use PasswordStoreDefault. We might want to make a native | 186 // For now, we use PasswordStoreDefault. We might want to make a native |
| 187 // backend for PasswordStoreX (see below) in the future though. | 187 // backend for PasswordStoreX (see below) in the future though. |
| 188 ps = new password_manager::PasswordStoreDefault( | 188 ps = new password_manager::PasswordStoreDefault( |
| 189 main_thread_runner, db_thread_runner, login_db.Pass()); | 189 main_thread_runner, db_thread_runner, login_db.Pass()); |
| 190 #elif defined(USE_X11) | 190 #elif defined(USE_X11) |
| 191 // On POSIX systems, we try to use the "native" password management system of | 191 // On POSIX systems, we try to use the "native" password management system of |
| 192 // the desktop environment currently running, allowing GNOME Keyring in XFCE. | 192 // the desktop environment currently running, allowing GNOME Keyring in XFCE. |
| 193 // (In all cases we fall back on the basic store in case of failure.) | 193 // (In all cases we fall back on the basic store in case of failure.) |
| 194 base::nix::DesktopEnvironment desktop_env; | 194 base::nix::DesktopEnvironment desktop_env = GetDesktopEnvironment(); |
| 195 base::nix::DesktopEnvironment used_desktop_env; | |
| 195 std::string store_type = | 196 std::string store_type = |
| 196 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( | 197 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
| 197 switches::kPasswordStore); | 198 switches::kPasswordStore); |
| 199 LinuxBackendUsed used_backend = PLAINTEXT; | |
| 198 if (store_type == "kwallet") { | 200 if (store_type == "kwallet") { |
| 199 desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; | 201 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; |
| 200 } else if (store_type == "gnome") { | 202 } else if (store_type == "gnome") { |
| 201 desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; | 203 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; |
| 202 } else if (store_type == "basic") { | 204 } else if (store_type == "basic") { |
| 203 desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; | 205 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; |
| 204 } else { | 206 } else { |
| 205 // Detect the store to use automatically. | 207 // Detect the store to use automatically. |
| 206 scoped_ptr<base::Environment> env(base::Environment::Create()); | 208 used_desktop_env = desktop_env; |
| 207 desktop_env = base::nix::GetDesktopEnvironment(env.get()); | |
| 208 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env); | 209 const char* name = base::nix::GetDesktopEnvironmentName(desktop_env); |
| 209 VLOG(1) << "Password storage detected desktop environment: " | 210 VLOG(1) << "Password storage detected desktop environment: " |
| 210 << (name ? name : "(unknown)"); | 211 << (name ? name : "(unknown)"); |
| 211 } | 212 } |
| 212 | 213 |
| 213 PrefService* prefs = profile->GetPrefs(); | 214 PrefService* prefs = profile->GetPrefs(); |
| 214 LocalProfileId id = GetLocalProfileId(prefs); | 215 LocalProfileId id = GetLocalProfileId(prefs); |
| 215 | 216 |
| 216 scoped_ptr<PasswordStoreX::NativeBackend> backend; | 217 scoped_ptr<PasswordStoreX::NativeBackend> backend; |
| 217 if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4) { | 218 if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4) { |
| 218 // KDE3 didn't use DBus, which our KWallet store uses. | 219 // KDE3 didn't use DBus, which our KWallet store uses. |
| 219 VLOG(1) << "Trying KWallet for password storage."; | 220 VLOG(1) << "Trying KWallet for password storage."; |
| 220 backend.reset(new NativeBackendKWallet(id)); | 221 backend.reset(new NativeBackendKWallet(id)); |
| 221 if (backend->Init()) | 222 if (backend->Init()) { |
| 222 VLOG(1) << "Using KWallet for password storage."; | 223 VLOG(1) << "Using KWallet for password storage."; |
| 223 else | 224 used_backend = KWALLET; |
| 225 } else | |
| 224 backend.reset(); | 226 backend.reset(); |
| 225 } else if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || | 227 } else if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || |
| 226 desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || | 228 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || |
| 227 desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { | 229 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { |
| 228 #if defined(USE_LIBSECRET) | 230 #if defined(USE_LIBSECRET) |
| 229 if (base::FieldTrialList::FindFullName(kLibsecretFieldTrialName) != | 231 if (base::FieldTrialList::FindFullName(kLibsecretFieldTrialName) != |
| 230 kLibsecretFieldTrialDisabledGroupName) { | 232 kLibsecretFieldTrialDisabledGroupName) { |
| 231 VLOG(1) << "Trying libsecret for password storage."; | 233 VLOG(1) << "Trying libsecret for password storage."; |
| 232 backend.reset(new NativeBackendLibsecret(id)); | 234 backend.reset(new NativeBackendLibsecret(id)); |
| 233 if (backend->Init()) | 235 if (backend->Init()) { |
| 234 VLOG(1) << "Using libsecret keyring for password storage."; | 236 VLOG(1) << "Using libsecret keyring for password storage."; |
| 235 else | 237 used_backend = LIBSECRET; |
| 238 } else | |
| 236 backend.reset(); | 239 backend.reset(); |
| 237 } | 240 } |
| 238 #endif // defined(USE_LIBSECRET) | 241 #endif // defined(USE_LIBSECRET) |
| 239 if (!backend.get()) { | 242 if (!backend.get()) { |
| 240 #if defined(USE_GNOME_KEYRING) | 243 #if defined(USE_GNOME_KEYRING) |
| 241 VLOG(1) << "Trying GNOME keyring for password storage."; | 244 VLOG(1) << "Trying GNOME keyring for password storage."; |
| 242 backend.reset(new NativeBackendGnome(id)); | 245 backend.reset(new NativeBackendGnome(id)); |
| 243 if (backend->Init()) | 246 if (backend->Init()) { |
| 244 VLOG(1) << "Using GNOME keyring for password storage."; | 247 VLOG(1) << "Using GNOME keyring for password storage."; |
| 245 else | 248 used_backend = GNOME_KEYRING; |
| 249 } else | |
| 246 backend.reset(); | 250 backend.reset(); |
| 247 #endif // defined(USE_GNOME_KEYRING) | 251 #endif // defined(USE_GNOME_KEYRING) |
| 248 } | 252 } |
| 249 } | 253 } |
| 250 | 254 |
| 251 if (!backend.get()) { | 255 if (!backend.get()) { |
| 252 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " | 256 LOG(WARNING) << "Using basic (unencrypted) store for password storage. " |
| 253 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " | 257 "See http://code.google.com/p/chromium/wiki/LinuxPasswordStorage for " |
| 254 "more information about password storage options."; | 258 "more information about password storage options."; |
| 255 } | 259 } |
| 256 | 260 |
| 257 ps = new PasswordStoreX(main_thread_runner, db_thread_runner, login_db.Pass(), | 261 ps = new PasswordStoreX(main_thread_runner, db_thread_runner, login_db.Pass(), |
| 258 backend.release()); | 262 backend.release()); |
| 263 RecordBackendStatistics(desktop_env, store_type, used_backend); | |
| 259 #elif defined(USE_OZONE) | 264 #elif defined(USE_OZONE) |
| 260 ps = new password_manager::PasswordStoreDefault( | 265 ps = new password_manager::PasswordStoreDefault( |
| 261 main_thread_runner, db_thread_runner, login_db.Pass()); | 266 main_thread_runner, db_thread_runner, login_db.Pass()); |
| 262 #else | 267 #else |
| 263 NOTIMPLEMENTED(); | 268 NOTIMPLEMENTED(); |
| 264 #endif | 269 #endif |
| 265 if (!ps.get() || | 270 if (!ps.get() || |
| 266 !ps->Init( | 271 !ps->Init( |
| 267 sync_start_util::GetFlareForSyncableService(profile->GetPath()))) { | 272 sync_start_util::GetFlareForSyncableService(profile->GetPath()))) { |
| 268 NOTREACHED() << "Could not initialize password manager."; | 273 NOTREACHED() << "Could not initialize password manager."; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 285 } | 290 } |
| 286 | 291 |
| 287 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse( | 292 content::BrowserContext* PasswordStoreFactory::GetBrowserContextToUse( |
| 288 content::BrowserContext* context) const { | 293 content::BrowserContext* context) const { |
| 289 return chrome::GetBrowserContextRedirectedInIncognito(context); | 294 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 290 } | 295 } |
| 291 | 296 |
| 292 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const { | 297 bool PasswordStoreFactory::ServiceIsNULLWhileTesting() const { |
| 293 return true; | 298 return true; |
| 294 } | 299 } |
| 300 | |
| 301 #if defined(USE_X11) | |
| 302 base::nix::DesktopEnvironment PasswordStoreFactory::GetDesktopEnvironment() { | |
| 303 scoped_ptr<base::Environment> env(base::Environment::Create()); | |
| 304 return base::nix::GetDesktopEnvironment(env.get()); | |
| 305 } | |
| 306 | |
| 307 void PasswordStoreFactory::RecordBackendStatistics( | |
| 308 base::nix::DesktopEnvironment desktop_env, | |
| 309 const std::string& command_line_flag, | |
| 310 LinuxBackendUsed used_backend) { | |
| 311 LinuxBackendUsage usage = OTHER_PLAINTEXT; | |
| 312 if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4) { | |
| 313 if (command_line_flag == "kwallet") { | |
| 314 usage = used_backend == KWALLET ? KDE_KWALLETFLAG_KWALLET | |
| 315 : KDE_KWALLETFLAG_PLAINTEXT; | |
| 316 } else if (command_line_flag == "gnome") { | |
| 317 usage = used_backend == PLAINTEXT | |
| 318 ? KDE_GNOMEFLAG_PLAINTEXT | |
| 319 : (used_backend == GNOME_KEYRING ? KDE_GNOMEFLAG_KEYRING | |
| 320 : KDE_GNOMEFLAG_LIBSECRET); | |
| 321 } else if (command_line_flag == "basic") { | |
| 322 usage = KDE_BASICFLAG_PLAINTEXT; | |
| 323 } else { | |
| 324 usage = | |
| 325 used_backend == KWALLET ? KDE_NOFLAG_KWALLET : KDE_NOFLAG_PLAINTEXT; | |
| 326 } | |
| 327 } else if (desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || | |
| 328 desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || | |
| 329 desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { | |
| 330 if (command_line_flag == "kwallet") { | |
| 331 usage = used_backend == KWALLET ? GNOME_KWALLETFLAG_KWALLET | |
| 332 : GNOME_KWALLETFLAG_PLAINTEXT; | |
| 333 } else if (command_line_flag == "gnome") { | |
| 334 usage = used_backend == PLAINTEXT | |
| 335 ? GNOME_GNOMEFLAG_PLAINTEXT | |
| 336 : (used_backend == GNOME_KEYRING ? GNOME_GNOMEFLAG_KEYRING | |
| 337 : GNOME_GNOMEFLAG_LIBSECRET); | |
| 338 } else if (command_line_flag == "basic") { | |
| 339 usage = GNOME_BASICFLAG_PLAINTEXT; | |
| 340 } else { | |
| 341 usage = used_backend == PLAINTEXT | |
| 342 ? GNOME_NOFLAG_PLAINTEXT | |
| 343 : (used_backend == GNOME_KEYRING ? GNOME_NOFLAG_KEYRING | |
| 344 : GNOME_NOFLAG_LIBSECRET); | |
| 345 } | |
| 346 } else { | |
| 347 // It is not Gnome nor KDE environment. | |
|
vabr (Chromium)
2015/01/28 12:26:23
grammar: not -> neither
dvadym
2015/01/28 13:15:11
Done.
| |
| 348 switch (used_backend) { | |
| 349 case PLAINTEXT: | |
| 350 usage = OTHER_PLAINTEXT; | |
| 351 break; | |
| 352 case KWALLET: | |
| 353 usage = OTHER_KWALLET; | |
| 354 break; | |
| 355 case GNOME_KEYRING: | |
| 356 usage = OTHER_KEYRING; | |
| 357 break; | |
| 358 case LIBSECRET: | |
| 359 usage = OTHER_LIBSECRET; | |
| 360 break; | |
| 361 } | |
| 362 } | |
| 363 UMA_HISTOGRAM_ENUMERATION("PasswordManager.LinuxBackendStatistics", usage, | |
| 364 MAX_BACKEND_USAGE_VALUE); | |
| 365 } | |
| 366 #endif | |
| OLD | NEW |