Chromium Code Reviews| Index: components/os_crypt/key_storage_linux.cc |
| diff --git a/components/os_crypt/key_storage_linux.cc b/components/os_crypt/key_storage_linux.cc |
| index c243a129808d6c8cd850189962ce20d1bfabae07..706f9064d6111b2d82cfa168646cdff565fd3ef4 100644 |
| --- a/components/os_crypt/key_storage_linux.cc |
| +++ b/components/os_crypt/key_storage_linux.cc |
| @@ -4,14 +4,56 @@ |
| #include "components/os_crypt/key_storage_linux.h" |
| +#include <string.h> |
| + |
| +#include "base/environment.h" |
| +#include "base/logging.h" |
| +#include "base/nix/xdg_util.h" |
| + |
| +#if defined(USE_LIBSECRET) |
| #include "components/os_crypt/key_storage_libsecret.h" |
| +#endif // defined(USE_LIBSECRET) |
| + |
| +const char* KeyStorageLinux::s_store_ = nullptr; |
| + |
| +// static |
| +void KeyStorageLinux::SetStore(const std::string& store_type) { |
| + delete s_store_; |
|
Lei Zhang
2016/07/12 02:02:53
Do we ever call SetStore() multiple times?
cfroussios
2016/07/12 15:25:35
Not currently, but I'm still considering the exten
|
| + s_store_ = strdup(store_type.data()); |
| +} |
| // static |
| std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { |
| - std::unique_ptr<KeyStorageLinux> key_storage(new KeyStorageLibsecret()); |
| + base::nix::DesktopEnvironment used_desktop_env; |
| + std::string store(s_store_ ? s_store_ : ""); |
| + if (store == "kwallet") { |
| + used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4; |
| + } else if (store == "kwallet5") { |
| + used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5; |
| + } else if (store == "gnome") { |
| + used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME; |
| + } else if (store == "basic") { |
| + used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER; |
| + } else { |
| + std::unique_ptr<base::Environment> env(base::Environment::Create()); |
| + used_desktop_env = base::nix::GetDesktopEnvironment(env.get()); |
| + } |
| - if (key_storage->Init()) |
| - return key_storage; |
| + // Try initializing the appropriate store for our environment. |
| + std::unique_ptr<KeyStorageLinux> key_storage; |
| + 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) { |
| +#if defined(USE_LIBSECRET) |
| + key_storage.reset(new KeyStorageLibsecret()); |
| + if (key_storage->Init()) { |
| + VLOG(1) << "OSCrypt using Libsecret as backend."; |
| + return key_storage; |
| + } |
| +#endif |
| + } |
| + // The appropriate store was not available. |
| + VLOG(1) << "OSCrypt could not initialize a backend."; |
| return nullptr; |
| } |