| 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 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #if defined(USE_GCONF) | 9 #if defined(USE_GCONF) |
| 10 #include <gconf/gconf-client.h> | 10 #include <gconf/gconf-client.h> |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 313 } |
| 314 // Simulate a change to avoid possibly losing updates before this point. | 314 // Simulate a change to avoid possibly losing updates before this point. |
| 315 OnChangeNotification(); | 315 OnChangeNotification(); |
| 316 return true; | 316 return true; |
| 317 } | 317 } |
| 318 | 318 |
| 319 virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE { | 319 virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE { |
| 320 return loop_; | 320 return loop_; |
| 321 } | 321 } |
| 322 | 322 |
| 323 virtual const char* GetDataSource() OVERRIDE { | 323 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
| 324 return "gconf"; | 324 return PROXY_CONFIG_SOURCE_GCONF; |
| 325 } | 325 } |
| 326 | 326 |
| 327 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 327 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
| 328 switch (key) { | 328 switch (key) { |
| 329 case PROXY_MODE: | 329 case PROXY_MODE: |
| 330 return GetStringByPath("/system/proxy/mode", result); | 330 return GetStringByPath("/system/proxy/mode", result); |
| 331 case PROXY_AUTOCONF_URL: | 331 case PROXY_AUTOCONF_URL: |
| 332 return GetStringByPath("/system/proxy/autoconfig_url", result); | 332 return GetStringByPath("/system/proxy/autoconfig_url", result); |
| 333 case PROXY_HTTP_HOST: | 333 case PROXY_HTTP_HOST: |
| 334 return GetStringByPath("/system/http_proxy/host", result); | 334 return GetStringByPath("/system/http_proxy/host", result); |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 G_CALLBACK(OnGSettingsChangeNotification), this); | 631 G_CALLBACK(OnGSettingsChangeNotification), this); |
| 632 // Simulate a change to avoid possibly losing updates before this point. | 632 // Simulate a change to avoid possibly losing updates before this point. |
| 633 OnChangeNotification(); | 633 OnChangeNotification(); |
| 634 return true; | 634 return true; |
| 635 } | 635 } |
| 636 | 636 |
| 637 virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE { | 637 virtual base::MessageLoopProxy* GetNotificationLoop() OVERRIDE { |
| 638 return loop_; | 638 return loop_; |
| 639 } | 639 } |
| 640 | 640 |
| 641 virtual const char* GetDataSource() OVERRIDE { | 641 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
| 642 return "gsettings"; | 642 return PROXY_CONFIG_SOURCE_GSETTINGS; |
| 643 } | 643 } |
| 644 | 644 |
| 645 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 645 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
| 646 DCHECK(client_); | 646 DCHECK(client_); |
| 647 switch (key) { | 647 switch (key) { |
| 648 case PROXY_MODE: | 648 case PROXY_MODE: |
| 649 return GetStringByPath(client_, "mode", result); | 649 return GetStringByPath(client_, "mode", result); |
| 650 case PROXY_AUTOCONF_URL: | 650 case PROXY_AUTOCONF_URL: |
| 651 return GetStringByPath(client_, "autoconfig-url", result); | 651 return GetStringByPath(client_, "autoconfig-url", result); |
| 652 case PROXY_HTTP_HOST: | 652 case PROXY_HTTP_HOST: |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 // Implement base::MessagePumpLibevent::Watcher. | 1039 // Implement base::MessagePumpLibevent::Watcher. |
| 1040 void OnFileCanReadWithoutBlocking(int fd) { | 1040 void OnFileCanReadWithoutBlocking(int fd) { |
| 1041 DCHECK_EQ(fd, inotify_fd_); | 1041 DCHECK_EQ(fd, inotify_fd_); |
| 1042 DCHECK(MessageLoop::current() == file_loop_); | 1042 DCHECK(MessageLoop::current() == file_loop_); |
| 1043 OnChangeNotification(); | 1043 OnChangeNotification(); |
| 1044 } | 1044 } |
| 1045 void OnFileCanWriteWithoutBlocking(int fd) { | 1045 void OnFileCanWriteWithoutBlocking(int fd) { |
| 1046 NOTREACHED(); | 1046 NOTREACHED(); |
| 1047 } | 1047 } |
| 1048 | 1048 |
| 1049 virtual const char* GetDataSource() OVERRIDE { | 1049 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
| 1050 return "KDE"; | 1050 return PROXY_CONFIG_SOURCE_KDE; |
| 1051 } | 1051 } |
| 1052 | 1052 |
| 1053 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 1053 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
| 1054 string_map_type::iterator it = string_table_.find(key); | 1054 string_map_type::iterator it = string_table_.find(key); |
| 1055 if (it == string_table_.end()) | 1055 if (it == string_table_.end()) |
| 1056 return false; | 1056 return false; |
| 1057 *result = it->second; | 1057 *result = it->second; |
| 1058 return true; | 1058 return true; |
| 1059 } | 1059 } |
| 1060 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { | 1060 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { |
| (...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1630 // and only fall back to gconf if env vars were unset. But | 1630 // and only fall back to gconf if env vars were unset. But |
| 1631 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it | 1631 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it |
| 1632 // does so even if the proxy mode is set to auto, which would | 1632 // does so even if the proxy mode is set to auto, which would |
| 1633 // mislead us. | 1633 // mislead us. |
| 1634 | 1634 |
| 1635 bool got_config = false; | 1635 bool got_config = false; |
| 1636 if (setting_getter_.get() && | 1636 if (setting_getter_.get() && |
| 1637 setting_getter_->Init(glib_default_loop, file_loop) && | 1637 setting_getter_->Init(glib_default_loop, file_loop) && |
| 1638 GetConfigFromSettings(&cached_config_)) { | 1638 GetConfigFromSettings(&cached_config_)) { |
| 1639 cached_config_.set_id(1); // Mark it as valid. | 1639 cached_config_.set_id(1); // Mark it as valid. |
| 1640 cached_config_.set_source(setting_getter_->GetConfigSource()); |
| 1640 VLOG(1) << "Obtained proxy settings from " | 1641 VLOG(1) << "Obtained proxy settings from " |
| 1641 << setting_getter_->GetDataSource(); | 1642 << ProxyConfigSourceToString(cached_config_.source()); |
| 1642 | 1643 |
| 1643 // If gconf proxy mode is "none", meaning direct, then we take | 1644 // If gconf proxy mode is "none", meaning direct, then we take |
| 1644 // that to be a valid config and will not check environment | 1645 // that to be a valid config and will not check environment |
| 1645 // variables. The alternative would have been to look for a proxy | 1646 // variables. The alternative would have been to look for a proxy |
| 1646 // whereever we can find one. | 1647 // whereever we can find one. |
| 1647 got_config = true; | 1648 got_config = true; |
| 1648 | 1649 |
| 1649 // Keep a copy of the config for use from this thread for | 1650 // Keep a copy of the config for use from this thread for |
| 1650 // comparison with updated settings when we get notifications. | 1651 // comparison with updated settings when we get notifications. |
| 1651 reference_config_ = cached_config_; | 1652 reference_config_ = cached_config_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1671 } | 1672 } |
| 1672 } | 1673 } |
| 1673 } | 1674 } |
| 1674 | 1675 |
| 1675 if (!got_config) { | 1676 if (!got_config) { |
| 1676 // We fall back on environment variables. | 1677 // We fall back on environment variables. |
| 1677 // | 1678 // |
| 1678 // Consulting environment variables doesn't need to be done from the | 1679 // Consulting environment variables doesn't need to be done from the |
| 1679 // default glib main loop, but it's a tiny enough amount of work. | 1680 // default glib main loop, but it's a tiny enough amount of work. |
| 1680 if (GetConfigFromEnv(&cached_config_)) { | 1681 if (GetConfigFromEnv(&cached_config_)) { |
| 1682 cached_config_.set_source(PROXY_CONFIG_SOURCE_ENV); |
| 1681 cached_config_.set_id(1); // Mark it as valid. | 1683 cached_config_.set_id(1); // Mark it as valid. |
| 1682 VLOG(1) << "Obtained proxy settings from environment variables"; | 1684 VLOG(1) << "Obtained proxy settings from environment variables"; |
| 1683 } | 1685 } |
| 1684 } | 1686 } |
| 1685 } | 1687 } |
| 1686 | 1688 |
| 1687 // Depending on the SettingGetter in use, this method will be called | 1689 // Depending on the SettingGetter in use, this method will be called |
| 1688 // on either the UI thread (GConf) or the file thread (KDE). | 1690 // on either the UI thread (GConf) or the file thread (KDE). |
| 1689 void ProxyConfigServiceLinux::Delegate::SetUpNotifications() { | 1691 void ProxyConfigServiceLinux::Delegate::SetUpNotifications() { |
| 1690 scoped_refptr<base::MessageLoopProxy> required_loop = | 1692 scoped_refptr<base::MessageLoopProxy> required_loop = |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1805 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1807 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
| 1806 delegate_->RemoveObserver(observer); | 1808 delegate_->RemoveObserver(observer); |
| 1807 } | 1809 } |
| 1808 | 1810 |
| 1809 ProxyConfigService::ConfigAvailability | 1811 ProxyConfigService::ConfigAvailability |
| 1810 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1812 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
| 1811 return delegate_->GetLatestProxyConfig(config); | 1813 return delegate_->GetLatestProxyConfig(config); |
| 1812 } | 1814 } |
| 1813 | 1815 |
| 1814 } // namespace net | 1816 } // namespace net |
| OLD | NEW |