| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/nix/xdg_util.h" | 5 #include "base/nix/xdg_util.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base_paths.h" | |
| 10 #include "base/environment.h" | 9 #include "base/environment.h" |
| 11 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 12 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 13 #include "base/path_service.h" | |
| 14 #include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h" | 12 #include "base/third_party/xdg_user_dirs/xdg_user_dir_lookup.h" |
| 15 | 13 |
| 16 namespace { | 14 namespace { |
| 17 | 15 |
| 18 // The KDE session version environment variable used in KDE 4. | 16 // The KDE session version environment variable used in KDE 4. |
| 19 const char kKDE4SessionEnvVar[] = "KDE_SESSION_VERSION"; | 17 const char kKDE4SessionEnvVar[] = "KDE_SESSION_VERSION"; |
| 20 | 18 |
| 21 } // namespace | 19 } // namespace |
| 22 | 20 |
| 23 namespace base { | 21 namespace base { |
| 24 namespace nix { | 22 namespace nix { |
| 25 | 23 |
| 26 const char kDotConfigDir[] = ".config"; | 24 const char kDotConfigDir[] = ".config"; |
| 27 const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME"; | 25 const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME"; |
| 28 | 26 |
| 29 FilePath GetXDGDirectory(Environment* env, const char* env_name, | 27 FilePath GetXDGDirectory(Environment* env, const char* env_name, |
| 30 const char* fallback_dir) { | 28 const char* fallback_dir) { |
| 31 FilePath path; | 29 FilePath path; |
| 32 std::string env_value; | 30 std::string env_value; |
| 33 if (env->GetVar(env_name, &env_value) && !env_value.empty()) { | 31 if (env->GetVar(env_name, &env_value) && !env_value.empty()) |
| 34 path = FilePath(env_value); | 32 path = FilePath(env_value); |
| 35 } else { | 33 else |
| 36 PathService::Get(base::DIR_HOME, &path); | 34 path = GetHomeDir().Append(fallback_dir); |
| 37 path = path.Append(fallback_dir); | |
| 38 } | |
| 39 return path.StripTrailingSeparators(); | 35 return path.StripTrailingSeparators(); |
| 40 } | 36 } |
| 41 | 37 |
| 42 FilePath GetXDGUserDirectory(const char* dir_name, const char* fallback_dir) { | 38 FilePath GetXDGUserDirectory(const char* dir_name, const char* fallback_dir) { |
| 43 FilePath path; | 39 FilePath path; |
| 44 char* xdg_dir = xdg_user_dir_lookup(dir_name); | 40 char* xdg_dir = xdg_user_dir_lookup(dir_name); |
| 45 if (xdg_dir) { | 41 if (xdg_dir) { |
| 46 path = FilePath(xdg_dir); | 42 path = FilePath(xdg_dir); |
| 47 free(xdg_dir); | 43 free(xdg_dir); |
| 48 } else { | 44 } else { |
| 49 PathService::Get(base::DIR_HOME, &path); | 45 path = GetHomeDir().Append(fallback_dir); |
| 50 path = path.Append(fallback_dir); | |
| 51 } | 46 } |
| 52 return path.StripTrailingSeparators(); | 47 return path.StripTrailingSeparators(); |
| 53 } | 48 } |
| 54 | 49 |
| 55 DesktopEnvironment GetDesktopEnvironment(Environment* env) { | 50 DesktopEnvironment GetDesktopEnvironment(Environment* env) { |
| 56 // XDG_CURRENT_DESKTOP is the newest standard circa 2012. | 51 // XDG_CURRENT_DESKTOP is the newest standard circa 2012. |
| 57 std::string xdg_current_desktop; | 52 std::string xdg_current_desktop; |
| 58 if (env->GetVar("XDG_CURRENT_DESKTOP", &xdg_current_desktop)) { | 53 if (env->GetVar("XDG_CURRENT_DESKTOP", &xdg_current_desktop)) { |
| 59 // Not all desktop environments set this env var as of this writing. | 54 // Not all desktop environments set this env var as of this writing. |
| 60 if (xdg_current_desktop == "Unity") | 55 if (xdg_current_desktop == "Unity") |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 106 } |
| 112 return NULL; | 107 return NULL; |
| 113 } | 108 } |
| 114 | 109 |
| 115 const char* GetDesktopEnvironmentName(Environment* env) { | 110 const char* GetDesktopEnvironmentName(Environment* env) { |
| 116 return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); | 111 return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); |
| 117 } | 112 } |
| 118 | 113 |
| 119 } // namespace nix | 114 } // namespace nix |
| 120 } // namespace base | 115 } // namespace base |
| OLD | NEW |