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

Unified Diff: components/os_crypt/key_storage_linux.cc

Issue 2118443002: Forward password-store switch to OSCrypt component (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Verify that target does not change after lazy initialization Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
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..3b107d1b7a51ebaff321c42a0fc7c61d5b4b4b86 100644
--- a/components/os_crypt/key_storage_linux.cc
+++ b/components/os_crypt/key_storage_linux.cc
@@ -4,14 +4,55 @@
#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)
Lei Zhang 2016/07/12 19:12:24 Personally, I'm kind of meh about the match commen
cfroussios 2016/07/13 09:33:10 Done.
+
+base::LazyInstance<std::string> g_store_ = LAZY_INSTANCE_INITIALIZER;
+
+// static
+void KeyStorageLinux::SetStore(const std::string& store_type) {
+ g_store_.Get() = store_type;
+ VLOG(1) << "OSCrypt store set to " << store_type;
+}
// static
std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() {
- std::unique_ptr<KeyStorageLinux> key_storage(new KeyStorageLibsecret());
+ base::nix::DesktopEnvironment used_desktop_env;
+ if (g_store_.Get() == "kwallet") {
+ used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4;
+ } else if (g_store_.Get() == "kwallet5") {
+ used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5;
+ } else if (g_store_.Get() == "gnome") {
+ used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME;
+ } else if (g_store_.Get() == "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;
}

Powered by Google App Engine
This is Rietveld 408576698