From a7eee32f5e2250e5bf8d2b47612e9de140a7e850 Mon Sep 17 00:00:00 2001 From: "robertshield@google.com" Date: Fri, 22 May 2009 18:08:17 +0000 Subject: Re-do of r16741 (http://codereview.chromium.org/113482). Moved the new automation message in automation_messages_internal.h to the END of the enum as per the large scary warning that I skillfully missed last time around. TBR=amit Review URL: http://codereview.chromium.org/115711 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16754 0039d316-1c4b-4281-b951-d872f2087c98 --- net/proxy/proxy_service.cc | 6 +++++ net/proxy/proxy_service.h | 7 ++++++ net/proxy/proxy_service_unittest.cc | 50 +++++++++++++++++++++++++++++++++++++ 3 files changed, 63 insertions(+) (limited to 'net') diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index a827389..65db636 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -518,6 +518,12 @@ void ProxyService::SetProxyScriptFetcher( proxy_script_fetcher_.reset(proxy_script_fetcher); } +void ProxyService::ResetConfigService( + ProxyConfigService* new_proxy_config_service) { + config_service_.reset(new_proxy_config_service); + UpdateConfig(); +} + void ProxyService::DidCompletePacRequest(int config_id, int result_code) { // If we get an error that indicates a bad PAC config, then we should // remember that, and not try the PAC config again for a while. diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index dc0c455..e12892e 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -86,6 +86,13 @@ class ProxyService { // |proxy_script_fetcher|. void SetProxyScriptFetcher(ProxyScriptFetcher* proxy_script_fetcher); + // Tells this ProxyService to start using a new ProxyConfigService to + // retrieve its ProxyConfig from. The new ProxyConfigService will immediately + // be queried for new config info which will be used for all subsequent + // ResolveProxy calls. ProxyService takes ownership of + // |new_proxy_config_service|. + void ResetConfigService(ProxyConfigService* new_proxy_config_service); + // Creates a proxy service using the specified settings. If |pc| is NULL then // the system's default proxy settings will be used (on Windows this will // use IE's settings). diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index a2b33d4..a33dfce 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -138,6 +138,14 @@ class ResultFuture : public base::RefCountedThreadSafe { started_.Wait(); } + void StartResetConfigService( + net::ProxyConfigService* new_proxy_config_service) { + DCHECK(MessageLoop::current() != io_message_loop_); + io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod( + this, &ResultFuture::DoResetConfigService, new_proxy_config_service)); + started_.Wait(); + } + // Called on |io_message_loop_|. void DoStartRequest(const GURL& url, RequestMethod method) { DCHECK(MessageLoop::current() == io_message_loop_); @@ -150,6 +158,14 @@ class ResultFuture : public base::RefCountedThreadSafe { } // Called on |io_message_loop_|. + void DoResetConfigService(net::ProxyConfigService* new_proxy_config_service) { + DCHECK(MessageLoop::current() == io_message_loop_); + service_->ResetConfigService(new_proxy_config_service); + started_.Signal(); + OnCompletion(0); + } + + // Called on |io_message_loop_|. void DoCancel() { DCHECK(MessageLoop::current() == io_message_loop_); if (!did_complete_) @@ -230,6 +246,13 @@ class ProxyServiceWithFutures { (*result)->StartReconsider(url, proxy_info); } + void ResetConfigService(scoped_refptr* result, + net::ProxyConfigService* new_proxy_config_service) { + *result = new ResultFuture(io_thread_.message_loop(), + io_thread_state_->service); + (*result)->StartResetConfigService(new_proxy_config_service); + } + void SetProxyScriptFetcher(net::ProxyScriptFetcher* proxy_script_fetcher) { io_thread_.message_loop()->PostTask(FROM_HERE, NewRunnableMethod( io_thread_state_.get(), &IOThreadState::DoSetProxyScriptFetcher, @@ -292,6 +315,12 @@ class SyncProxyService { return result->GetResultCode(); } + int ResetConfigService(net::ProxyConfigService* new_proxy_config_service) { + scoped_refptr result; + service_.ResetConfigService(&result, new_proxy_config_service); + return result->GetResultCode(); + } + private: ProxyServiceWithFutures service_; }; @@ -1096,3 +1125,24 @@ TEST(ProxyServiceTest, CancelWhilePACFetching) { EXPECT_EQ("pac-v1.request3:80", result3->GetProxyInfo().proxy_server().ToURI()); } + +TEST(ProxyServiceTest, ResetProxyConfigService) { + net::ProxyConfig config1; + config1.proxy_rules.ParseFromString("foopy1:8080"); + config1.auto_detect = false; + scoped_ptr service( + new SyncProxyService(new MockProxyConfigService(config1), + new MockProxyResolverWithoutFetch)); + + net::ProxyInfo info; + service->ResolveProxy(GURL("http://request1"), &info); + EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); + + net::ProxyConfig config2; + config2.proxy_rules.ParseFromString("foopy2:8080"); + config2.auto_detect = false; + int result = service->ResetConfigService(new MockProxyConfigService(config2)); + DCHECK(result == 0); + service->ResolveProxy(GURL("http://request2"), &info); + EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); +} -- cgit v1.1