Index: chrome/browser/password_manager/password_store_factory.cc |
diff --git a/chrome/browser/password_manager/password_store_factory.cc b/chrome/browser/password_manager/password_store_factory.cc |
index bb575a5022c3a7c90d0b02032029b35231649a1a..b55ad9f037e589887f189d9eb9b5d8ec232921ad 100644 |
--- a/chrome/browser/password_manager/password_store_factory.cc |
+++ b/chrome/browser/password_manager/password_store_factory.cc |
@@ -21,6 +21,7 @@ |
#include "chrome/common/chrome_switches.h" |
#include "components/browser_sync/browser/profile_sync_service.h" |
#include "components/keyed_service/content/browser_context_dependency_manager.h" |
+#include "components/os_crypt/key_storage_util_linux.h" |
#include "components/os_crypt/os_crypt_switches.h" |
#include "components/password_manager/core/browser/login_database.h" |
#include "components/password_manager/core/browser/password_store.h" |
@@ -183,35 +184,25 @@ PasswordStoreFactory::BuildServiceInstanceFor( |
// the desktop environment currently running, allowing GNOME Keyring in XFCE. |
// (In all cases we fall back on the basic store in case of failure.) |
base::nix::DesktopEnvironment desktop_env = GetDesktopEnvironment(); |
- base::nix::DesktopEnvironment used_desktop_env; |
std::string store_type = |
base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
switches::kPasswordStore); |
LinuxBackendUsed used_backend = PLAINTEXT; |
- if (store_type == "kwallet") { |
- used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; |
- } else if (store_type == "kwallet5") { |
- used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5; |
- } else if (store_type == "gnome") { |
- used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; |
- } else if (store_type == "basic") { |
- used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; |
- } else { |
- // Detect the store to use automatically. |
- used_desktop_env = desktop_env; |
- const char* name = base::nix::GetDesktopEnvironmentName(desktop_env); |
- VLOG(1) << "Password storage detected desktop environment: " |
- << (name ? name : "(unknown)"); |
- } |
PrefService* prefs = profile->GetPrefs(); |
LocalProfileId id = GetLocalProfileId(prefs); |
+ os_crypt::SelectedLinuxBackend selected_backend = |
+ os_crypt::SelectBackend(store_type, desktop_env); |
+ |
std::unique_ptr<PasswordStoreX::NativeBackend> backend; |
- if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE4 || |
- used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_KDE5) { |
- // KDE3 didn't use DBus, which our KWallet store uses. |
+ if (selected_backend == os_crypt::SelectedLinuxBackend::KWALLET || |
+ selected_backend == os_crypt::SelectedLinuxBackend::KWALLET5) { |
VLOG(1) << "Trying KWallet for password storage."; |
+ base::nix::DesktopEnvironment used_desktop_env = |
+ selected_backend == os_crypt::SelectedLinuxBackend::KWALLET |
+ ? base::nix::DESKTOP_ENVIRONMENT_KDE4 |
+ : base::nix::DESKTOP_ENVIRONMENT_KDE5; |
backend.reset(new NativeBackendKWallet(id, used_desktop_env)); |
if (backend->Init()) { |
VLOG(1) << "Using KWallet for password storage."; |
@@ -219,21 +210,28 @@ PasswordStoreFactory::BuildServiceInstanceFor( |
} else { |
backend.reset(); |
} |
- } else if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME || |
- used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY || |
- used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) { |
+ } else if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
+ selected_backend == |
+ os_crypt::SelectedLinuxBackend::GNOME_KEYRING || |
+ selected_backend == |
+ os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { |
#if defined(USE_LIBSECRET) |
- VLOG(1) << "Trying libsecret for password storage."; |
- backend.reset(new NativeBackendLibsecret(id)); |
- if (backend->Init()) { |
- VLOG(1) << "Using libsecret keyring for password storage."; |
- used_backend = LIBSECRET; |
- } else { |
- backend.reset(); |
+ if (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
+ selected_backend == os_crypt::SelectedLinuxBackend::GNOME_LIBSECRET) { |
+ VLOG(1) << "Trying libsecret for password storage."; |
+ backend.reset(new NativeBackendLibsecret(id)); |
+ if (backend->Init()) { |
+ VLOG(1) << "Using libsecret keyring for password storage."; |
+ used_backend = LIBSECRET; |
+ } else { |
+ backend.reset(); |
+ } |
} |
#endif // defined(USE_LIBSECRET) |
- if (!backend.get()) { |
#if defined(USE_GNOME_KEYRING) |
+ if (!backend.get() && |
+ (selected_backend == os_crypt::SelectedLinuxBackend::GNOME_ANY || |
+ selected_backend == os_crypt::SelectedLinuxBackend::GNOME_KEYRING)) { |
VLOG(1) << "Trying GNOME keyring for password storage."; |
backend.reset(new NativeBackendGnome(id)); |
if (backend->Init()) { |
@@ -242,8 +240,8 @@ PasswordStoreFactory::BuildServiceInstanceFor( |
} else { |
backend.reset(); |
} |
-#endif // defined(USE_GNOME_KEYRING) |
} |
+#endif // defined(USE_GNOME_KEYRING) |
} |
if (!backend.get()) { |