diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-24 00:52:01 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-24 00:52:01 +0000 |
commit | 00fb5ef53f9afadc88ddaf1e091a8114b5a9365b (patch) | |
tree | d185578d6c611e9d21d05fc9e87ade6b399b3360 /net | |
parent | 92464e9acbc960e08355d5983560de04a939c1f2 (diff) | |
download | chromium_src-00fb5ef53f9afadc88ddaf1e091a8114b5a9365b.zip chromium_src-00fb5ef53f9afadc88ddaf1e091a8114b5a9365b.tar.gz chromium_src-00fb5ef53f9afadc88ddaf1e091a8114b5a9365b.tar.bz2 |
Change the logging of PROXY_CONFIG_CHANGED so it is not displayed each time the IP address changes.
BUG=53387
Review URL: http://codereview.chromium.org/3404017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60393 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/proxy/proxy_service.cc | 47 | ||||
-rw-r--r-- | net/proxy/proxy_service.h | 10 | ||||
-rw-r--r-- | net/proxy/proxy_service_unittest.cc | 14 |
3 files changed, 53 insertions, 18 deletions
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index c74b8b0..ee4a403 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -567,10 +567,17 @@ void ProxyService::SetReady() { void ProxyService::ApplyProxyConfigIfAvailable() { DCHECK_EQ(STATE_NONE, current_state_); - current_state_ = STATE_WAITING_FOR_PROXY_CONFIG; - config_service_->OnLazyPoll(); + // If we have already fetched the configuration, start applying it. + if (fetched_config_.is_valid()) { + InitializeUsingLastFetchedConfig(); + return; + } + + // Otherwise we need to first fetch the configuration. + current_state_ = STATE_WAITING_FOR_PROXY_CONFIG; + // Retrieve the current proxy configuration from the ProxyConfigService. // If a configuration is not available yet, we will get called back later // by our ProxyConfigService::Observer once it changes. @@ -680,7 +687,7 @@ int ProxyService::DidFinishResolvingProxy(ProxyInfo* result, void ProxyService::SetProxyScriptFetcher( ProxyScriptFetcher* proxy_script_fetcher) { - State previous_state = ResetProxyConfig(); + State previous_state = ResetProxyConfig(false); proxy_script_fetcher_.reset(proxy_script_fetcher); if (previous_state != STATE_NONE) ApplyProxyConfigIfAvailable(); @@ -690,13 +697,15 @@ ProxyScriptFetcher* ProxyService::GetProxyScriptFetcher() const { return proxy_script_fetcher_.get(); } -ProxyService::State ProxyService::ResetProxyConfig() { +ProxyService::State ProxyService::ResetProxyConfig(bool reset_fetched_config) { State previous_state = current_state_; proxy_retry_info_.clear(); init_proxy_resolver_.reset(); SuspendAllPendingRequests(); config_ = ProxyConfig(); + if (reset_fetched_config) + fetched_config_ = ProxyConfig(); current_state_ = STATE_NONE; return previous_state; @@ -704,7 +713,7 @@ ProxyService::State ProxyService::ResetProxyConfig() { void ProxyService::ResetConfigService( ProxyConfigService* new_proxy_config_service) { - State previous_state = ResetProxyConfig(); + State previous_state = ResetProxyConfig(true); // Release the old configuration service. if (config_service_.get()) @@ -724,7 +733,7 @@ void ProxyService::PurgeMemory() { } void ProxyService::ForceReloadProxyConfig() { - ResetProxyConfig(); + ResetProxyConfig(false); ApplyProxyConfigIfAvailable(); } @@ -767,17 +776,10 @@ ProxyConfigService* ProxyService::CreateSystemProxyConfigService( } void ProxyService::OnProxyConfigChanged(const ProxyConfig& config) { - ProxyConfig old_fetched_config = fetched_config_; - ResetProxyConfig(); - - // Increment the ID to reflect that the config has changed. - fetched_config_ = config; - fetched_config_.set_id(next_config_id_++); - // Emit the proxy settings change to the NetLog stream. if (net_log_) { scoped_refptr<NetLog::EventParameters> params = - new ProxyConfigChangedNetLogParam(old_fetched_config, fetched_config_); + new ProxyConfigChangedNetLogParam(fetched_config_, config); net_log_->AddEntry(net::NetLog::TYPE_PROXY_CONFIG_CHANGED, base::TimeTicks::Now(), NetLog::Source(), @@ -785,6 +787,21 @@ void ProxyService::OnProxyConfigChanged(const ProxyConfig& config) { params); } + // Set the new configuration as the most recently fetched one. + fetched_config_ = config; + fetched_config_.set_id(1); // Needed for a later DCHECK of is_valid(). + + InitializeUsingLastFetchedConfig(); +} + +void ProxyService::InitializeUsingLastFetchedConfig() { + ResetProxyConfig(false); + + DCHECK(fetched_config_.is_valid()); + + // Increment the ID to reflect that the config has changed. + fetched_config_.set_id(next_config_id_++); + if (!fetched_config_.HasAutomaticSettings()) { config_ = fetched_config_; SetReady(); @@ -814,7 +831,7 @@ void ProxyService::OnIPAddressChanged() { stall_proxy_autoconfig_until_ = base::TimeTicks::Now() + stall_proxy_auto_config_delay_; - State previous_state = ResetProxyConfig(); + State previous_state = ResetProxyConfig(false); if (previous_state != STATE_NONE) ApplyProxyConfigIfAvailable(); } diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index 8e53970..d8d2e6c 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -221,8 +221,11 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>, // Resets all the variables associated with the current proxy configuration, // and rewinds the current state to |STATE_NONE|. Returns the previous value - // of |current_state_|. - State ResetProxyConfig(); + // of |current_state_|. If |reset_fetched_config| is true then + // |fetched_config_| will also be reset, otherwise it will be left as-is. + // Resetting it means that we will have to re-fetch the configuration from + // the ProxyConfigService later. + State ResetProxyConfig(bool reset_fetched_config); // Retrieves the current proxy configuration from the ProxyConfigService, and // starts initializing for it. @@ -265,6 +268,9 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>, // ProxyConfigService::Observer virtual void OnProxyConfigChanged(const ProxyConfig& config); + // Start initialization using |fetched_config_|. + void InitializeUsingLastFetchedConfig(); + scoped_ptr<ProxyConfigService> config_service_; scoped_ptr<ProxyResolver> resolver_; diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index 420d831..1c77876 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -1584,8 +1584,10 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { MockAsyncProxyResolverExpectsBytes* resolver = new MockAsyncProxyResolverExpectsBytes; + CapturingNetLog log(CapturingNetLog::kUnbounded); + scoped_refptr<ProxyService> service( - new ProxyService(config_service, resolver, NULL)); + new ProxyService(config_service, resolver, &log)); MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; service->SetProxyScriptFetcher(fetcher); @@ -1672,6 +1674,16 @@ TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { // Wait for completion callback, and verify that the request ran as expected. EXPECT_EQ(OK, callback2.WaitForResult()); EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); + + // Check that the expected events were outputted to the log stream. + // In particular, PROXY_CONFIG_CHANGED should have only been emitted once + // (for the initial setup), and NOT a second time when the IP address + // changed. + EXPECT_TRUE(LogContainsEntryWithType(log.entries(), 0, + NetLog::TYPE_PROXY_CONFIG_CHANGED)); + ASSERT_EQ(13u, log.entries().size()); + for (size_t i = 1; i < log.entries().size(); ++i) + EXPECT_NE(NetLog::TYPE_PROXY_CONFIG_CHANGED, log.entries()[i].type); } } // namespace net |