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

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 Eric's comments. Created 9 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) 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 1117 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 *config = cached_config_.is_valid() ?
1177 cached_config_ : ProxyConfig::CreateDirect(); 1178 cached_config_ : ProxyConfig::CreateDirect();
1178 1179
1179 // We return true to indicate that *config was filled in. It is always 1180 // We return CONFIG_VALID to indicate that *config was filled in. It is always
1180 // going to be available since we initialized eagerly on the UI thread. 1181 // going to be available since we initialized eagerly on the UI thread.
1181 // TODO(eroman): do lazy initialization instead, so we no longer need 1182 // TODO(eroman): do lazy initialization instead, so we no longer need
1182 // to construct ProxyConfigServiceLinux on the UI thread. 1183 // to construct ProxyConfigServiceLinux on the UI thread.
1183 // In which case, we may return false here. 1184 // In which case, we may return false here.
1184 return true; 1185 return CONFIG_VALID;
1185 } 1186 }
1186 1187
1187 // Depending on the GConfSettingGetter in use, this method will be called 1188 // Depending on the GConfSettingGetter in use, this method will be called
1188 // on either the UI thread (GConf) or the file thread (KDE). 1189 // on either the UI thread (GConf) or the file thread (KDE).
1189 void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() { 1190 void ProxyConfigServiceLinux::Delegate::OnCheckProxyConfigSettings() {
1190 MessageLoop* required_loop = gconf_getter_->GetNotificationLoop(); 1191 MessageLoop* required_loop = gconf_getter_->GetNotificationLoop();
1191 DCHECK(!required_loop || MessageLoop::current() == required_loop); 1192 DCHECK(!required_loop || MessageLoop::current() == required_loop);
1192 ProxyConfig new_config; 1193 ProxyConfig new_config;
1193 bool valid = GetConfigFromGConf(&new_config); 1194 bool valid = GetConfigFromGConf(&new_config);
1194 if (valid) 1195 if (valid)
(...skipping 13 matching lines...) Expand all
1208 // Update the thread-private copy in |reference_config_| as well. 1209 // Update the thread-private copy in |reference_config_| as well.
1209 reference_config_ = new_config; 1210 reference_config_ = new_config;
1210 } 1211 }
1211 } 1212 }
1212 1213
1213 void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig( 1214 void ProxyConfigServiceLinux::Delegate::SetNewProxyConfig(
1214 const ProxyConfig& new_config) { 1215 const ProxyConfig& new_config) {
1215 DCHECK(MessageLoop::current() == io_loop_); 1216 DCHECK(MessageLoop::current() == io_loop_);
1216 VLOG(1) << "Proxy configuration changed"; 1217 VLOG(1) << "Proxy configuration changed";
1217 cached_config_ = new_config; 1218 cached_config_ = new_config;
1218 FOR_EACH_OBSERVER(Observer, observers_, OnProxyConfigChanged(new_config)); 1219 FOR_EACH_OBSERVER(
1220 Observer, observers_,
1221 OnProxyConfigChanged(new_config, ProxyConfigService::CONFIG_VALID));
1219 } 1222 }
1220 1223
1221 void ProxyConfigServiceLinux::Delegate::PostDestroyTask() { 1224 void ProxyConfigServiceLinux::Delegate::PostDestroyTask() {
1222 if (!gconf_getter_.get()) 1225 if (!gconf_getter_.get())
1223 return; 1226 return;
1224 MessageLoop* shutdown_loop = gconf_getter_->GetNotificationLoop(); 1227 MessageLoop* shutdown_loop = gconf_getter_->GetNotificationLoop();
1225 if (!shutdown_loop || MessageLoop::current() == shutdown_loop) { 1228 if (!shutdown_loop || MessageLoop::current() == shutdown_loop) {
1226 // Already on the right thread, call directly. 1229 // Already on the right thread, call directly.
1227 // This is the case for the unittests. 1230 // This is the case for the unittests.
1228 OnDestroy(); 1231 OnDestroy();
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 } 1265 }
1263 1266
1264 void ProxyConfigServiceLinux::AddObserver(Observer* observer) { 1267 void ProxyConfigServiceLinux::AddObserver(Observer* observer) {
1265 delegate_->AddObserver(observer); 1268 delegate_->AddObserver(observer);
1266 } 1269 }
1267 1270
1268 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) { 1271 void ProxyConfigServiceLinux::RemoveObserver(Observer* observer) {
1269 delegate_->RemoveObserver(observer); 1272 delegate_->RemoveObserver(observer);
1270 } 1273 }
1271 1274
1272 bool ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) { 1275 ProxyConfigService::ConfigAvailability
1276 ProxyConfigServiceLinux::GetLatestProxyConfig(ProxyConfig* config) {
1273 return delegate_->GetLatestProxyConfig(config); 1277 return delegate_->GetLatestProxyConfig(config);
1274 } 1278 }
1275 1279
1276 } // namespace net 1280 } // 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