diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 01:07:42 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-29 01:07:42 +0000 |
commit | ffeaed3f5521c7e76509f2d74aa3dcaaacda0de5 (patch) | |
tree | e6ceb20a96233e9fb519ea33d051c7b5772d7634 | |
parent | 932fd710af1cff10f012626c0bfca92402917d0e (diff) | |
download | chromium_src-ffeaed3f5521c7e76509f2d74aa3dcaaacda0de5.zip chromium_src-ffeaed3f5521c7e76509f2d74aa3dcaaacda0de5.tar.gz chromium_src-ffeaed3f5521c7e76509f2d74aa3dcaaacda0de5.tar.bz2 |
Cleanup: Simplify the Linux proxy options code.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6902124
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83463 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/ui/webui/options/advanced_options_utils_gtk.cc | 82 |
1 files changed, 20 insertions, 62 deletions
diff --git a/chrome/browser/ui/webui/options/advanced_options_utils_gtk.cc b/chrome/browser/ui/webui/options/advanced_options_utils_gtk.cc index 1c382ae..edb0f25 100644 --- a/chrome/browser/ui/webui/options/advanced_options_utils_gtk.cc +++ b/chrome/browser/ui/webui/options/advanced_options_utils_gtk.cc @@ -7,18 +7,16 @@ #include "chrome/browser/ui/webui/options/advanced_options_utils.h" #include "base/environment.h" -#include "base/file_util.h" #include "base/nix/xdg_util.h" #include "base/process_util.h" -#include "base/string_tokenizer.h" -#include "chrome/browser/ui/browser_list.h" #include "content/browser/browser_thread.h" #include "content/browser/tab_contents/tab_contents.h" #include "content/common/process_watcher.h" -#include "ui/base/gtk/gtk_signal.h" // Command used to configure GNOME proxy settings. The command was renamed // in January 2009, so both are used to work on both old and new systems. +// As on April 2011, many systems do not have the old command anymore. +// TODO(thestig) Remove the old command in the future. const char* kOldGNOMEProxyConfigCommand[] = {"gnome-network-preferences", NULL}; const char* kGNOMEProxyConfigCommand[] = {"gnome-network-properties", NULL}; // KDE3 and KDE4 are only slightly different, but incompatible. Go figure. @@ -29,38 +27,8 @@ const char* kKDE4ProxyConfigCommand[] = {"kcmshell4", "proxy", NULL}; // supported desktop environment. const char kLinuxProxyConfigUrl[] = "about:linux-proxy-config"; -struct ProxyConfigCommand { - std::string binary; - const char** argv; -}; - namespace { -// Search $PATH to find one of the commands. Store the full path to -// it in the |binary| field and the command array index in in |index|. -bool SearchPATH(ProxyConfigCommand* commands, size_t ncommands, size_t* index) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); - const char* path = getenv("PATH"); - if (!path) - return false; - FilePath bin_path; - CStringTokenizer tk(path, path + strlen(path), ":"); - // Search $PATH looking for the commands in order. - while (tk.GetNext()) { - for (size_t i = 0; i < ncommands; i++) { - bin_path = FilePath(tk.token()).Append(commands[i].argv[0]); - if (file_util::PathExists(bin_path)) { - commands[i].binary = bin_path.value(); - if (index) - *index = i; - return true; - } - } - } - // Did not find any of the binaries in $PATH. - return false; -} - // Show the proxy config URL in the given tab. void ShowLinuxProxyConfigUrl(TabContents* tab_contents) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -73,22 +41,19 @@ void ShowLinuxProxyConfigUrl(TabContents* tab_contents) { } // Start the given proxy configuration utility. -void StartProxyConfigUtil(TabContents* tab_contents, - const ProxyConfigCommand& command) { +bool StartProxyConfigUtil(TabContents* tab_contents, const char* command[]) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); std::vector<std::string> argv; - argv.push_back(command.binary); - for (size_t i = 1; command.argv[i]; i++) - argv.push_back(command.argv[i]); + for (size_t i = 0; command[i]; ++i) + argv.push_back(command[i]); base::file_handle_mapping_vector no_files; base::ProcessHandle handle; if (!base::LaunchApp(argv, no_files, false, &handle)) { - LOG(ERROR) << "StartProxyConfigUtil failed to start " << command.binary; - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableFunction(&ShowLinuxProxyConfigUrl, tab_contents)); - return; + LOG(ERROR) << "StartProxyConfigUtil failed to start " << command[0]; + return false; } ProcessWatcher::EnsureProcessGetsReaped(handle); + return true; } // Detect, and if possible, start the appropriate proxy config utility. On @@ -97,28 +62,23 @@ void DetectAndStartProxyConfigUtil(TabContents* tab_contents) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); scoped_ptr<base::Environment> env(base::Environment::Create()); - ProxyConfigCommand command; - bool found_command = false; + bool launched = false; switch (base::nix::GetDesktopEnvironment(env.get())) { case base::nix::DESKTOP_ENVIRONMENT_GNOME: { - size_t index; - ProxyConfigCommand commands[2]; - commands[0].argv = kGNOMEProxyConfigCommand; - commands[1].argv = kOldGNOMEProxyConfigCommand; - found_command = SearchPATH(commands, 2, &index); - if (found_command) - command = commands[index]; + launched = StartProxyConfigUtil(tab_contents, kGNOMEProxyConfigCommand); + if (!launched) { + launched = StartProxyConfigUtil(tab_contents, + kOldGNOMEProxyConfigCommand); + } break; } case base::nix::DESKTOP_ENVIRONMENT_KDE3: - command.argv = kKDE3ProxyConfigCommand; - found_command = SearchPATH(&command, 1, NULL); + launched = StartProxyConfigUtil(tab_contents, kKDE3ProxyConfigCommand); break; case base::nix::DESKTOP_ENVIRONMENT_KDE4: - command.argv = kKDE4ProxyConfigCommand; - found_command = SearchPATH(&command, 1, NULL); + launched = StartProxyConfigUtil(tab_contents, kKDE4ProxyConfigCommand); break; case base::nix::DESKTOP_ENVIRONMENT_XFCE: @@ -126,12 +86,10 @@ void DetectAndStartProxyConfigUtil(TabContents* tab_contents) { break; } - if (found_command) { - StartProxyConfigUtil(tab_contents, command); - } else { - BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, - NewRunnableFunction(&ShowLinuxProxyConfigUrl, tab_contents)); - } + if (launched) + return; + BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, + NewRunnableFunction(&ShowLinuxProxyConfigUrl, tab_contents)); } } // anonymous namespace |