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

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

Issue 6597070: Allow ProxyConfigService to report "no configuration set" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comment Created 9 years, 9 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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>
11 #endif 11 #endif
12 #include <limits.h> 12 #include <limits.h>
13 #include <stdio.h> 13 #include <stdio.h>
14 #include <stdlib.h> 14 #include <stdlib.h>
15 #include <sys/inotify.h> 15 #include <sys/inotify.h>
16 #include <unistd.h> 16 #include <unistd.h>
17 17
18 #include <map> 18 #include <map>
19 19
20 #include "base/environment.h" 20 #include "base/environment.h"
21 #include "base/file_path.h" 21 #include "base/file_path.h"
22 #include "base/file_util.h" 22 #include "base/file_util.h"
23 #include "base/logging.h" 23 #include "base/logging.h"
24 #include "base/message_loop.h" 24 #include "base/message_loop.h"
25 #include "base/nix/xdg_util.h"
25 #include "base/string_number_conversions.h" 26 #include "base/string_number_conversions.h"
26 #include "base/string_tokenizer.h" 27 #include "base/string_tokenizer.h"
27 #include "base/string_util.h" 28 #include "base/string_util.h"
28 #include "base/task.h" 29 #include "base/task.h"
29 #include "base/threading/thread_restrictions.h" 30 #include "base/threading/thread_restrictions.h"
30 #include "base/timer.h" 31 #include "base/timer.h"
31 #include "base/nix/xdg_util.h"
32 #include "googleurl/src/url_canon.h" 32 #include "googleurl/src/url_canon.h"
33 #include "net/base/net_errors.h" 33 #include "net/base/net_errors.h"
34 #include "net/http/http_util.h" 34 #include "net/http/http_util.h"
35 #include "net/proxy/proxy_config.h" 35 #include "net/proxy/proxy_config.h"
36 #include "net/proxy/proxy_server.h" 36 #include "net/proxy/proxy_server.h"
37 37
38 namespace net { 38 namespace net {
39 39
40 namespace { 40 namespace {
41 41
(...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 return true; 952 return true;
953 } 953 }
954 954
955 if (mode == "auto") { 955 if (mode == "auto") {
956 // automatic proxy config 956 // automatic proxy config
957 std::string pac_url_str; 957 std::string pac_url_str;
958 if (gconf_getter_->GetString("/system/proxy/autoconfig_url", 958 if (gconf_getter_->GetString("/system/proxy/autoconfig_url",
959 &pac_url_str)) { 959 &pac_url_str)) {
960 if (!pac_url_str.empty()) { 960 if (!pac_url_str.empty()) {
961 GURL pac_url(pac_url_str); 961 GURL pac_url(pac_url_str);
962 if (!pac_url.is_valid()) 962 if (pac_url.is_valid()) {
963 return false; 963 config->set_pac_url(pac_url);
eroman 2011/03/16 01:30:00 This seems like it will change the behavior (befor
Mattias Nissler (ping if slow) 2011/03/16 17:40:00 I agree it's not a good idea to change behavior of
eroman 2011/03/26 00:50:30 I still see this change in the latest patchset...
964 config->set_pac_url(pac_url); 964 return true;
965 return true; 965 }
966 } 966 }
967 } 967 }
968 config->set_auto_detect(true); 968 config->set_auto_detect(true);
969 return true; 969 return true;
970 } 970 }
971 971
972 if (mode != "manual") { 972 if (mode != "manual") {
973 // Mode is unrecognized. 973 // Mode is unrecognized.
974 return false; 974 return false;
975 } 975 }
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1103 glib_default_loop_ = glib_default_loop; 1103 glib_default_loop_ = glib_default_loop;
1104 io_loop_ = io_loop; 1104 io_loop_ = io_loop;
1105 1105
1106 // If we are passed a NULL io_loop or file_loop, then we don't set up 1106 // If we are passed a NULL io_loop or file_loop, then we don't set up
1107 // proxy setting change notifications. This should not be the usual 1107 // proxy setting change notifications. This should not be the usual
1108 // case but is intended to simplify test setups. 1108 // case but is intended to simplify test setups.
1109 if (!io_loop_ || !file_loop) 1109 if (!io_loop_ || !file_loop)
1110 VLOG(1) << "Monitoring of proxy setting changes is disabled"; 1110 VLOG(1) << "Monitoring of proxy setting changes is disabled";
1111 1111
1112 // Fetch and cache the current proxy config. The config is left in 1112 // Fetch and cache the current proxy config. The config is left in
1113 // cached_config_, where GetLatestProxyConfig() running on the IO thread 1113 // cached_config_, where GetLastestProxyConfig() running on the IO thread
eroman 2011/03/16 01:30:00 typo: please restore earlier version.
Mattias Nissler (ping if slow) 2011/03/16 17:40:00 Done.
eroman 2011/03/26 00:50:30 I don't see this change int he latest patchset...
1114 // will expect to find it. This is safe to do because we return 1114 // will expect to find it. This is safe to do because we return
1115 // before this ProxyConfigServiceLinux is passed on to 1115 // before this ProxyConfigServiceLinux is passed on to
1116 // the ProxyService. 1116 // the ProxyService.
1117 1117
1118 // Note: It would be nice to prioritize environment variables 1118 // Note: It would be nice to prioritize environment variables
1119 // and only fall back to gconf if env vars were unset. But 1119 // and only fall back to gconf if env vars were unset. But
1120 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it 1120 // gnome-terminal "helpfully" sets http_proxy and no_proxy, and it
1121 // does so even if the proxy mode is set to auto, which would 1121 // does so even if the proxy mode is set to auto, which would
1122 // mislead us. 1122 // mislead us.
1123 1123
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 } 1159 }
1160 1160
1161 void ProxyConfigServiceLinux::Delegate::AddObserver(Observer* observer) { 1161 void ProxyConfigServiceLinux::Delegate::AddObserver(Observer* observer) {
1162 observers_.AddObserver(observer); 1162 observers_.AddObserver(observer);
1163 } 1163 }
1164 1164
1165 void ProxyConfigServiceLinux::Delegate::RemoveObserver(Observer* observer) { 1165 void ProxyConfigServiceLinux::Delegate::RemoveObserver(Observer* observer) {
1166 observers_.RemoveObserver(observer); 1166 observers_.RemoveObserver(observer);
1167 } 1167 }
1168 1168
1169 bool ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig( 1169 ProxyConfigService::ConfigAvailability
1170 ProxyConfig* config) { 1170 ProxyConfigServiceLinux::Delegate::GetLatestProxyConfig(
1171 ProxyConfig* config) {
1171 // This is called from the IO thread. 1172 // This is called from the IO thread.
1172 DCHECK(!io_loop_ || MessageLoop::current() == io_loop_); 1173 DCHECK(!io_loop_ || MessageLoop::current() == io_loop_);
1173 1174
1174 // Simply return the last proxy configuration that glib_default_loop 1175 // Simply return the last proxy configuration that glib_default_loop
1175 // notified us of. 1176 // notified us of.
1176 *config = cached_config_.is_valid() ? 1177 if (cached_config_.is_valid()) {
1177 cached_config_ : ProxyConfig::CreateDirect(); 1178 *config = cached_config_;
1179 return CONFIG_VALID;
1180 }
1178 1181
1179 // We return true to indicate that *config was filled in. It is always 1182 // We return CONFIG_UNSET to indicate that the config has been read
1180 // going to be available since we initialized eagerly on the UI thread. 1183 // successfully but there was nothing configured. Since we initialize eagerly
1184 // on the UI thread, we never need to return CONFIG_PENDING.
1181 // TODO(eroman): do lazy initialization instead, so we no longer need 1185 // TODO(eroman): do lazy initialization instead, so we no longer need
1182 // to construct ProxyConfigServiceLinux on the UI thread. 1186 // to construct ProxyConfigServiceLinux on the UI thread.
1183 // In which case, we may return false here. 1187 // In which case, we may return false here.
1184 return true; 1188 return CONFIG_UNSET;
eroman 2011/03/16 01:30:00 I don't think the system config services should ev
Mattias Nissler (ping if slow) 2011/03/16 17:40:00 I did this change for consolidating the defaulting
1185 } 1189 }
1186 1190
1187 // Depending on the GConfSettingGetter in use, this method will be called 1191 // Depending on the GConfSettingGetter in use, this method will be called
1188 // on either the UI thread (GConf) or the file thread (KDE). 1192 // on either the UI thread (GConf) or the file thread (KDE).
1189 void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() { 1193 void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() {
1190 MessageLoop* required_loop = gconf_getter_->GetNotificationLoop(); 1194 MessageLoop* required_loop = gconf_getter_->GetNotificationLoop();
1191 DCHECK(!required_loop || MessageLoop::current() == required_loop); 1195 DCHECK(!required_loop || MessageLoop::current() == required_loop);
1192 ProxyConfig new_config; 1196 ProxyConfig new_config;
1193 bool valid = GetConfigFromGConf(&new_config); 1197 bool valid = GetConfigFromGConf(&new_config);
1194 if (valid) 1198 if (valid)
(...skipping 13 matching lines...) Expand all
1208 // Update the thread-private copy in |reference_config_| as well. 1212 // Update the thread-private copy in |reference_config_| as well.
1209 reference_config_ = new_config; 1213 reference_config_ = new_config;
1210 } 1214 }
1211 } 1215 }
1212 1216
1213 void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig( 1217 void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig(
1214 const ProxyConfig& new_config) { 1218 const ProxyConfig& new_config) {
1215 DCHECK(MessageLoop::current() == io_loop_); 1219 DCHECK(MessageLoop::current() == io_loop_);
1216 VLOG(1) << "Proxy configuration changed"; 1220 VLOG(1) << "Proxy configuration changed";
1217 cached_config_ = new_config; 1221 cached_config_ = new_config;
1218 FOR_EACH_OBSERVER(Observer, observers_, OnProxyConfigChanged(new_config)); 1222 FOR_EACH_OBSERVER(
1223 Observer, observers_,
1224 OnProxyConfigChanged(cached_config_,
1225 cached_config_.is_valid() ?
1226 ProxyConfigService::CONFIG_VALID :
1227 ProxyConfigService::CONFIG_UNSET));
eroman 2011/03/16 01:30:00 See earlier comment.
Mattias Nissler (ping if slow) 2011/03/16 17:40:00 Done.
1219 } 1228 }
1220 1229
1221 void ProxyConfigServiceLinux::Delegate::PostDestroyTask() { 1230 void ProxyConfigServiceLinux::Delegate::PostDestroyTask() {
1222 if (!gconf_getter_.get()) 1231 if (!gconf_getter_.get())
1223 return; 1232 return;
1224 MessageLoop* shutdown_loop = gconf_getter_->GetNotificationLoop(); 1233 MessageLoop* shutdown_loop = gconf_getter_->GetNotificationLoop();
1225 if (!shutdown_loop || MessageLoop::current() == shutdown_loop) { 1234 if (!shutdown_loop || MessageLoop::current() == shutdown_loop) {
1226 // Already on the right thread, call directly. 1235 // Already on the right thread, call directly.
1227 // This is the case for the unittests. 1236 // This is the case for the unittests.
1228 OnDestroy(); 1237 OnDestroy();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 } 1271 }
1263 1272
1264 void ProxyConfigServiceLinux::AddObserver(Observer* observer) { 1273 void ProxyConfigServiceLinux::AddObserver(Observer* observer) {
1265 delegate_->AddObserver(observer); 1274 delegate_->AddObserver(observer);
1266 } 1275 }
1267 1276
1268 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { 1277 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) {
1269 delegate_->RemoveObserver(observer); 1278 delegate_->RemoveObserver(observer);
1270 } 1279 }
1271 1280
1272 bool ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { 1281 ProxyConfigService::ConfigAvailability
1282 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) {
1273 return delegate_->GetLatestProxyConfig(config); 1283 return delegate_->GetLatestProxyConfig(config);
1274 } 1284 }
1275 1285
1276 } // namespace net 1286 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698