summaryrefslogtreecommitdiffstats
path: root/base/linux_util.cc
diff options
context:
space:
mode:
authormattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 00:22:49 +0000
committermattm@chromium.org <mattm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-22 00:22:49 +0000
commit87fc168b364ef36033f72e545a4894bd7ce9354f (patch)
tree8dd7a36186859c6b42be3156178373d91599e310 /base/linux_util.cc
parentbda0b8792b40ce11649995a622344b0aa91b7a9d (diff)
downloadchromium_src-87fc168b364ef36033f72e545a4894bd7ce9354f.zip
chromium_src-87fc168b364ef36033f72e545a4894bd7ce9354f.tar.gz
chromium_src-87fc168b364ef36033f72e545a4894bd7ce9354f.tar.bz2
Try again: Add proxy config (using gnome-network-preferences)
BUG=11507 TEST=Open options, click change proxy, gnome-network-preferences should launch.  If gnome isn't installed or running, LinuxProxyConfig wiki page should load. Review URL: http://codereview.chromium.org/155792 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21246 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/linux_util.cc')
-rw-r--r--base/linux_util.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/base/linux_util.cc b/base/linux_util.cc
index 604980b..bc99d44 100644
--- a/base/linux_util.cc
+++ b/base/linux_util.cc
@@ -10,6 +10,41 @@
#include "base/command_line.h"
#include "base/process_util.h"
+#include "base/string_util.h"
+
+namespace {
+
+class EnvironmentVariableGetterImpl
+ : public base::EnvironmentVariableGetter {
+ public:
+ virtual bool Getenv(const char* variable_name, std::string* result) {
+ const char* env_value = ::getenv(variable_name);
+ if (env_value) {
+ // Note that the variable may be defined but empty.
+ *result = env_value;
+ return true;
+ }
+ // Some commonly used variable names are uppercase while others
+ // are lowercase, which is inconsistent. Let's try to be helpful
+ // and look for a variable name with the reverse case.
+ char first_char = variable_name[0];
+ std::string alternate_case_var;
+ if (first_char >= 'a' && first_char <= 'z')
+ alternate_case_var = StringToUpperASCII(std::string(variable_name));
+ else if (first_char >= 'A' && first_char <= 'Z')
+ alternate_case_var = StringToLowerASCII(std::string(variable_name));
+ else
+ return false;
+ env_value = ::getenv(alternate_case_var.c_str());
+ if (env_value) {
+ *result = env_value;
+ return true;
+ }
+ return false;
+ }
+};
+
+} // anonymous namespace
namespace base {
@@ -59,4 +94,19 @@ std::string GetLinuxDistro() {
return linux_distro;
}
+// static
+EnvironmentVariableGetter* EnvironmentVariableGetter::Create() {
+ return new EnvironmentVariableGetterImpl();
+}
+
+bool UseGnomeForSettings(EnvironmentVariableGetter* env_var_getter) {
+ // GNOME_DESKTOP_SESSION_ID being defined is a good indication that
+ // we are probably running under GNOME.
+ // Note: KDE_FULL_SESSION is a corresponding env var to recognize KDE.
+ std::string dummy, desktop_session;
+ return env_var_getter->Getenv("GNOME_DESKTOP_SESSION_ID", &dummy)
+ || (env_var_getter->Getenv("DESKTOP_SESSION", &desktop_session)
+ && desktop_session == "gnome");
+}
+
} // namespace base