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

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

Issue 1606007: Move EnvironmentVariableGetter from base/linux_util.h to base/env_var.h. Labe... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fix windows build for good this time? Created 10 years, 8 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 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>
11 #include <stdio.h> 11 #include <stdio.h>
12 #include <stdlib.h> 12 #include <stdlib.h>
13 #include <sys/inotify.h> 13 #include <sys/inotify.h>
14 #include <unistd.h> 14 #include <unistd.h>
15 15
16 #include <map>
17
16 #include "base/file_path.h" 18 #include "base/file_path.h"
17 #include "base/file_util.h" 19 #include "base/file_util.h"
20 #include "base/linux_util.h"
18 #include "base/logging.h" 21 #include "base/logging.h"
19 #include "base/message_loop.h" 22 #include "base/message_loop.h"
20 #include "base/string_tokenizer.h" 23 #include "base/string_tokenizer.h"
21 #include "base/string_util.h" 24 #include "base/string_util.h"
22 #include "base/task.h" 25 #include "base/task.h"
23 #include "base/timer.h" 26 #include "base/timer.h"
24 #include "googleurl/src/url_canon.h" 27 #include "googleurl/src/url_canon.h"
25 #include "net/base/net_errors.h" 28 #include "net/base/net_errors.h"
26 #include "net/http/http_util.h" 29 #include "net/http/http_util.h"
27 #include "net/proxy/proxy_config.h" 30 #include "net/proxy/proxy_config.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 host.resize(host.length() - 1); 74 host.resize(host.length() - 1);
72 return host; 75 return host;
73 } 76 }
74 77
75 } // namespace 78 } // namespace
76 79
77 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme( 80 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVarForScheme(
78 const char* variable, ProxyServer::Scheme scheme, 81 const char* variable, ProxyServer::Scheme scheme,
79 ProxyServer* result_server) { 82 ProxyServer* result_server) {
80 std::string env_value; 83 std::string env_value;
81 if (env_var_getter_->Getenv(variable, &env_value)) { 84 if (env_var_getter_->GetEnv(variable, &env_value)) {
82 if (!env_value.empty()) { 85 if (!env_value.empty()) {
83 env_value = FixupProxyHostScheme(scheme, env_value); 86 env_value = FixupProxyHostScheme(scheme, env_value);
84 ProxyServer proxy_server = 87 ProxyServer proxy_server =
85 ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP); 88 ProxyServer::FromURI(env_value, ProxyServer::SCHEME_HTTP);
86 if (proxy_server.is_valid() && !proxy_server.is_direct()) { 89 if (proxy_server.is_valid() && !proxy_server.is_direct()) {
87 *result_server = proxy_server; 90 *result_server = proxy_server;
88 return true; 91 return true;
89 } else { 92 } else {
90 LOG(ERROR) << "Failed to parse environment variable " << variable; 93 LOG(ERROR) << "Failed to parse environment variable " << variable;
91 } 94 }
92 } 95 }
93 } 96 }
94 return false; 97 return false;
95 } 98 }
96 99
97 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar( 100 bool ProxyConfigServiceLinux::Delegate::GetProxyFromEnvVar(
98 const char* variable, ProxyServer* result_server) { 101 const char* variable, ProxyServer* result_server) {
99 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP, 102 return GetProxyFromEnvVarForScheme(variable, ProxyServer::SCHEME_HTTP,
100 result_server); 103 result_server);
101 } 104 }
102 105
103 bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) { 106 bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) {
104 // Check for automatic configuration first, in 107 // Check for automatic configuration first, in
105 // "auto_proxy". Possibly only the "environment_proxy" firefox 108 // "auto_proxy". Possibly only the "environment_proxy" firefox
106 // extension has ever used this, but it still sounds like a good 109 // extension has ever used this, but it still sounds like a good
107 // idea. 110 // idea.
108 std::string auto_proxy; 111 std::string auto_proxy;
109 if (env_var_getter_->Getenv("auto_proxy", &auto_proxy)) { 112 if (env_var_getter_->GetEnv("auto_proxy", &auto_proxy)) {
110 if (auto_proxy.empty()) { 113 if (auto_proxy.empty()) {
111 // Defined and empty => autodetect 114 // Defined and empty => autodetect
112 config->set_auto_detect(true); 115 config->set_auto_detect(true);
113 } else { 116 } else {
114 // specified autoconfig URL 117 // specified autoconfig URL
115 config->set_pac_url(GURL(auto_proxy)); 118 config->set_pac_url(GURL(auto_proxy));
116 } 119 }
117 return true; 120 return true;
118 } 121 }
119 // "all_proxy" is a shortcut to avoid defining {http,https,ftp}_proxy. 122 // "all_proxy" is a shortcut to avoid defining {http,https,ftp}_proxy.
(...skipping 19 matching lines...) Expand all
139 if (have_http || have_https || have_ftp) { 142 if (have_http || have_https || have_ftp) {
140 // mustn't change type unless some rules are actually set. 143 // mustn't change type unless some rules are actually set.
141 config->proxy_rules().type = 144 config->proxy_rules().type =
142 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; 145 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
143 } 146 }
144 } 147 }
145 if (config->proxy_rules().empty()) { 148 if (config->proxy_rules().empty()) {
146 // If the above were not defined, try for socks. 149 // If the above were not defined, try for socks.
147 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS4; 150 ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS4;
148 std::string env_version; 151 std::string env_version;
149 if (env_var_getter_->Getenv("SOCKS_VERSION", &env_version) 152 if (env_var_getter_->GetEnv("SOCKS_VERSION", &env_version)
150 && env_version == "5") 153 && env_version == "5")
151 scheme = ProxyServer::SCHEME_SOCKS5; 154 scheme = ProxyServer::SCHEME_SOCKS5;
152 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) { 155 if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) {
153 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; 156 config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
154 config->proxy_rules().single_proxy = proxy_server; 157 config->proxy_rules().single_proxy = proxy_server;
155 } 158 }
156 } 159 }
157 // Look for the proxy bypass list. 160 // Look for the proxy bypass list.
158 std::string no_proxy; 161 std::string no_proxy;
159 env_var_getter_->Getenv("no_proxy", &no_proxy); 162 env_var_getter_->GetEnv("no_proxy", &no_proxy);
160 if (config->proxy_rules().empty()) { 163 if (config->proxy_rules().empty()) {
161 // Having only "no_proxy" set, presumably to "*", makes it 164 // Having only "no_proxy" set, presumably to "*", makes it
162 // explicit that env vars do specify a configuration: having no 165 // explicit that env vars do specify a configuration: having no
163 // rules specified only means the user explicitly asks for direct 166 // rules specified only means the user explicitly asks for direct
164 // connections. 167 // connections.
165 return !no_proxy.empty(); 168 return !no_proxy.empty();
166 } 169 }
167 // Note that this uses "suffix" matching. So a bypass of "google.com" 170 // Note that this uses "suffix" matching. So a bypass of "google.com"
168 // is understood to mean a bypass of "*google.com". 171 // is understood to mean a bypass of "*google.com".
169 config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching( 172 config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching(
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 DISALLOW_COPY_AND_ASSIGN(GConfSettingGetterImplGConf); 404 DISALLOW_COPY_AND_ASSIGN(GConfSettingGetterImplGConf);
402 }; 405 };
403 406
404 // This is the KDE version that reads kioslaverc and simulates gconf. 407 // This is the KDE version that reads kioslaverc and simulates gconf.
405 // Doing this allows the main Delegate code, as well as the unit tests 408 // Doing this allows the main Delegate code, as well as the unit tests
406 // for it, to stay the same - and the settings map fairly well besides. 409 // for it, to stay the same - and the settings map fairly well besides.
407 class GConfSettingGetterImplKDE 410 class GConfSettingGetterImplKDE
408 : public ProxyConfigServiceLinux::GConfSettingGetter, 411 : public ProxyConfigServiceLinux::GConfSettingGetter,
409 public base::MessagePumpLibevent::Watcher { 412 public base::MessagePumpLibevent::Watcher {
410 public: 413 public:
411 explicit GConfSettingGetterImplKDE( 414 explicit GConfSettingGetterImplKDE(base::EnvVarGetter* env_var_getter)
412 base::EnvironmentVariableGetter* env_var_getter)
413 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false), 415 : inotify_fd_(-1), notify_delegate_(NULL), indirect_manual_(false),
414 auto_no_pac_(false), reversed_exception_(false), file_loop_(NULL) { 416 auto_no_pac_(false), reversed_exception_(false), file_loop_(NULL) {
415 // We don't save the env var getter for later use since we don't own it. 417 // We don't save the env var getter for later use since we don't own it.
416 // Instead we use it here and save the result we actually care about. 418 // Instead we use it here and save the result we actually care about.
417 std::string kde_home; 419 std::string kde_home;
418 if (!env_var_getter->Getenv("KDE_HOME", &kde_home)) { 420 if (!env_var_getter->GetEnv("KDE_HOME", &kde_home)) {
419 if (!env_var_getter->Getenv("HOME", &kde_home)) 421 if (!env_var_getter->GetEnv("HOME", &kde_home))
420 // User has no $HOME? Give up. Later we'll report the failure. 422 // User has no $HOME? Give up. Later we'll report the failure.
421 return; 423 return;
422 kde_home = FilePath(kde_home).Append(FILE_PATH_LITERAL(".kde")).value(); 424 kde_home = FilePath(kde_home).Append(FILE_PATH_LITERAL(".kde")).value();
423 } 425 }
424 kde_config_dir_ = FilePath(kde_home).Append( 426 kde_config_dir_ = FilePath(kde_home).Append(
425 FILE_PATH_LITERAL("share")).Append(FILE_PATH_LITERAL("config")); 427 FILE_PATH_LITERAL("share")).Append(FILE_PATH_LITERAL("config"));
426 } 428 }
427 429
428 virtual ~GConfSettingGetterImplKDE() { 430 virtual ~GConfSettingGetterImplKDE() {
429 // inotify_fd_ should have been closed before now, from 431 // inotify_fd_ should have been closed before now, from
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 config->proxy_rules().bypass_rules.Clear(); 956 config->proxy_rules().bypass_rules.Clear();
955 for (size_t i = 0; i < ignore_hosts_list.size(); ++i) 957 for (size_t i = 0; i < ignore_hosts_list.size(); ++i)
956 config->proxy_rules().bypass_rules.AddRuleFromString(ignore_hosts_list[i]); 958 config->proxy_rules().bypass_rules.AddRuleFromString(ignore_hosts_list[i]);
957 959
958 // Note that there are no settings with semantics corresponding to 960 // Note that there are no settings with semantics corresponding to
959 // bypass of local names. 961 // bypass of local names.
960 962
961 return true; 963 return true;
962 } 964 }
963 965
964 ProxyConfigServiceLinux::Delegate::Delegate( 966 ProxyConfigServiceLinux::Delegate::Delegate(base::EnvVarGetter* env_var_getter)
965 base::EnvironmentVariableGetter* env_var_getter)
966 : env_var_getter_(env_var_getter), 967 : env_var_getter_(env_var_getter),
967 glib_default_loop_(NULL), io_loop_(NULL) { 968 glib_default_loop_(NULL), io_loop_(NULL) {
968 // Figure out which GConfSettingGetterImpl to use, if any. 969 // Figure out which GConfSettingGetterImpl to use, if any.
969 switch (base::GetDesktopEnvironment(env_var_getter)) { 970 switch (base::GetDesktopEnvironment(env_var_getter)) {
970 case base::DESKTOP_ENVIRONMENT_GNOME: 971 case base::DESKTOP_ENVIRONMENT_GNOME:
971 gconf_getter_.reset(new GConfSettingGetterImplGConf()); 972 gconf_getter_.reset(new GConfSettingGetterImplGConf());
972 break; 973 break;
973 case base::DESKTOP_ENVIRONMENT_KDE3: 974 case base::DESKTOP_ENVIRONMENT_KDE3:
974 case base::DESKTOP_ENVIRONMENT_KDE4: 975 case base::DESKTOP_ENVIRONMENT_KDE4:
975 gconf_getter_.reset(new GConfSettingGetterImplKDE(env_var_getter)); 976 gconf_getter_.reset(new GConfSettingGetterImplKDE(env_var_getter));
976 break; 977 break;
977 case base::DESKTOP_ENVIRONMENT_XFCE: 978 case base::DESKTOP_ENVIRONMENT_XFCE:
978 case base::DESKTOP_ENVIRONMENT_OTHER: 979 case base::DESKTOP_ENVIRONMENT_OTHER:
979 break; 980 break;
980 } 981 }
981 } 982 }
982 983
983 ProxyConfigServiceLinux::Delegate::Delegate( 984 ProxyConfigServiceLinux::Delegate::Delegate(base::EnvVarGetter* env_var_getter,
984 base::EnvironmentVariableGetter* env_var_getter,
985 GConfSettingGetter* gconf_getter) 985 GConfSettingGetter* gconf_getter)
986 : env_var_getter_(env_var_getter), gconf_getter_(gconf_getter), 986 : env_var_getter_(env_var_getter), gconf_getter_(gconf_getter),
987 glib_default_loop_(NULL), io_loop_(NULL) { 987 glib_default_loop_(NULL), io_loop_(NULL) {
988 } 988 }
989 989
990 void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig( 990 void ProxyConfigServiceLinux::Delegate::SetupAndFetchInitialConfig(
991 MessageLoop* glib_default_loop, MessageLoop* io_loop, 991 MessageLoop* glib_default_loop, MessageLoop* io_loop,
992 MessageLoopForIO* file_loop) { 992 MessageLoopForIO* file_loop) {
993 // We should be running on the default glib main loop thread right 993 // We should be running on the default glib main loop thread right
994 // now. gconf can only be accessed from this thread. 994 // now. gconf can only be accessed from this thread.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 &ProxyConfigServiceLinux::Delegate::OnDestroy)); 1112 &ProxyConfigServiceLinux::Delegate::OnDestroy));
1113 } 1113 }
1114 } 1114 }
1115 void ProxyConfigServiceLinux::Delegate::OnDestroy() { 1115 void ProxyConfigServiceLinux::Delegate::OnDestroy() {
1116 MessageLoop* shutdown_loop = gconf_getter_->GetNotificationLoop(); 1116 MessageLoop* shutdown_loop = gconf_getter_->GetNotificationLoop();
1117 DCHECK(!shutdown_loop || MessageLoop::current() == shutdown_loop); 1117 DCHECK(!shutdown_loop || MessageLoop::current() == shutdown_loop);
1118 gconf_getter_->Shutdown(); 1118 gconf_getter_->Shutdown();
1119 } 1119 }
1120 1120
1121 ProxyConfigServiceLinux::ProxyConfigServiceLinux() 1121 ProxyConfigServiceLinux::ProxyConfigServiceLinux()
1122 : delegate_(new Delegate(base::EnvironmentVariableGetter::Create())) { 1122 : delegate_(new Delegate(base::EnvVarGetter::Create())) {
1123 } 1123 }
1124 1124
1125 ProxyConfigServiceLinux::ProxyConfigServiceLinux( 1125 ProxyConfigServiceLinux::ProxyConfigServiceLinux(
1126 base::EnvironmentVariableGetter* env_var_getter) 1126 base::EnvVarGetter* env_var_getter)
1127 : delegate_(new Delegate(env_var_getter)) { 1127 : delegate_(new Delegate(env_var_getter)) {
1128 } 1128 }
1129 1129
1130 ProxyConfigServiceLinux::ProxyConfigServiceLinux( 1130 ProxyConfigServiceLinux::ProxyConfigServiceLinux(
1131 base::EnvironmentVariableGetter* env_var_getter, 1131 base::EnvVarGetter* env_var_getter,
1132 GConfSettingGetter* gconf_getter) 1132 GConfSettingGetter* gconf_getter)
1133 : delegate_(new Delegate(env_var_getter, gconf_getter)) { 1133 : delegate_(new Delegate(env_var_getter, gconf_getter)) {
1134 } 1134 }
1135 1135
1136 } // namespace net 1136 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_config_service_linux.h ('k') | net/proxy/proxy_config_service_linux_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698