| 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::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { | 319 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { |
| 320 return task_runner_; | 320 return task_runner_; |
| 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 G_CALLBACK(OnGSettingsChangeNotification), this); | 630 G_CALLBACK(OnGSettingsChangeNotification), this); |
| 631 // Simulate a change to avoid possibly losing updates before this point. | 631 // Simulate a change to avoid possibly losing updates before this point. |
| 632 OnChangeNotification(); | 632 OnChangeNotification(); |
| 633 return true; | 633 return true; |
| 634 } | 634 } |
| 635 | 635 |
| 636 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { | 636 virtual base::SingleThreadTaskRunner* GetNotificationTaskRunner() OVERRIDE { |
| 637 return task_runner_; | 637 return task_runner_; |
| 638 } | 638 } |
| 639 | 639 |
| 640 virtual const char* GetDataSource() OVERRIDE { | 640 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
| 641 return "gsettings"; | 641 return PROXY_CONFIG_SOURCE_GSETTINGS; |
| 642 } | 642 } |
| 643 | 643 |
| 644 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 644 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
| 645 DCHECK(client_); | 645 DCHECK(client_); |
| 646 switch (key) { | 646 switch (key) { |
| 647 case PROXY_MODE: | 647 case PROXY_MODE: |
| 648 return GetStringByPath(client_, "mode", result); | 648 return GetStringByPath(client_, "mode", result); |
| 649 case PROXY_AUTOCONF_URL: | 649 case PROXY_AUTOCONF_URL: |
| 650 return GetStringByPath(client_, "autoconfig-url", result); | 650 return GetStringByPath(client_, "autoconfig-url", result); |
| 651 case PROXY_HTTP_HOST: | 651 case PROXY_HTTP_HOST: |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1038 // Implement base::MessagePumpLibevent::Watcher. | 1038 // Implement base::MessagePumpLibevent::Watcher. |
| 1039 void OnFileCanReadWithoutBlocking(int fd) { | 1039 void OnFileCanReadWithoutBlocking(int fd) { |
| 1040 DCHECK_EQ(fd, inotify_fd_); | 1040 DCHECK_EQ(fd, inotify_fd_); |
| 1041 DCHECK(MessageLoop::current() == file_loop_); | 1041 DCHECK(MessageLoop::current() == file_loop_); |
| 1042 OnChangeNotification(); | 1042 OnChangeNotification(); |
| 1043 } | 1043 } |
| 1044 void OnFileCanWriteWithoutBlocking(int fd) { | 1044 void OnFileCanWriteWithoutBlocking(int fd) { |
| 1045 NOTREACHED(); | 1045 NOTREACHED(); |
| 1046 } | 1046 } |
| 1047 | 1047 |
| 1048 virtual const char* GetDataSource() OVERRIDE { | 1048 virtual ProxyConfigSource GetConfigSource() OVERRIDE { |
| 1049 return "KDE"; | 1049 return PROXY_CONFIG_SOURCE_KDE; |
| 1050 } | 1050 } |
| 1051 | 1051 |
| 1052 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { | 1052 virtual bool GetString(StringSetting key, std::string* result) OVERRIDE { |
| 1053 string_map_type::iterator it = string_table_.find(key); | 1053 string_map_type::iterator it = string_table_.find(key); |
| 1054 if (it == string_table_.end()) | 1054 if (it == string_table_.end()) |
| 1055 return false; | 1055 return false; |
| 1056 *result = it->second; | 1056 *result = it->second; |
| 1057 return true; | 1057 return true; |
| 1058 } | 1058 } |
| 1059 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { | 1059 virtual bool GetBool(BoolSetting key, bool* result) OVERRIDE { |
| (...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1627 // and only fall back to gconf if env vars were unset. But | 1627 // and only fall back to gconf if env vars were unset. But |
| 1628 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it | 1628 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it |
| 1629 // does so even if the proxy mode is set to auto, which would | 1629 // does so even if the proxy mode is set to auto, which would |
| 1630 // mislead us. | 1630 // mislead us. |
| 1631 | 1631 |
| 1632 bool got_config = false; | 1632 bool got_config = false; |
| 1633 if (setting_getter_.get() && | 1633 if (setting_getter_.get() && |
| 1634 setting_getter_->Init(glib_thread_task_runner, file_loop) && | 1634 setting_getter_->Init(glib_thread_task_runner, file_loop) && |
| 1635 GetConfigFromSettings(&cached_config_)) { | 1635 GetConfigFromSettings(&cached_config_)) { |
| 1636 cached_config_.set_id(1); // Mark it as valid. | 1636 cached_config_.set_id(1); // Mark it as valid. |
| 1637 cached_config_.set_source(setting_getter_->GetConfigSource()); |
| 1637 VLOG(1) << "Obtained proxy settings from " | 1638 VLOG(1) << "Obtained proxy settings from " |
| 1638 << setting_getter_->GetDataSource(); | 1639 << ProxyConfigSourceToString(cached_config_.source()); |
| 1639 | 1640 |
| 1640 // If gconf proxy mode is "none", meaning direct, then we take | 1641 // If gconf proxy mode is "none", meaning direct, then we take |
| 1641 // that to be a valid config and will not check environment | 1642 // that to be a valid config and will not check environment |
| 1642 // variables. The alternative would have been to look for a proxy | 1643 // variables. The alternative would have been to look for a proxy |
| 1643 // whereever we can find one. | 1644 // whereever we can find one. |
| 1644 got_config = true; | 1645 got_config = true; |
| 1645 | 1646 |
| 1646 // Keep a copy of the config for use from this thread for | 1647 // Keep a copy of the config for use from this thread for |
| 1647 // comparison with updated settings when we get notifications. | 1648 // comparison with updated settings when we get notifications. |
| 1648 reference_config_ = cached_config_; | 1649 reference_config_ = cached_config_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1668 } | 1669 } |
| 1669 } | 1670 } |
| 1670 } | 1671 } |
| 1671 | 1672 |
| 1672 if (!got_config) { | 1673 if (!got_config) { |
| 1673 // We fall back on environment variables. | 1674 // We fall back on environment variables. |
| 1674 // | 1675 // |
| 1675 // Consulting environment variables doesn't need to be done from the | 1676 // Consulting environment variables doesn't need to be done from the |
| 1676 // default glib main loop, but it's a tiny enough amount of work. | 1677 // default glib main loop, but it's a tiny enough amount of work. |
| 1677 if (GetConfigFromEnv(&cached_config_)) { | 1678 if (GetConfigFromEnv(&cached_config_)) { |
| 1679 cached_config_.set_source(PROXY_CONFIG_SOURCE_ENV); |
| 1678 cached_config_.set_id(1); // Mark it as valid. | 1680 cached_config_.set_id(1); // Mark it as valid. |
| 1679 VLOG(1) << "Obtained proxy settings from environment variables"; | 1681 VLOG(1) << "Obtained proxy settings from environment variables"; |
| 1680 } | 1682 } |
| 1681 } | 1683 } |
| 1682 } | 1684 } |
| 1683 | 1685 |
| 1684 // Depending on the SettingGetter in use, this method will be called | 1686 // Depending on the SettingGetter in use, this method will be called |
| 1685 // on either the UI thread (GConf) or the file thread (KDE). | 1687 // on either the UI thread (GConf) or the file thread (KDE). |
| 1686 void ProxyConfigServiceLinux::Delegate::SetUpNotifications() { | 1688 void ProxyConfigServiceLinux::Delegate::SetUpNotifications() { |
| 1687 scoped_refptr<base::SingleThreadTaskRunner> required_loop = | 1689 scoped_refptr<base::SingleThreadTaskRunner> required_loop = |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1701 | 1703 |
| 1702 ProxyConfigService::ConfigAvailability | 1704 ProxyConfigService::ConfigAvailability |
| 1703 ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig( | 1705 ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig( |
| 1704 ProxyConfig* config) { | 1706 ProxyConfig* config) { |
| 1705 // This is called from the IO thread. | 1707 // This is called from the IO thread. |
| 1706 DCHECK(!io_thread_task_runner_ || | 1708 DCHECK(!io_thread_task_runner_ || |
| 1707 io_thread_task_runner_->BelongsToCurrentThread()); | 1709 io_thread_task_runner_->BelongsToCurrentThread()); |
| 1708 | 1710 |
| 1709 // Simply return the last proxy configuration that glib_default_loop | 1711 // Simply return the last proxy configuration that glib_default_loop |
| 1710 // notified us of. | 1712 // notified us of. |
| 1711 *config = cached_config_.is_valid() ? | 1713 if (cached_config_.is_valid()) { |
| 1712 cached_config_ : ProxyConfig::CreateDirect(); | 1714 *config = cached_config_; |
| 1715 } else { |
| 1716 *config = ProxyConfig::CreateDirect(); |
| 1717 config->set_source(PROXY_CONFIG_SOURCE_SYSTEM_FAILED); |
| 1718 } |
| 1713 | 1719 |
| 1714 // We return CONFIG_VALID to indicate that *config was filled in. It is always | 1720 // We return CONFIG_VALID to indicate that *config was filled in. It is always |
| 1715 // going to be available since we initialized eagerly on the UI thread. | 1721 // going to be available since we initialized eagerly on the UI thread. |
| 1716 // TODO(eroman): do lazy initialization instead, so we no longer need | 1722 // TODO(eroman): do lazy initialization instead, so we no longer need |
| 1717 // to construct ProxyConfigServiceLinux on the UI thread. | 1723 // to construct ProxyConfigServiceLinux on the UI thread. |
| 1718 // In which case, we may return false here. | 1724 // In which case, we may return false here. |
| 1719 return CONFIG_VALID; | 1725 return CONFIG_VALID; |
| 1720 } | 1726 } |
| 1721 | 1727 |
| 1722 // Depending on the SettingGetter in use, this method will be called | 1728 // Depending on the SettingGetter in use, this method will be called |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1803 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { | 1809 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { |
| 1804 delegate_->RemoveObserver(observer); | 1810 delegate_->RemoveObserver(observer); |
| 1805 } | 1811 } |
| 1806 | 1812 |
| 1807 ProxyConfigService::ConfigAvailability | 1813 ProxyConfigService::ConfigAvailability |
| 1808 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { | 1814 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { |
| 1809 return delegate_->GetLatestProxyConfig(config); | 1815 return delegate_->GetLatestProxyConfig(config); |
| 1810 } | 1816 } |
| 1811 | 1817 |
| 1812 } // namespace net | 1818 } // namespace net |
| OLD | NEW |