| 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 "net/proxy/proxy_config_service_linux.h" | 5 #include "net/proxy/proxy_config_service_linux.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #if defined(USE_GCONF) | 8 #if defined(USE_GCONF) |
| 9 #include <gconf/gconf-client.h> | 9 #include <gconf/gconf-client.h> |
| 10 #endif // defined(USE_GCONF) | 10 #endif // defined(USE_GCONF) |
| 11 #include <limits.h> | 11 #include <limits.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <stdlib.h> | 13 #include <stdlib.h> |
| 14 #include <sys/inotify.h> | 14 #include <sys/inotify.h> |
| 15 #include <unistd.h> | 15 #include <unistd.h> |
| 16 | 16 |
| 17 #include <map> | 17 #include <map> |
| 18 | 18 |
| 19 #include "base/bind.h" | 19 #include "base/bind.h" |
| 20 #include "base/compiler_specific.h" | 20 #include "base/compiler_specific.h" |
| 21 #include "base/debug/leak_annotations.h" | 21 #include "base/debug/leak_annotations.h" |
| 22 #include "base/environment.h" | |
| 23 #include "base/files/file_path.h" | 22 #include "base/files/file_path.h" |
| 24 #include "base/files/file_util.h" | 23 #include "base/files/file_util.h" |
| 25 #include "base/files/scoped_file.h" | 24 #include "base/files/scoped_file.h" |
| 26 #include "base/logging.h" | 25 #include "base/logging.h" |
| 27 #include "base/macros.h" | 26 #include "base/macros.h" |
| 28 #include "base/message_loop/message_loop.h" | 27 #include "base/message_loop/message_loop.h" |
| 29 #include "base/nix/xdg_util.h" | 28 #include "base/nix/xdg_util.h" |
| 30 #include "base/single_thread_task_runner.h" | 29 #include "base/single_thread_task_runner.h" |
| 31 #include "base/strings/string_number_conversions.h" | 30 #include "base/strings/string_number_conversions.h" |
| 32 #include "base/strings/string_split.h" | |
| 33 #include "base/strings/string_tokenizer.h" | 31 #include "base/strings/string_tokenizer.h" |
| 34 #include "base/strings/string_util.h" | 32 #include "base/strings/string_util.h" |
| 35 #include "base/threading/thread_restrictions.h" | 33 #include "base/threading/thread_restrictions.h" |
| 36 #include "base/timer/timer.h" | 34 #include "base/timer/timer.h" |
| 37 #include "net/base/net_errors.h" | 35 #include "net/base/net_errors.h" |
| 38 #include "net/http/http_util.h" | 36 #include "net/http/http_util.h" |
| 39 #include "net/proxy/proxy_config.h" | 37 #include "net/proxy/proxy_config.h" |
| 40 #include "net/proxy/proxy_server.h" | 38 #include "net/proxy/proxy_server.h" |
| 41 #include "url/url_canon.h" | 39 #include "url/url_canon.h" |
| 42 | 40 |
| (...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 827 if (SchemaExists(kProxyGConfSchema)) { | 825 if (SchemaExists(kProxyGConfSchema)) { |
| 828 ANNOTATE_SCOPED_MEMORY_LEAK; // http://crbug.com/380782 | 826 ANNOTATE_SCOPED_MEMORY_LEAK; // http://crbug.com/380782 |
| 829 client = libgio_loader_.g_settings_new(kProxyGConfSchema); | 827 client = libgio_loader_.g_settings_new(kProxyGConfSchema); |
| 830 } | 828 } |
| 831 if (!client) { | 829 if (!client) { |
| 832 VLOG(1) << "Cannot create gsettings client. Will fall back to gconf."; | 830 VLOG(1) << "Cannot create gsettings client. Will fall back to gconf."; |
| 833 return false; | 831 return false; |
| 834 } | 832 } |
| 835 g_object_unref(client); | 833 g_object_unref(client); |
| 836 | 834 |
| 837 std::string path; | 835 // Yes, we're on the UI thread. Yes, we're accessing the file system. |
| 838 if (!env->GetVar("PATH", &path)) { | 836 // Sadly, we don't have much choice. We need the proxy settings and we |
| 839 LOG(ERROR) << "No $PATH variable. Assuming no gnome-network-properties."; | 837 // need them now, and to figure out where to get them, we have to check |
| 840 } else { | 838 // for this binary. See http://crbug.com/69057 for additional details. |
| 841 // Yes, we're on the UI thread. Yes, we're accessing the file system. | 839 { |
| 842 // Sadly, we don't have much choice. We need the proxy settings and we | |
| 843 // need them now, and to figure out where to get them, we have to check | |
| 844 // for this binary. See http://crbug.com/69057 for additional details. | |
| 845 base::ThreadRestrictions::ScopedAllowIO allow_io; | 840 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 846 | 841 if (base::ExecutableExistsInPath(env, "gnome-network-properties")) { |
| 847 for (const base::StringPiece& path_str : base::SplitStringPiece( | 842 VLOG(1) << "Found gnome-network-properties. Will fall back to gconf."; |
| 848 path, ":", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { | 843 return false; |
| 849 base::FilePath file(path_str); | |
| 850 if (base::PathExists(file.Append("gnome-network-properties"))) { | |
| 851 VLOG(1) << "Found gnome-network-properties. Will fall back to gconf."; | |
| 852 return false; | |
| 853 } | |
| 854 } | 844 } |
| 855 } | 845 } |
| 856 | 846 |
| 857 VLOG(1) << "All gsettings tests OK. Will get proxy config from gsettings."; | 847 VLOG(1) << "All gsettings tests OK. Will get proxy config from gsettings."; |
| 858 return true; | 848 return true; |
| 859 } | 849 } |
| 860 #endif // defined(USE_GIO) | 850 #endif // defined(USE_GIO) |
| 861 | 851 |
| 862 // This is the KDE version that reads kioslaverc and simulates gconf. | 852 // This is the KDE version that reads kioslaverc and simulates gconf. |
| 863 // Doing this allows the main Delegate code, as well as the unit tests | 853 // Doing this allows the main Delegate code, as well as the unit tests |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1784 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1774 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
| 1785 delegate_->RemoveObserver(observer); | 1775 delegate_->RemoveObserver(observer); |
| 1786 } | 1776 } |
| 1787 | 1777 |
| 1788 ProxyConfigService::ConfigAvailability | 1778 ProxyConfigService::ConfigAvailability |
| 1789 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1779 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
| 1790 return delegate_->GetLatestProxyConfig(config); | 1780 return delegate_->GetLatestProxyConfig(config); |
| 1791 } | 1781 } |
| 1792 | 1782 |
| 1793 } // namespace net | 1783 } // namespace net |
| OLD | NEW |