Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: net/proxy/proxy_config_service_linux.cc

Issue 3029062: base: rename Environment::GetEnv to Environment::GetVar. (Closed) Base URL: git://git.chromium.org/chromium.git
Patch Set: Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « courgette/encoded_program.cc ('k') | net/proxy/proxy_config_service_linux_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #include <gconf/gconf-client.h> 9 #include <gconf/gconf-client.h>
10 #include <limits.h> 10 #include <limits.h>
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 host.resize(host.length() - 1); 76 host.resize(host.length() - 1);
77 return host; 77 return host;
78 } 78 }
79 79
80 } // namespace 80 } // namespace
81 81
82 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme( 82 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme(
83 const char* variable, ProxyServer::Scheme scheme, 83 const char* variable, ProxyServer::Scheme scheme,
84 ProxyServer* result_server) { 84 ProxyServer* result_server) {
85 std::string env_value; 85 std::string env_value;
86 if (env_var_getter_->GetEnv(variable, &env_value)) { 86 if (env_var_getter_->GetVar(variable, &env_value)) {
87 if (!env_value.empty()) { 87 if (!env_value.empty()) {
88 env_value = FixupProxyHostScheme(scheme, env_value); 88 env_value = FixupProxyHostScheme(scheme, env_value);
89 ProxyServer proxy_server = 89 ProxyServer proxy_server =
90 ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP); 90 ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP);
91 if (proxy_server.is_valid() && !proxy_server.is_direct()) { 91 if (proxy_server.is_valid() && !proxy_server.is_direct()) {
92 *result_server = proxy_server; 92 *result_server = proxy_server;
93 return true; 93 return true;
94 } else { 94 } else {
95 LOG(ERROR) << "Failed to parse environment variable " << variable; 95 LOG(ERROR) << "Failed to parse environment variable " << variable;
96 } 96 }
97 } 97 }
98 } 98 }
99 return false; 99 return false;
100 } 100 }
101 101
102 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar( 102 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar(
103 const char* variable, ProxyServer* result_server) { 103 const char* variable, ProxyServer* result_server) {
104 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP, 104 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP,
105 result_server); 105 result_server);
106 } 106 }
107 107
108 bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) { 108 bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) {
109 // Check for automatic configuration first, in 109 // Check for automatic configuration first, in
110 // "auto_proxy". Possibly only the "environment_proxy" firefox 110 // "auto_proxy". Possibly only the "environment_proxy" firefox
111 // extension has ever used this, but it still sounds like a good 111 // extension has ever used this, but it still sounds like a good
112 // idea. 112 // idea.
113 std::string auto_proxy; 113 std::string auto_proxy;
114 if (env_var_getter_->GetEnv("auto_proxy", &auto_proxy)) { 114 if (env_var_getter_->GetVar("auto_proxy", &auto_proxy)) {
115 if (auto_proxy.empty()) { 115 if (auto_proxy.empty()) {
116 // Defined and empty => autodetect 116 // Defined and empty => autodetect
117 config->set_auto_detect(true); 117 config->set_auto_detect(true);
118 } else { 118 } else {
119 // specified autoconfig URL 119 // specified autoconfig URL
120 config->set_pac_url(GURL(auto_proxy)); 120 config->set_pac_url(GURL(auto_proxy));
121 } 121 }
122 return true; 122 return true;
123 } 123 }
124 // "all_proxy" is a shortcut to avoid defining {http,https,ftp}_proxy. 124 // "all_proxy" is a shortcut to avoid defining {http,https,ftp}_proxy.
(...skipping 19 matching lines...) Expand all
144 if (have_http || have_https || have_ftp) { 144 if (have_http || have_https || have_ftp) {
145 // mustn't change type unless some rules are actually set. 145 // mustn't change type unless some rules are actually set.
146 config->proxy_rules().type = 146 config->proxy_rules().type =
147 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; 147 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
148 } 148 }
149 } 149 }
150 if (config->proxy_rules().empty()) { 150 if (config->proxy_rules().empty()) {
151 // If the above were not defined, try for socks. 151 // If the above were not defined, try for socks.
152 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS4; 152 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS4;
153 std::string env_version; 153 std::string env_version;
154 if (env_var_getter_->GetEnv("SOCKS_VERSION", &env_version) 154 if (env_var_getter_->GetVar("SOCKS_VERSION", &env_version)
155 && env_version == "5") 155 && env_version == "5")
156 scheme = ProxyServer::SCHEME_SOCKS5; 156 scheme = ProxyServer::SCHEME_SOCKS5;
157 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) { 157 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) {
158 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; 158 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
159 config->proxy_rules().single_proxy = proxy_server; 159 config->proxy_rules().single_proxy = proxy_server;
160 } 160 }
161 } 161 }
162 // Look for the proxy bypass list. 162 // Look for the proxy bypass list.
163 std::string no_proxy; 163 std::string no_proxy;
164 env_var_getter_->GetEnv("no_proxy", &no_proxy); 164 env_var_getter_->GetVar("no_proxy", &no_proxy);
165 if (config->proxy_rules().empty()) { 165 if (config->proxy_rules().empty()) {
166 // Having only "no_proxy" set, presumably to "*", makes it 166 // Having only "no_proxy" set, presumably to "*", makes it
167 // explicit that env vars do specify a configuration: having no 167 // explicit that env vars do specify a configuration: having no
168 // rules specified only means the user explicitly asks for direct 168 // rules specified only means the user explicitly asks for direct
169 // connections. 169 // connections.
170 return !no_proxy.empty(); 170 return !no_proxy.empty();
171 } 171 }
172 // Note that this uses "suffix" matching. So a bypass of "google.com" 172 // Note that this uses "suffix" matching. So a bypass of "google.com"
173 // is understood to mean a bypass of "*google.com". 173 // is understood to mean a bypass of "*google.com".
174 config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching( 174 config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching(
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 class GConfSettingGetterImplKDE 421 class GConfSettingGetterImplKDE
422 : public ProxyConfigServiceLinux::GConfSettingGetter, 422 : public ProxyConfigServiceLinux::GConfSettingGetter,
423 public base::MessagePumpLibevent::Watcher { 423 public base::MessagePumpLibevent::Watcher {
424 public: 424 public:
425 explicit GConfSettingGetterImplKDE(base::Environment* env_var_getter) 425 explicit GConfSettingGetterImplKDE(base::Environment* env_var_getter)
426 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), 426 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false),
427 auto_no_pac_(false), reversed_bypass_list_(false), 427 auto_no_pac_(false), reversed_bypass_list_(false),
428 env_var_getter_(env_var_getter), file_loop_(NULL) { 428 env_var_getter_(env_var_getter), file_loop_(NULL) {
429 // Derive the location of the kde config dir from the environment. 429 // Derive the location of the kde config dir from the environment.
430 std::string home; 430 std::string home;
431 if (env_var_getter->GetEnv("KDEHOME", &home) && !home.empty()) { 431 if (env_var_getter->GetVar("KDEHOME", &home) && !home.empty()) {
432 // $KDEHOME is set. Use it unconditionally. 432 // $KDEHOME is set. Use it unconditionally.
433 kde_config_dir_ = KDEHomeToConfigPath(FilePath(home)); 433 kde_config_dir_ = KDEHomeToConfigPath(FilePath(home));
434 } else { 434 } else {
435 // $KDEHOME is unset. Try to figure out what to use. This seems to be 435 // $KDEHOME is unset. Try to figure out what to use. This seems to be
436 // the common case on most distributions. 436 // the common case on most distributions.
437 if (!env_var_getter->GetEnv(base::env_vars::kHome, &home)) 437 if (!env_var_getter->GetVar(base::env_vars::kHome, &home))
438 // User has no $HOME? Give up. Later we'll report the failure. 438 // User has no $HOME? Give up. Later we'll report the failure.
439 return; 439 return;
440 if (base::GetDesktopEnvironment(env_var_getter) == 440 if (base::GetDesktopEnvironment(env_var_getter) ==
441 base::DESKTOP_ENVIRONMENT_KDE3) { 441 base::DESKTOP_ENVIRONMENT_KDE3) {
442 // KDE3 always uses .kde for its configuration. 442 // KDE3 always uses .kde for its configuration.
443 FilePath kde_path = FilePath(home).Append(".kde"); 443 FilePath kde_path = FilePath(home).Append(".kde");
444 kde_config_dir_ = KDEHomeToConfigPath(kde_path); 444 kde_config_dir_ = KDEHomeToConfigPath(kde_path);
445 } else { 445 } else {
446 // Some distributions patch KDE4 to use .kde4 instead of .kde, so that 446 // Some distributions patch KDE4 to use .kde4 instead of .kde, so that
447 // both can be installed side-by-side. Sadly they don't all do this, and 447 // both can be installed side-by-side. Sadly they don't all do this, and
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
681 LOG(WARNING) << 681 LOG(WARNING) <<
682 "Proxy authentication parameters ignored, see bug 16709"; 682 "Proxy authentication parameters ignored, see bug 16709";
683 } 683 }
684 } 684 }
685 } 685 }
686 686
687 void ResolveIndirect(const std::string& key) { 687 void ResolveIndirect(const std::string& key) {
688 string_map_type::iterator it = string_table_.find(key); 688 string_map_type::iterator it = string_table_.find(key);
689 if (it != string_table_.end()) { 689 if (it != string_table_.end()) {
690 std::string value; 690 std::string value;
691 if (env_var_getter_->GetEnv(it->second.c_str(), &value)) 691 if (env_var_getter_->GetVar(it->second.c_str(), &value))
692 it->second = value; 692 it->second = value;
693 else 693 else
694 string_table_.erase(it); 694 string_table_.erase(it);
695 } 695 }
696 } 696 }
697 697
698 void ResolveIndirectList(const std::string& key) { 698 void ResolveIndirectList(const std::string& key) {
699 strings_map_type::iterator it = strings_table_.find(key); 699 strings_map_type::iterator it = strings_table_.find(key);
700 if (it != strings_table_.end()) { 700 if (it != strings_table_.end()) {
701 std::string value; 701 std::string value;
702 if (!it->second.empty() && 702 if (!it->second.empty() &&
703 env_var_getter_->GetEnv(it->second[0].c_str(), &value)) 703 env_var_getter_->GetVar(it->second[0].c_str(), &value))
704 AddHostList(key, value); 704 AddHostList(key, value);
705 else 705 else
706 strings_table_.erase(it); 706 strings_table_.erase(it);
707 } 707 }
708 } 708 }
709 709
710 // The settings in kioslaverc could occur in any order, but some affect 710 // The settings in kioslaverc could occur in any order, but some affect
711 // others. Rather than read the whole file in and then query them in an 711 // others. Rather than read the whole file in and then query them in an
712 // order that allows us to handle that, we read the settings in whatever 712 // order that allows us to handle that, we read the settings in whatever
713 // order they occur and do any necessary tweaking after we finish. 713 // order they occur and do any necessary tweaking after we finish.
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1232 : delegate_(new Delegate(env_var_getter)) { 1232 : delegate_(new Delegate(env_var_getter)) {
1233 } 1233 }
1234 1234
1235 ProxyConfigServiceLinux::ProxyConfigServiceLinux( 1235 ProxyConfigServiceLinux::ProxyConfigServiceLinux(
1236 base::Environment* env_var_getter, 1236 base::Environment* env_var_getter,
1237 GConfSettingGetter* gconf_getter) 1237 GConfSettingGetter* gconf_getter)
1238 : delegate_(new Delegate(env_var_getter, gconf_getter)) { 1238 : delegate_(new Delegate(env_var_getter, gconf_getter)) {
1239 } 1239 }
1240 1240
1241 } // namespace net 1241 } // namespace net
OLDNEW
« no previous file with comments | « courgette/encoded_program.cc ('k') | net/proxy/proxy_config_service_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698