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

Side by Side Diff: base/nix/xdg_util.cc

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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
« no previous file with comments | « base/message_loop/message_pump_win.cc ('k') | base/nix/xdg_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 9 #include "base/base_paths.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 15 matching lines...) Expand all
26 const char kDotConfigDir[] = ".config"; 26 const char kDotConfigDir[] = ".config";
27 const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME"; 27 const char kXdgConfigHomeEnvVar[] = "XDG_CONFIG_HOME";
28 28
29 FilePath GetXDGDirectory(Environment* env, const char* env_name, 29 FilePath GetXDGDirectory(Environment* env, const char* env_name,
30 const char* fallback_dir) { 30 const char* fallback_dir) {
31 FilePath path; 31 FilePath path;
32 std::string env_value; 32 std::string env_value;
33 if (env->GetVar(env_name, &env_value) && !env_value.empty()) { 33 if (env->GetVar(env_name, &env_value) && !env_value.empty()) {
34 path = FilePath(env_value); 34 path = FilePath(env_value);
35 } else { 35 } else {
36 PathService::Get(base::DIR_HOME, &path); 36 PathService::Get(DIR_HOME, &path);
37 path = path.Append(fallback_dir); 37 path = path.Append(fallback_dir);
38 } 38 }
39 return path.StripTrailingSeparators(); 39 return path.StripTrailingSeparators();
40 } 40 }
41 41
42 FilePath GetXDGUserDirectory(const char* dir_name, const char* fallback_dir) { 42 FilePath GetXDGUserDirectory(const char* dir_name, const char* fallback_dir) {
43 FilePath path; 43 FilePath path;
44 char* xdg_dir = xdg_user_dir_lookup(dir_name); 44 char* xdg_dir = xdg_user_dir_lookup(dir_name);
45 if (xdg_dir) { 45 if (xdg_dir) {
46 path = FilePath(xdg_dir); 46 path = FilePath(xdg_dir);
47 free(xdg_dir); 47 free(xdg_dir);
48 } else { 48 } else {
49 PathService::Get(base::DIR_HOME, &path); 49 PathService::Get(DIR_HOME, &path);
50 path = path.Append(fallback_dir); 50 path = path.Append(fallback_dir);
51 } 51 }
52 return path.StripTrailingSeparators(); 52 return path.StripTrailingSeparators();
53 } 53 }
54 54
55 DesktopEnvironment GetDesktopEnvironment(Environment* env) { 55 DesktopEnvironment GetDesktopEnvironment(Environment* env) {
56 // XDG_CURRENT_DESKTOP is the newest standard circa 2012. 56 // XDG_CURRENT_DESKTOP is the newest standard circa 2012.
57 std::string xdg_current_desktop; 57 std::string xdg_current_desktop;
58 if (env->GetVar("XDG_CURRENT_DESKTOP", &xdg_current_desktop)) { 58 if (env->GetVar("XDG_CURRENT_DESKTOP", &xdg_current_desktop)) {
59 // Not all desktop environments set this env var as of this writing. 59 // Not all desktop environments set this env var as of this writing.
60 if (xdg_current_desktop == "Unity") { 60 if (xdg_current_desktop == "Unity") {
61 // gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity 61 // gnome-fallback sessions set XDG_CURRENT_DESKTOP to Unity
62 // DESKTOP_SESSION can be gnome-fallback or gnome-fallback-compiz 62 // DESKTOP_SESSION can be gnome-fallback or gnome-fallback-compiz
63 std::string desktop_session; 63 std::string desktop_session;
64 if (env->GetVar("DESKTOP_SESSION", &desktop_session) && 64 if (env->GetVar("DESKTOP_SESSION", &desktop_session) &&
65 desktop_session.find("gnome-fallback") != std::string::npos) { 65 desktop_session.find("gnome-fallback") != std::string::npos) {
66 return DESKTOP_ENVIRONMENT_GNOME; 66 return DESKTOP_ENVIRONMENT_GNOME;
67 } 67 }
68 return DESKTOP_ENVIRONMENT_UNITY; 68 return DESKTOP_ENVIRONMENT_UNITY;
69 } else if (xdg_current_desktop == "GNOME") { 69 } else if (xdg_current_desktop == "GNOME") {
70 return DESKTOP_ENVIRONMENT_GNOME; 70 return DESKTOP_ENVIRONMENT_GNOME;
71 } else if (xdg_current_desktop == "KDE") {
72 return DESKTOP_ENVIRONMENT_KDE4;
71 } 73 }
72 } 74 }
73 75
74 // DESKTOP_SESSION was what everyone used in 2010. 76 // DESKTOP_SESSION was what everyone used in 2010.
75 std::string desktop_session; 77 std::string desktop_session;
76 if (env->GetVar("DESKTOP_SESSION", &desktop_session)) { 78 if (env->GetVar("DESKTOP_SESSION", &desktop_session)) {
77 if (desktop_session == "gnome") { 79 if (desktop_session == "gnome" || desktop_session =="mate") {
78 return DESKTOP_ENVIRONMENT_GNOME; 80 return DESKTOP_ENVIRONMENT_GNOME;
79 } else if (desktop_session == "kde4") { 81 } else if (desktop_session == "kde4" || desktop_session == "kde-plasma") {
80 return DESKTOP_ENVIRONMENT_KDE4; 82 return DESKTOP_ENVIRONMENT_KDE4;
81 } else if (desktop_session == "kde") { 83 } else if (desktop_session == "kde") {
82 // This may mean KDE4 on newer systems, so we have to check. 84 // This may mean KDE4 on newer systems, so we have to check.
83 if (env->HasVar(kKDE4SessionEnvVar)) 85 if (env->HasVar(kKDE4SessionEnvVar))
84 return DESKTOP_ENVIRONMENT_KDE4; 86 return DESKTOP_ENVIRONMENT_KDE4;
85 return DESKTOP_ENVIRONMENT_KDE3; 87 return DESKTOP_ENVIRONMENT_KDE3;
86 } else if (desktop_session.find("xfce") != std::string::npos || 88 } else if (desktop_session.find("xfce") != std::string::npos ||
87 desktop_session == "xubuntu") { 89 desktop_session == "xubuntu") {
88 return DESKTOP_ENVIRONMENT_XFCE; 90 return DESKTOP_ENVIRONMENT_XFCE;
89 } 91 }
(...skipping 29 matching lines...) Expand all
119 } 121 }
120 return NULL; 122 return NULL;
121 } 123 }
122 124
123 const char* GetDesktopEnvironmentName(Environment* env) { 125 const char* GetDesktopEnvironmentName(Environment* env) {
124 return GetDesktopEnvironmentName(GetDesktopEnvironment(env)); 126 return GetDesktopEnvironmentName(GetDesktopEnvironment(env));
125 } 127 }
126 128
127 } // namespace nix 129 } // namespace nix
128 } // namespace base 130 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_pump_win.cc ('k') | base/nix/xdg_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698