diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 04:05:10 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-08 04:05:10 +0000 |
commit | bd45292e5c21fcb3fef1fd5dfb8207ae29277f8a (patch) | |
tree | 1eca5cafa1a1b87a5f5182f1d7f12aaf588fc809 /net/proxy/proxy_service.cc | |
parent | 3ffe71e020ea8e3597c2835f1ba0ebb8fb85ab9e (diff) | |
download | chromium_src-bd45292e5c21fcb3fef1fd5dfb8207ae29277f8a.zip chromium_src-bd45292e5c21fcb3fef1fd5dfb8207ae29277f8a.tar.gz chromium_src-bd45292e5c21fcb3fef1fd5dfb8207ae29277f8a.tar.bz2 |
Adds a NetworkChangeNotifier dependency to ProxyService; when we observer a network change through the notifier, the ProxyService re-configures itself.
So for example, if you were to switch to VPN and are using a custom PAC URL, we will re-download that URL on the new network.
Similarly if you are using auto-detect PAC settings, we will re-run the autodiscovery steps for the next resolve.
Note that Chromium is still passing a NULL NetworkChangeNotifier dependency into its ProxyService -- until it passes a real implementation, this will not impact Chrome.
BUG=12293
TEST=ProxyServiceTest.NetworkChangeTriggersPacRefetch
Review URL: http://codereview.chromium.org/525104
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@35772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_service.cc')
-rw-r--r-- | net/proxy/proxy_service.cc | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 01a42ac..8160e64 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -198,13 +198,18 @@ class ProxyService::PacRequest // ProxyService --------------------------------------------------------------- ProxyService::ProxyService(ProxyConfigService* config_service, - ProxyResolver* resolver) + ProxyResolver* resolver, + NetworkChangeNotifier* network_change_notifier) : config_service_(config_service), resolver_(resolver), next_config_id_(1), should_use_proxy_resolver_(false), ALLOW_THIS_IN_INITIALIZER_LIST(init_proxy_resolver_callback_( - this, &ProxyService::OnInitProxyResolverComplete)) { + this, &ProxyService::OnInitProxyResolverComplete)), + network_change_notifier_(network_change_notifier) { + // Register to receive network change notifications. + if (network_change_notifier_) + network_change_notifier_->AddObserver(this); } // static @@ -212,6 +217,7 @@ ProxyService* ProxyService::Create( ProxyConfigService* proxy_config_service, bool use_v8_resolver, URLRequestContext* url_request_context, + NetworkChangeNotifier* network_change_notifier, MessageLoop* io_loop) { ProxyResolver* proxy_resolver; @@ -231,7 +237,7 @@ ProxyService* ProxyService::Create( proxy_resolver = new SingleThreadedProxyResolver(proxy_resolver); ProxyService* proxy_service = new ProxyService( - proxy_config_service, proxy_resolver); + proxy_config_service, proxy_resolver, network_change_notifier); if (proxy_resolver->expects_pac_bytes()) { // Configure PAC script downloads to be issued using |url_request_context|. @@ -245,13 +251,15 @@ ProxyService* ProxyService::Create( // static ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { - return Create(new ProxyConfigServiceFixed(pc), false, NULL, NULL); + return Create(new ProxyConfigServiceFixed(pc), false, NULL, NULL, NULL); } // static ProxyService* ProxyService::CreateNull() { // Use a configuration fetcher and proxy resolver which always fail. - return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull); + return new ProxyService(new ProxyConfigServiceNull, + new ProxyResolverNull, + NULL); } int ProxyService::ResolveProxy(const GURL& raw_url, @@ -354,6 +362,10 @@ void ProxyService::ApplyProxyRules(const GURL& url, } ProxyService::~ProxyService() { + // Unregister to receive network change notifications. + if (network_change_notifier_) + network_change_notifier_->RemoveObserver(this); + // Cancel any inprogress requests. for (PendingRequests::iterator it = pending_requests_.begin(); it != pending_requests_.end(); @@ -736,6 +748,17 @@ bool ProxyService::IsLocalName(const GURL& url) { return host.find('.') == std::string::npos; } +void ProxyService::OnIPAddressChanged() { + DCHECK(network_change_notifier_); + + // Mark the current configuration as being un-initialized. + // + // This will force us to re-fetch the configuration (and re-run all of + // the initialization steps) on the next ResolveProxy() request, as part + // of UpdateConfigIfOld(). + config_.set_id(ProxyConfig::INVALID_ID); +} + SyncProxyServiceHelper::SyncProxyServiceHelper(MessageLoop* io_message_loop, ProxyService* proxy_service) : io_message_loop_(io_message_loop), |