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

Side by Side 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: also gyp 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "components/os_crypt/key_storage_linux.h" 5 #include "components/os_crypt/key_storage_linux.h"
6 6
7 #include <string.h>
8
9 #include "base/environment.h"
10 #include "base/logging.h"
11 #include "base/nix/xdg_util.h"
12
13 #if defined(USE_LIBSECRET)
7 #include "components/os_crypt/key_storage_libsecret.h" 14 #include "components/os_crypt/key_storage_libsecret.h"
15 #endif // defined(USE_LIBSECRET)
16
17 const char* KeyStorageLinux::s_store_ = nullptr;
18
19 // static
20 void KeyStorageLinux::SetStore(const std::string& store_type) {
21 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
22 s_store_ = strdup(store_type.data());
23 }
8 24
9 // static 25 // static
10 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() { 26 std::unique_ptr<KeyStorageLinux> KeyStorageLinux::CreateService() {
11 std::unique_ptr<KeyStorageLinux> key_storage(new KeyStorageLibsecret()); 27 base::nix::DesktopEnvironment used_desktop_env;
28 std::string store(s_store_ ? s_store_ : "");
29 if (store == "kwallet") {
30 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE4;
31 } else if (store == "kwallet5") {
32 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_KDE5;
33 } else if (store == "gnome") {
34 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_GNOME;
35 } else if (store == "basic") {
36 used_desktop_env = base::nix::DESKTOP_ENVIRONMENT_OTHER;
37 } else {
38 std::unique_ptr<base::Environment> env(base::Environment::Create());
39 used_desktop_env = base::nix::GetDesktopEnvironment(env.get());
40 }
12 41
13 if (key_storage->Init()) 42 // Try initializing the appropriate store for our environment.
14 return key_storage; 43 std::unique_ptr<KeyStorageLinux> key_storage;
44 if (used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_GNOME ||
45 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_UNITY ||
46 used_desktop_env == base::nix::DESKTOP_ENVIRONMENT_XFCE) {
47 #if defined(USE_LIBSECRET)
48 key_storage.reset(new KeyStorageLibsecret());
49 if (key_storage->Init()) {
50 VLOG(1) << "OSCrypt using Libsecret as backend.";
51 return key_storage;
52 }
53 #endif
54 }
15 55
56 // The appropriate store was not available.
57 VLOG(1) << "OSCrypt could not initialize a backend.";
16 return nullptr; 58 return nullptr;
17 } 59 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698