summarylogtreecommitdiffstats
path: root/xdg-basedir.patch
blob: b5d14a3ffee16cbabc851637610862892c66e1b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Move ~/.pki directory to ${XDG_DATA_HOME:-$HOME/.local}/share/pki on linux
# builds to follow the XDG Base Directory Specification. For details, refer to
# https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

--- a/base/nix/xdg_util.cc
+++ b/base/nix/xdg_util.cc
@@ -30,6 +30,8 @@ const char kDotConfigDir[] = ".config";
 const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
 const char kXdgCurrentDesktopEnvVar[] = "XDG_CURRENT_DESKTOP";
 const char kXdgSessionTypeEnvVar[] = "XDG_SESSION_TYPE";
+const char kDotDataDir[] = ".local/share";
+const char kXdgDataHomeEnvVar[] = "XDG_DATA_HOME";

 FilePath GetXDGDirectory(Environment* env, const char* env_name,
                          const char* fallback_dir) {

--- a/base/nix/xdg_util.h
+++ b/base/nix/xdg_util.h
@@ -61,6 +61,12 @@ BASE_EXPORT extern const char kXdgCurrentDesktopEnvVar[];
 // The XDG session type environment variable.
 BASE_EXPORT extern const char kXdgSessionTypeEnvVar[];

+// The default XDG data directory name.
+BASE_EXPORT extern const char kDotDataDir[];
+
+// The XDG data directory environment variable.
+BASE_EXPORT extern const char kXdgDataHomeEnvVar[];
+
 // Utility function for getting XDG directories.
 // |env_name| is the name of an environment variable that we want to use to get
 // a directory path. |fallback_dir| is the directory relative to $HOME that we

--- a/crypto/nss_util.cc
+++ b/crypto/nss_util.cc
@@ -30,6 +30,9 @@
 #include "build/chromeos_buildflags.h"
 #include "crypto/nss_crypto_module_delegate.h"
 #include "crypto/nss_util_internal.h"
+#include "base/environment.h"
+#include "base/nix/xdg_util.h"
+#include "chrome/common/chrome_constants.h"

 namespace crypto {

@@ -45,12 +48,21 @@ static const base::FilePath::CharType kReadOnlyCertDB[] =

 base::FilePath GetDefaultConfigDirectory() {
   base::FilePath dir;
+#if defined(OS_LINUX)
+  std::unique_ptr<base::Environment> env(base::Environment::Create());
+  dir = base::nix::GetXDGDirectory(env.get(), base::nix::kXdgDataHomeEnvVar, base::nix::kDotDataDir);
+#else
   base::PathService::Get(base::DIR_HOME, &dir);
+#endif
   if (dir.empty()) {
-    LOG(ERROR) << "Failed to get home directory.";
+    LOG(ERROR) << "Failed to get $HOME or $XDG_DATA_HOME directory.";
     return dir;
   }
+#if defined(OS_LINUX)
+  dir = dir.Append(chrome::kBrowserProcessExecutableName).AppendASCII("pki").AppendASCII("nssdb");
+#else
   dir = dir.AppendASCII(".pki").AppendASCII("nssdb");
+#endif
   if (!base::CreateDirectory(dir)) {
     LOG(ERROR) << "Failed to create " << dir.value() << " directory.";
     dir.clear();