diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-19 22:17:53 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-19 22:17:53 +0000 |
commit | 51fff29dc2dae1a8be5ea107d2b13205510c4e46 (patch) | |
tree | 56a82f110e5605f9aed8f75b2cf954cc5765ed1a /net | |
parent | 4750a86ea19e14d99a6b5fc94cd18d08ced463da (diff) | |
download | chromium_src-51fff29dc2dae1a8be5ea107d2b13205510c4e46.zip chromium_src-51fff29dc2dae1a8be5ea107d2b13205510c4e46.tar.gz chromium_src-51fff29dc2dae1a8be5ea107d2b13205510c4e46.tar.bz2 |
Split ProxyResolver into two interfaces: A. interface for retrieving the system proxy settings (ProxyConfigService) B. interface for resolving the proxy (ProxyResolver)The motivation behind this change is: 1. Simplify sharing the WinHTTP code that fetches IE settings, with the V8 proxy resolver (avoids having platform-specific code in ProxyResolverV8). 2. Restrict objects to one thread. (ProxyService calls the config getter on IO thread, and the proxy resolving on the PAC thread).(ProxyResolver is now only 1 method, but this will grow shortly).
Review URL: http://codereview.chromium.org/15070
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7323 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/build/net.vcproj | 6 | ||||
-rw-r--r-- | net/http/http_network_layer_unittest.cc | 13 | ||||
-rw-r--r-- | net/http/http_network_transaction_unittest.cc | 27 | ||||
-rw-r--r-- | net/http/http_transaction_winhttp_unittest.cc | 13 | ||||
-rw-r--r-- | net/net.xcodeproj/project.pbxproj | 8 | ||||
-rw-r--r-- | net/net_lib.scons | 2 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_fixed.h | 30 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_win.cc | 58 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_win.h | 23 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_fixed.cc | 24 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_fixed.h | 30 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_mac.cc | 2 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_mac.h | 7 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_null.h | 28 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_winhttp.cc | 41 | ||||
-rw-r--r-- | net/proxy/proxy_resolver_winhttp.h | 1 | ||||
-rw-r--r-- | net/proxy/proxy_service.cc | 42 | ||||
-rw-r--r-- | net/proxy/proxy_service.h | 28 | ||||
-rw-r--r-- | net/proxy/proxy_service_unittest.cc | 116 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.cc | 3 | ||||
-rw-r--r-- | net/url_request/url_request_unittest.h | 3 |
21 files changed, 277 insertions, 228 deletions
diff --git a/net/build/net.vcproj b/net/build/net.vcproj index c304043..dad5e02 100644 --- a/net/build/net.vcproj +++ b/net/build/net.vcproj @@ -1017,15 +1017,15 @@ Name="proxy" > <File - RelativePath="..\proxy\proxy_resolver_fixed.cc" + RelativePath="..\proxy\proxy_config_service_fixed.h" > </File> <File - RelativePath="..\proxy\proxy_resolver_fixed.h" + RelativePath="..\proxy\proxy_config_service_win.cc" > </File> <File - RelativePath="..\proxy\proxy_resolver_null.h" + RelativePath="..\proxy\proxy_config_service_win.h" > </File> <File diff --git a/net/http/http_network_layer_unittest.cc b/net/http/http_network_layer_unittest.cc index 0460947..aae4ed5 100644 --- a/net/http/http_network_layer_unittest.cc +++ b/net/http/http_network_layer_unittest.cc @@ -5,7 +5,6 @@ #include "net/base/scoped_host_mapper.h" #include "net/http/http_network_layer.h" #include "net/http/http_transaction_unittest.h" -#include "net/proxy/proxy_resolver_null.h" #include "net/proxy/proxy_service.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -22,15 +21,15 @@ class HttpNetworkLayerTest : public PlatformTest { }; TEST_F(HttpNetworkLayerTest, CreateAndDestroy) { - net::ProxyService proxy_service(new net::ProxyResolverNull); - net::HttpNetworkLayer factory(&proxy_service); + scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); + net::HttpNetworkLayer factory(proxy_service.get()); scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); } TEST_F(HttpNetworkLayerTest, Suspend) { - net::ProxyService proxy_service(new net::ProxyResolverNull); - net::HttpNetworkLayer factory(&proxy_service); + scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); + net::HttpNetworkLayer factory(proxy_service.get()); scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); trans.reset(); @@ -46,8 +45,8 @@ TEST_F(HttpNetworkLayerTest, Suspend) { } TEST_F(HttpNetworkLayerTest, GoogleGET) { - net::ProxyService proxy_service(new net::ProxyResolverNull); - net::HttpNetworkLayer factory(&proxy_service); + scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); + net::HttpNetworkLayer factory(proxy_service.get()); TestCompletionCallback callback; diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 903f6d9..375d62d 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -11,8 +11,7 @@ #include "net/http/http_network_session.h" #include "net/http/http_network_transaction.h" #include "net/http/http_transaction_unittest.h" -#include "net/proxy/proxy_resolver_fixed.h" -#include "net/proxy/proxy_resolver_null.h" +#include "net/proxy/proxy_config_service_fixed.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -202,9 +201,17 @@ MockClientSocketFactory mock_socket_factory; // Create a proxy service which fails on all requests (falls back to direct). net::ProxyService* CreateNullProxyService() { - return new net::ProxyService(new net::ProxyResolverNull); + return net::ProxyService::CreateNull(); } +net::ProxyService* CreateFixedProxyService(const std::string& proxy) { + net::ProxyInfo proxy_info; + proxy_info.UseNamedProxy(proxy); + return new net::ProxyService( + new net::ProxyConfigServiceFixed(proxy_info), NULL); +} + + net::HttpNetworkSession* CreateSession(net::ProxyService* proxy_service) { return new net::HttpNetworkSession(proxy_service); } @@ -709,13 +716,12 @@ TEST_F(HttpNetworkTransactionTest, BasicAuth) { // authentication. Again, this uses basic auth for both since that is // the simplest to mock. TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { - net::ProxyInfo proxy_info; - proxy_info.UseNamedProxy("myproxy:70"); - net::ProxyService proxy_service(new net::ProxyResolverFixed(proxy_info)); + scoped_ptr<net::ProxyService> proxy_service( + CreateFixedProxyService("myproxy:70")); // Configure against proxy server "myproxy:70". scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( - CreateSession(&proxy_service), + CreateSession(proxy_service.get()), &mock_socket_factory)); net::HttpRequestInfo request; @@ -889,12 +895,11 @@ TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { // http://code.google.com/p/chromium/issues/detail?id=3772 TEST_F(HttpNetworkTransactionTest, DontRecycleTCPSocketForSSLTunnel) { // Configure against proxy server "myproxy:70". - net::ProxyInfo proxy_info; - proxy_info.UseNamedProxy("myproxy:70"); - net::ProxyService proxy_service(new net::ProxyResolverFixed(proxy_info)); + scoped_ptr<net::ProxyService> proxy_service( + CreateFixedProxyService("myproxy:70")); scoped_refptr<net::HttpNetworkSession> session( - CreateSession(&proxy_service)); + CreateSession(proxy_service.get())); scoped_ptr<net::HttpTransaction> trans(new net::HttpNetworkTransaction( session.get(), &mock_socket_factory)); diff --git a/net/http/http_transaction_winhttp_unittest.cc b/net/http/http_transaction_winhttp_unittest.cc index acc4e08..e24c8d8 100644 --- a/net/http/http_transaction_winhttp_unittest.cc +++ b/net/http/http_transaction_winhttp_unittest.cc @@ -4,19 +4,18 @@ #include "net/http/http_transaction_winhttp.h" #include "net/http/http_transaction_unittest.h" -#include "net/proxy/proxy_resolver_null.h" #include "testing/gtest/include/gtest/gtest.h" TEST(HttpTransactionWinHttp, CreateAndDestroy) { - net::ProxyService proxy_service(new net::ProxyResolverNull); - net::HttpTransactionWinHttp::Factory factory(&proxy_service); + scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); + net::HttpTransactionWinHttp::Factory factory(proxy_service.get()); scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); } TEST(HttpTransactionWinHttp, Suspend) { - net::ProxyService proxy_service(new net::ProxyResolverNull); - net::HttpTransactionWinHttp::Factory factory(&proxy_service); + scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); + net::HttpTransactionWinHttp::Factory factory(proxy_service.get()); scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); trans.reset(); @@ -32,8 +31,8 @@ TEST(HttpTransactionWinHttp, Suspend) { } TEST(HttpTransactionWinHttp, GoogleGET) { - net::ProxyService proxy_service(new net::ProxyResolverNull); - net::HttpTransactionWinHttp::Factory factory(&proxy_service); + scoped_ptr<net::ProxyService> proxy_service(net::ProxyService::CreateNull()); + net::HttpTransactionWinHttp::Factory factory(proxy_service.get()); TestCompletionCallback callback; scoped_ptr<net::HttpTransaction> trans(factory.CreateTransaction()); diff --git a/net/net.xcodeproj/project.pbxproj b/net/net.xcodeproj/project.pbxproj index 8a85e0a..54cf89e 100644 --- a/net/net.xcodeproj/project.pbxproj +++ b/net/net.xcodeproj/project.pbxproj @@ -175,7 +175,6 @@ E49DD2EA0E892F8C003C7A87 /* sdch_manager.cc in Sources */ = {isa = PBXBuildFile; fileRef = E49DD2E80E892F8C003C7A87 /* sdch_manager.cc */; }; E49DD3290E893336003C7A87 /* http_network_layer.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED33620E5A194700A747DB /* http_network_layer.cc */; }; E49DD3370E8933A2003C7A87 /* proxy_service.cc in Sources */ = {isa = PBXBuildFile; fileRef = E49DD3360E8933A2003C7A87 /* proxy_service.cc */; }; - E49DD33C0E8933C0003C7A87 /* proxy_resolver_fixed.cc in Sources */ = {isa = PBXBuildFile; fileRef = E49DD33B0E8933C0003C7A87 /* proxy_resolver_fixed.cc */; }; E4AFA6430E5241B400201347 /* run_all_unittests.cc in Sources */ = {isa = PBXBuildFile; fileRef = E4AFA6420E5241B400201347 /* run_all_unittests.cc */; }; E4CE9BC50E8BF92400D5378C /* http_network_transaction.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED33680E5A194700A747DB /* http_network_transaction.cc */; }; E4CE9C070E8BFF0700D5378C /* upload_data_stream.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7BED32870E5A181C00A747DB /* upload_data_stream.cc */; }; @@ -429,7 +428,6 @@ 0435A48D0E8DD74300E4DF08 /* http_auth_handler_basic.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = http_auth_handler_basic.h; sourceTree = "<group>"; }; 0435A48E0E8DD74B00E4DF08 /* http_auth_handler_digest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_auth_handler_digest.cc; sourceTree = "<group>"; }; 0435A4900E8DD75200E4DF08 /* http_auth_handler_digest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = http_auth_handler_digest.h; sourceTree = "<group>"; }; - 04AC41720EA941AE0063A0AB /* proxy_resolver_null.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = proxy_resolver_null.h; path = proxy/proxy_resolver_null.h; sourceTree = "<group>"; }; 04C626D50E8DE39E0067E92A /* http_auth_handler_digest_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_auth_handler_digest_unittest.cc; sourceTree = "<group>"; }; 04C626D70E8DE3AA0067E92A /* http_auth_handler_basic_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_auth_handler_basic_unittest.cc; sourceTree = "<group>"; }; 04C626D90E8DE3BA0067E92A /* http_auth_unittest.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = http_auth_unittest.cc; sourceTree = "<group>"; }; @@ -694,8 +692,6 @@ E49DD2E90E892F8C003C7A87 /* sdch_manager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = sdch_manager.h; sourceTree = "<group>"; }; E49DD3350E8933A2003C7A87 /* proxy_service.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = proxy_service.h; path = proxy/proxy_service.h; sourceTree = "<group>"; }; E49DD3360E8933A2003C7A87 /* proxy_service.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = proxy_service.cc; path = proxy/proxy_service.cc; sourceTree = "<group>"; }; - E49DD33A0E8933C0003C7A87 /* proxy_resolver_fixed.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = proxy_resolver_fixed.h; path = proxy/proxy_resolver_fixed.h; sourceTree = "<group>"; }; - E49DD33B0E8933C0003C7A87 /* proxy_resolver_fixed.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = proxy_resolver_fixed.cc; path = proxy/proxy_resolver_fixed.cc; sourceTree = "<group>"; }; E4AFA6230E523E2900201347 /* net_unittests */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = net_unittests; sourceTree = BUILT_PRODUCTS_DIR; }; E4AFA62E0E5240A300201347 /* gtest.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = gtest.xcodeproj; path = testing/gtest.xcodeproj; sourceTree = "<group>"; }; E4AFA6420E5241B400201347 /* run_all_unittests.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = run_all_unittests.cc; sourceTree = "<group>"; }; @@ -1160,11 +1156,8 @@ E49DD3330E893388003C7A87 /* proxy */ = { isa = PBXGroup; children = ( - E49DD33A0E8933C0003C7A87 /* proxy_resolver_fixed.h */, - E49DD33B0E8933C0003C7A87 /* proxy_resolver_fixed.cc */, 820701030EB6611F005CD9E7 /* proxy_resolver_mac.h */, 820701020EB6611F005CD9E7 /* proxy_resolver_mac.cc */, - 04AC41720EA941AE0063A0AB /* proxy_resolver_null.h */, E49DD3350E8933A2003C7A87 /* proxy_service.h */, E49DD3360E8933A2003C7A87 /* proxy_service.cc */, 7BA361EC0E8C38D30023C8B9 /* proxy_service_unittest.cc */, @@ -1513,7 +1506,6 @@ 7B8B5AE30E5CDC00002F9A97 /* net_util.cc in Sources */, 533102E70E5E3EBF00FF8E32 /* net_util_posix.cc in Sources */, 7B85043C0E5B2E6400730B43 /* platform_mime_util_mac.cc in Sources */, - E49DD33C0E8933C0003C7A87 /* proxy_resolver_fixed.cc in Sources */, 820701040EB6611F005CD9E7 /* proxy_resolver_mac.cc in Sources */, E49DD3370E8933A2003C7A87 /* proxy_service.cc in Sources */, 7B85043D0E5B2E6400730B43 /* rankings.cc in Sources */, diff --git a/net/net_lib.scons b/net/net_lib.scons index 75e33a7..d9566a6 100644 --- a/net/net_lib.scons +++ b/net/net_lib.scons @@ -81,7 +81,6 @@ input_files = [ 'http/http_util.cc', 'http/http_vary_data.cc', 'http/winhttp_request_throttle.cc', - 'proxy/proxy_resolver_fixed.cc', 'proxy/proxy_script_fetcher.cc', 'proxy/proxy_service.cc', 'url_request/mime_sniffer_proxy.cc', @@ -127,6 +126,7 @@ if env.Bit('windows'): 'disk_cache/cache_util_win.cc', 'disk_cache/file_win.cc', 'disk_cache/mapped_file_win.cc', + 'proxy/proxy_config_service_win.cc', 'proxy/proxy_resolver_winhttp.cc', 'url_request/url_request_inet_job.cc', ]) diff --git a/net/proxy/proxy_config_service_fixed.h b/net/proxy/proxy_config_service_fixed.h new file mode 100644 index 0000000..633af95 --- /dev/null +++ b/net/proxy/proxy_config_service_fixed.h @@ -0,0 +1,30 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_PROXY_PROXY_CONFIG_SERVICE_FIXED_H_ +#define NET_PROXY_PROXY_CONFIG_SERVICE_FIXED_H_ + +#include "net/proxy/proxy_service.h" + +namespace net { + +// Implementation of ProxyConfigService that returns a fixed result. +class ProxyConfigServiceFixed : public ProxyConfigService { + public: + explicit ProxyConfigServiceFixed(const ProxyInfo& pi) { pi_.Use(pi); } + + // ProxyConfigService methods: + virtual int GetProxyConfig(ProxyConfig* config) { + config->proxy_server = pi_.proxy_server(); + return OK; + } + + private: + ProxyInfo pi_; +}; + +} // namespace net + +#endif // NET_PROXY_PROXY_CONFIG_SERVICE_FIXED_H_ + diff --git a/net/proxy/proxy_config_service_win.cc b/net/proxy/proxy_config_service_win.cc new file mode 100644 index 0000000..f356ac9 --- /dev/null +++ b/net/proxy/proxy_config_service_win.cc @@ -0,0 +1,58 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/proxy/proxy_config_service_win.h" + +#include <windows.h> +#include <winhttp.h> + +#include "base/string_tokenizer.h" +#include "net/base/net_errors.h" + +#pragma comment(lib, "winhttp.lib") + +namespace net { + +static void FreeConfig(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* config) { + if (config->lpszAutoConfigUrl) + GlobalFree(config->lpszAutoConfigUrl); + if (config->lpszProxy) + GlobalFree(config->lpszProxy); + if (config->lpszProxyBypass) + GlobalFree(config->lpszProxyBypass); +} + +int ProxyConfigServiceWin::GetProxyConfig(ProxyConfig* config) { + WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config = {0}; + if (!WinHttpGetIEProxyConfigForCurrentUser(&ie_config)) { + LOG(ERROR) << "WinHttpGetIEProxyConfigForCurrentUser failed: " << + GetLastError(); + return ERR_FAILED; // TODO(darin): Bug 1189288: translate error code. + } + + if (ie_config.fAutoDetect) + config->auto_detect = true; + if (ie_config.lpszProxy) + config->proxy_server = WideToASCII(ie_config.lpszProxy); + if (ie_config.lpszProxyBypass) { + std::string proxy_bypass = WideToASCII(ie_config.lpszProxyBypass); + + StringTokenizer proxy_server_bypass_list(proxy_bypass, "; \t\n\r"); + while (proxy_server_bypass_list.GetNext()) { + std::string bypass_url_domain = proxy_server_bypass_list.token(); + if (bypass_url_domain == "<local>") + config->proxy_bypass_local_names = true; + else + config->proxy_bypass.push_back(bypass_url_domain); + } + } + if (ie_config.lpszAutoConfigUrl) + config->pac_url = GURL(ie_config.lpszAutoConfigUrl); + + FreeConfig(&ie_config); + return OK; +} + +} // namespace net + diff --git a/net/proxy/proxy_config_service_win.h b/net/proxy/proxy_config_service_win.h new file mode 100644 index 0000000..f2a5e47 --- /dev/null +++ b/net/proxy/proxy_config_service_win.h @@ -0,0 +1,23 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ +#define NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ + +#include "net/proxy/proxy_service.h" + +namespace net { + +// Implementation of ProxyConfigService that retrieves the system proxy +// settings. +class ProxyConfigServiceWin : public ProxyConfigService { + public: + // ProxyConfigService methods. + virtual int GetProxyConfig(ProxyConfig* config); +}; + +} // namespace net + +#endif // NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ + diff --git a/net/proxy/proxy_resolver_fixed.cc b/net/proxy/proxy_resolver_fixed.cc deleted file mode 100644 index b064803..0000000 --- a/net/proxy/proxy_resolver_fixed.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "net/proxy/proxy_resolver_fixed.h" - -#include "net/base/net_errors.h" - -namespace net { - -int ProxyResolverFixed::GetProxyConfig(ProxyConfig* config) { - config->proxy_server = pi_.proxy_server(); - return OK; -} - -int ProxyResolverFixed::GetProxyForURL(const GURL& query_url, - const GURL& pac_url, - ProxyInfo* results) { - NOTREACHED() << "Should not be asked to do proxy auto config"; - return ERR_FAILED; -} - -} // namespace net - diff --git a/net/proxy/proxy_resolver_fixed.h b/net/proxy/proxy_resolver_fixed.h deleted file mode 100644 index 2ecd62c..0000000 --- a/net/proxy/proxy_resolver_fixed.h +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_PROXY_PROXY_RESOLVER_FIXED_H_ -#define NET_PROXY_PROXY_RESOLVER_FIXED_H_ - -#include "net/proxy/proxy_service.h" - -namespace net { - -// Implementation of ProxyResolver that returns a fixed result. -class ProxyResolverFixed : public ProxyResolver { - public: - ProxyResolverFixed(const ProxyInfo& pi) { pi_.Use(pi); } - - // ProxyResolver methods: - virtual int GetProxyConfig(ProxyConfig* config); - virtual int GetProxyForURL(const GURL& query_url, - const GURL& pac_url, - ProxyInfo* results); - - private: - ProxyInfo pi_; -}; - -} // namespace net - -#endif // NET_PROXY_PROXY_RESOLVER_FIXED_H_ - diff --git a/net/proxy/proxy_resolver_mac.cc b/net/proxy/proxy_resolver_mac.cc index f58cc85..4f021a4 100644 --- a/net/proxy/proxy_resolver_mac.cc +++ b/net/proxy/proxy_resolver_mac.cc @@ -115,7 +115,7 @@ void ResultCallback(void* client, CFArrayRef proxies, CFErrorRef error) { namespace net { -int ProxyResolverMac::GetProxyConfig(ProxyConfig* config) { +int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) { scoped_cftyperef<CFDictionaryRef> config_dict( SCDynamicStoreCopyProxies(NULL)); DCHECK(config_dict); diff --git a/net/proxy/proxy_resolver_mac.h b/net/proxy/proxy_resolver_mac.h index a3b56fc..f207e1b 100644 --- a/net/proxy/proxy_resolver_mac.h +++ b/net/proxy/proxy_resolver_mac.h @@ -14,12 +14,17 @@ namespace net { class ProxyResolverMac : public ProxyResolver { public: // ProxyResolver methods: - virtual int GetProxyConfig(ProxyConfig* config); virtual int GetProxyForURL(const GURL& query_url, const GURL& pac_url, ProxyInfo* results); }; +class ProxyConfigServiceMac : public ProxyConfigService { + public: + // ProxyConfigService methods: + virtual int GetProxyConfig(ProxyConfig* config); +}; + } // namespace net #endif // NET_PROXY_PROXY_RESOLVER_MAC_H_ diff --git a/net/proxy/proxy_resolver_null.h b/net/proxy/proxy_resolver_null.h deleted file mode 100644 index e1bdcbd..0000000 --- a/net/proxy/proxy_resolver_null.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef NET_PROXY_PROXY_RESOLVER_NULL_H_ -#define NET_PROXY_PROXY_RESOLVER_NULL_H_ - -#include "net/proxy/proxy_service.h" - -namespace net { - -// Implementation of ProxyResolver that always fails. -class ProxyResolverNull : public ProxyResolver { - public: - virtual int GetProxyConfig(ProxyConfig* config) { - return ERR_NOT_IMPLEMENTED; - } - virtual int GetProxyForURL(const GURL& query_url, - const GURL& pac_url, - ProxyInfo* results) { - return ERR_NOT_IMPLEMENTED; - } -}; - -} // namespace net - -#endif // NET_PROXY_PROXY_RESOLVER_NULL_H_ - diff --git a/net/proxy/proxy_resolver_winhttp.cc b/net/proxy/proxy_resolver_winhttp.cc index 382914f..d4877ac 100644 --- a/net/proxy/proxy_resolver_winhttp.cc +++ b/net/proxy/proxy_resolver_winhttp.cc @@ -8,7 +8,6 @@ #include <winhttp.h> #include "base/histogram.h" -#include "base/string_tokenizer.h" #include "net/base/net_errors.h" #pragma comment(lib, "winhttp.lib") @@ -35,15 +34,6 @@ static BOOL CallWinHttpGetProxyForUrl(HINTERNET session, LPCWSTR url, return rv; } -static void FreeConfig(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* config) { - if (config->lpszAutoConfigUrl) - GlobalFree(config->lpszAutoConfigUrl); - if (config->lpszProxy) - GlobalFree(config->lpszProxy); - if (config->lpszProxyBypass) - GlobalFree(config->lpszProxyBypass); -} - static void FreeInfo(WINHTTP_PROXY_INFO* info) { if (info->lpszProxy) GlobalFree(info->lpszProxy); @@ -59,37 +49,6 @@ ProxyResolverWinHttp::~ProxyResolverWinHttp() { CloseWinHttpSession(); } -int ProxyResolverWinHttp::GetProxyConfig(ProxyConfig* config) { - WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config = {0}; - if (!WinHttpGetIEProxyConfigForCurrentUser(&ie_config)) { - LOG(ERROR) << "WinHttpGetIEProxyConfigForCurrentUser failed: " << - GetLastError(); - return ERR_FAILED; // TODO(darin): Bug 1189288: translate error code. - } - - if (ie_config.fAutoDetect) - config->auto_detect = true; - if (ie_config.lpszProxy) - config->proxy_server = WideToASCII(ie_config.lpszProxy); - if (ie_config.lpszProxyBypass) { - std::string proxy_bypass = WideToASCII(ie_config.lpszProxyBypass); - - StringTokenizer proxy_server_bypass_list(proxy_bypass, "; \t\n\r"); - while (proxy_server_bypass_list.GetNext()) { - std::string bypass_url_domain = proxy_server_bypass_list.token(); - if (bypass_url_domain == "<local>") - config->proxy_bypass_local_names = true; - else - config->proxy_bypass.push_back(bypass_url_domain); - } - } - if (ie_config.lpszAutoConfigUrl) - config->pac_url = GURL(ie_config.lpszAutoConfigUrl); - - FreeConfig(&ie_config); - return OK; -} - int ProxyResolverWinHttp::GetProxyForURL(const GURL& query_url, const GURL& pac_url, ProxyInfo* results) { diff --git a/net/proxy/proxy_resolver_winhttp.h b/net/proxy/proxy_resolver_winhttp.h index ac981686..032cab7 100644 --- a/net/proxy/proxy_resolver_winhttp.h +++ b/net/proxy/proxy_resolver_winhttp.h @@ -19,7 +19,6 @@ class ProxyResolverWinHttp : public ProxyResolver { ~ProxyResolverWinHttp(); // ProxyResolver implementation: - virtual int GetProxyConfig(ProxyConfig* config); virtual int GetProxyForURL(const GURL& query_url, const GURL& pac_url, ProxyInfo* results); diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 5f0f6b2..7f51f52 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -17,10 +17,10 @@ #include "base/string_util.h" #include "googleurl/src/gurl.h" #include "net/base/net_errors.h" -#include "net/proxy/proxy_resolver_fixed.h" -#include "net/proxy/proxy_resolver_null.h" +#include "net/proxy/proxy_config_service_fixed.h" #if defined(OS_WIN) #include "net/http/http_transaction_winhttp.h" +#include "net/proxy/proxy_config_service_win.h" #include "net/proxy/proxy_resolver_winhttp.h" #elif defined(OS_MACOSX) #include "net/proxy/proxy_resolver_mac.h" @@ -31,6 +31,15 @@ using base::TimeTicks; namespace net { +// Config getter that fails every time. +class ProxyConfigServiceNull : public ProxyConfigService { + public: + virtual int GetProxyConfig(ProxyConfig* config) { + return ERR_NOT_IMPLEMENTED; + } +}; + + // ProxyConfig ---------------------------------------------------------------- // static @@ -272,8 +281,10 @@ class ProxyService::PacRequest : // ProxyService --------------------------------------------------------------- -ProxyService::ProxyService(ProxyResolver* resolver) - : resolver_(resolver), +ProxyService::ProxyService(ProxyConfigService* config_service, + ProxyResolver* resolver) + : config_service_(config_service), + resolver_(resolver), config_is_bad_(false), config_has_been_updated_(false) { } @@ -281,8 +292,10 @@ ProxyService::ProxyService(ProxyResolver* resolver) // static ProxyService* ProxyService::Create(const ProxyInfo* pi) { if (pi) { + // The ProxyResolver is set to NULL, since it should never be called + // (because the configuration will never require PAC). ProxyService* proxy_service = - new ProxyService(new ProxyResolverFixed(*pi)); + new ProxyService(new ProxyConfigServiceFixed(*pi), NULL); // TODO(eroman): remove this WinHTTP hack once it is no more. // We keep a copy of the ProxyInfo that was used to create the @@ -292,23 +305,32 @@ ProxyService* ProxyService::Create(const ProxyInfo* pi) { return proxy_service; } #if defined(OS_WIN) - return new ProxyService(new ProxyResolverWinHttp()); + return new ProxyService(new ProxyConfigServiceWin(), + new ProxyResolverWinHttp()); #elif defined(OS_MACOSX) - return new ProxyService(new ProxyResolverMac()); + return new ProxyService(new ProxyConfigServiceMac(), + new ProxyResolverMac()); #else // This used to be a NOTIMPLEMENTED(), but that logs as an error, // screwing up layout tests. LOG(WARNING) << "Proxies are not implemented; remove me once that's fixed."; // http://code.google.com/p/chromium/issues/detail?id=4523 is the bug // to implement this. - return new ProxyService(new ProxyResolverNull()); + return CreateNull(); #endif } +// static +ProxyService* ProxyService::CreateNull() { + // The ProxyResolver is set to NULL, since it should never be called + // (because the configuration will never require PAC). + return new ProxyService(new ProxyConfigServiceNull, NULL); +} + int ProxyService::ResolveProxy(const GURL& url, ProxyInfo* result, CompletionCallback* callback, PacRequest** pac_request) { - // The overhead of calling WinHttpGetIEProxyConfigForCurrentUser is very low. + // The overhead of calling ProxyConfigService::GetProxyConfig is very low. const TimeDelta kProxyConfigMaxAge = TimeDelta::FromSeconds(5); // Periodically check for a new config. @@ -481,7 +503,7 @@ void ProxyService::UpdateConfig() { config_has_been_updated_ = true; ProxyConfig latest; - if (resolver_->GetProxyConfig(&latest) != OK) + if (config_service_->GetProxyConfig(&latest) != OK) return; config_last_update_time_ = TimeTicks::Now(); diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index bea4aef..6a9c04b 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -24,6 +24,7 @@ class GURL; namespace net { +class ProxyConfigService; class ProxyInfo; class ProxyResolver; @@ -85,8 +86,9 @@ typedef std::map<std::string, ProxyRetryInfo> ProxyRetryInfoMap; // resolution. See ProxyResolverWinHttp for example. class ProxyService { public: - // The instance takes ownership of |resolver|. - explicit ProxyService(ProxyResolver* resolver); + // The instance takes ownership of |config_service| and |resolver|. + ProxyService(ProxyConfigService* config_service, + ProxyResolver* resolver); // Used internally to handle PAC queries. class PacRequest; @@ -138,6 +140,10 @@ class ProxyService { // use IE's settings). static ProxyService* Create(const ProxyInfo* pi); + // Create a proxy service that always fails to fetch the proxy configuration, + // so it falls back to direct connect. + static ProxyService* CreateNull(); + // TODO(eroman): remove once WinHTTP is gone. // Get the ProxyInfo used to create this proxy service (only used by WinHTTP). const ProxyInfo* proxy_info() const { @@ -169,6 +175,7 @@ class ProxyService { // 2. The URL matches one of the entities in the proxy bypass list. bool ShouldBypassProxyForURL(const GURL& url); + scoped_ptr<ProxyConfigService> config_service_; scoped_ptr<ProxyResolver> resolver_; scoped_ptr<base::Thread> pac_thread_; @@ -288,20 +295,27 @@ class ProxyInfo { bool config_was_tried_; }; -// This interface provides the low-level functions to access the proxy -// configuration and resolve proxies for given URLs synchronously. -class ProxyResolver { +// Synchronously fetch the system's proxy configuration settings. Called on +// the IO Thread. +class ProxyConfigService { public: - virtual ~ProxyResolver() {} + virtual ~ProxyConfigService() {} // Get the proxy configuration. Returns OK if successful or an error code if // otherwise. |config| should be in its initial state when this method is // called. virtual int GetProxyConfig(ProxyConfig* config) = 0; +}; + +// Synchronously resolve the proxy for a URL, using a PAC script. Called on the +// PAC Thread. +class ProxyResolver { + public: + virtual ~ProxyResolver() {} // Query the proxy auto-config file (specified by |pac_url|) for the proxy to // use to load the given |query_url|. Returns OK if successful or an error - // code if otherwise. + // code otherwise. virtual int GetProxyForURL(const GURL& query_url, const GURL& pac_url, ProxyInfo* results) = 0; diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index 1ad7d32..48a8721 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -9,22 +9,32 @@ namespace { -class MockProxyResolver : public net::ProxyResolver { +// TODO(eroman): get rid of synchronous usages of ProxyService::ResolveProxy(). + +class MockProxyConfigService: public net::ProxyConfigService { public: - MockProxyResolver() : fail_get_proxy_for_url(false) { - } - // Init the MockProxyResolver with the specified ProxyConfig. - explicit MockProxyResolver(const net::ProxyConfig& c) : config(c) { + MockProxyConfigService() {} // Direct connect. + explicit MockProxyConfigService(const net::ProxyConfig& pc) : config(pc) {} + explicit MockProxyConfigService(const std::string& pac_url) { + config.pac_url = GURL(pac_url); } + virtual int GetProxyConfig(net::ProxyConfig* results) { *results = config; return net::OK; } + + net::ProxyConfig config; +}; + +class MockProxyResolver : public net::ProxyResolver { + public: + MockProxyResolver() : fail_get_proxy_for_url(false) { + } + virtual int GetProxyForURL(const GURL& query_url, const GURL& pac_url, net::ProxyInfo* results) { - if (pac_url != config.pac_url) - return net::ERR_INVALID_ARGUMENT; if (fail_get_proxy_for_url) return net::ERR_FAILED; if (GURL(query_url).host() == info_predicate_query_host) { @@ -34,7 +44,7 @@ class MockProxyResolver : public net::ProxyResolver { } return net::OK; } - net::ProxyConfig config; + net::ProxyInfo info; // info is only returned if query_url in GetProxyForURL matches this: @@ -62,7 +72,8 @@ TEST(ProxyListTest, GetAnnotatedList) { } TEST(ProxyServiceTest, Direct) { - net::ProxyService service(new MockProxyResolver); + net::ProxyService service(new MockProxyConfigService, + new MockProxyResolver); GURL url("http://www.google.com/"); @@ -73,12 +84,14 @@ TEST(ProxyServiceTest, Direct) { } TEST(ProxyServiceTest, PAC) { + MockProxyConfigService* config_service = + new MockProxyConfigService("http://foopy/proxy.pac"); + MockProxyResolver* resolver = new MockProxyResolver; - resolver->config.pac_url = GURL("http://foopy/proxy.pac"); resolver->info.UseNamedProxy("foopy"); resolver->info_predicate_query_host = "www.google.com"; - net::ProxyService service(resolver); + net::ProxyService service(config_service, resolver); GURL url("http://www.google.com/"); @@ -90,12 +103,14 @@ TEST(ProxyServiceTest, PAC) { } TEST(ProxyServiceTest, PAC_FailoverToDirect) { + MockProxyConfigService* config_service = + new MockProxyConfigService("http://foopy/proxy.pac"); + MockProxyResolver* resolver = new MockProxyResolver; - resolver->config.pac_url = GURL("http://foopy/proxy.pac"); resolver->info.UseNamedProxy("foopy:8080"); resolver->info_predicate_query_host = "www.google.com"; - net::ProxyService service(resolver); + net::ProxyService service(config_service, resolver); GURL url("http://www.google.com/"); @@ -114,13 +129,15 @@ TEST(ProxyServiceTest, PAC_FailoverToDirect) { TEST(ProxyServiceTest, PAC_FailsToDownload) { // Test what happens when we fail to download the PAC URL. + MockProxyConfigService* config_service = + new MockProxyConfigService("http://foopy/proxy.pac"); + MockProxyResolver* resolver = new MockProxyResolver; - resolver->config.pac_url = GURL("http://foopy/proxy.pac"); resolver->info.UseNamedProxy("foopy:8080"); resolver->info_predicate_query_host = "www.google.com"; resolver->fail_get_proxy_for_url = true; - net::ProxyService service(resolver); + net::ProxyService service(config_service, resolver); GURL url("http://www.google.com/"); net::ProxyInfo info; @@ -147,13 +164,15 @@ TEST(ProxyServiceTest, ProxyFallback) { // Test what happens when we specify multiple proxy servers and some of them // are bad. + MockProxyConfigService* config_service = + new MockProxyConfigService("http://foopy/proxy.pac"); + MockProxyResolver* resolver = new MockProxyResolver; - resolver->config.pac_url = GURL("http://foopy/proxy.pac"); resolver->info.UseNamedProxy("foopy1:8080;foopy2:9090"); resolver->info_predicate_query_host = "www.google.com"; resolver->fail_get_proxy_for_url = false; - net::ProxyService service(resolver); + net::ProxyService service(config_service, resolver); GURL url("http://www.google.com/"); @@ -175,7 +194,7 @@ TEST(ProxyServiceTest, ProxyFallback) { // Create a new resolver that returns 3 proxies. The second one is already // known to be bad. - resolver->config.pac_url = GURL("http://foopy/proxy.pac"); + config_service->config.pac_url = GURL("http://foopy/proxy.pac"); resolver->info.UseNamedProxy("foopy3:7070;foopy1:8080;foopy2:9090"); resolver->info_predicate_query_host = "www.google.com"; resolver->fail_get_proxy_for_url = false; @@ -205,13 +224,15 @@ TEST(ProxyServiceTest, ProxyFallback) { TEST(ProxyServiceTest, ProxyFallback_NewSettings) { // Test proxy failover when new settings are available. + MockProxyConfigService* config_service = + new MockProxyConfigService("http://foopy/proxy.pac"); + MockProxyResolver* resolver = new MockProxyResolver; - resolver->config.pac_url = GURL("http://foopy/proxy.pac"); resolver->info.UseNamedProxy("foopy1:8080;foopy2:9090"); resolver->info_predicate_query_host = "www.google.com"; resolver->fail_get_proxy_for_url = false; - net::ProxyService service(resolver); + net::ProxyService service(config_service, resolver); GURL url("http://www.google.com/"); @@ -225,8 +246,8 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { EXPECT_EQ(info.proxy_server(), "foopy1:8080"); // Fake an error on the proxy, and also a new configuration on the proxy. - resolver->config = net::ProxyConfig(); - resolver->config.pac_url = GURL("http://foopy-new/proxy.pac"); + config_service->config = net::ProxyConfig(); + config_service->config.pac_url = GURL("http://foopy-new/proxy.pac"); rv = service.ReconsiderProxyAfterError(url, &info, NULL, NULL); EXPECT_EQ(rv, net::OK); @@ -240,8 +261,8 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { EXPECT_EQ(info.proxy_server(), "foopy2:9090"); // We simulate a new configuration. - resolver->config = net::ProxyConfig(); - resolver->config.pac_url = GURL("http://foopy-new2/proxy.pac"); + config_service->config = net::ProxyConfig(); + config_service->config.pac_url = GURL("http://foopy-new2/proxy.pac"); // We fake anothe error. It should go back to the first proxy. rv = service.ReconsiderProxyAfterError(url, &info, NULL, NULL); @@ -252,13 +273,15 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { TEST(ProxyServiceTest, ProxyFallback_BadConfig) { // Test proxy failover when the configuration is bad. + MockProxyConfigService* config_service = + new MockProxyConfigService("http://foopy/proxy.pac"); + MockProxyResolver* resolver = new MockProxyResolver; - resolver->config.pac_url = GURL("http://foopy/proxy.pac"); resolver->info.UseNamedProxy("foopy1:8080;foopy2:9090"); resolver->info_predicate_query_host = "www.google.com"; resolver->fail_get_proxy_for_url = false; - net::ProxyService service(resolver); + net::ProxyService service(config_service, resolver); GURL url("http://www.google.com/"); @@ -318,7 +341,8 @@ TEST(ProxyServiceTest, ProxyBypassList) { config.auto_detect = false; config.proxy_bypass_local_names = true; - net::ProxyService service(new MockProxyResolver(config)); + net::ProxyService service(new MockProxyConfigService(config), + new MockProxyResolver()); GURL url("http://www.google.com/"); // Get the proxy information. net::ProxyInfo info; @@ -326,7 +350,8 @@ TEST(ProxyServiceTest, ProxyBypassList) { EXPECT_EQ(rv, net::OK); EXPECT_FALSE(info.is_direct()); - net::ProxyService service1(new MockProxyResolver(config)); + net::ProxyService service1(new MockProxyConfigService(config), + new MockProxyResolver()); GURL test_url1("local"); net::ProxyInfo info1; rv = service1.ResolveProxy(test_url1, &info1, NULL, NULL); @@ -336,8 +361,8 @@ TEST(ProxyServiceTest, ProxyBypassList) { config.proxy_bypass.clear(); config.proxy_bypass.push_back("*.org"); config.proxy_bypass_local_names = true; - MockProxyResolver* resolver = new MockProxyResolver(config); - net::ProxyService service2(resolver); + net::ProxyService service2(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url2("http://www.webkit.org"); net::ProxyInfo info2; rv = service2.ResolveProxy(test_url2, &info2, NULL, NULL); @@ -348,8 +373,8 @@ TEST(ProxyServiceTest, ProxyBypassList) { config.proxy_bypass.push_back("*.org"); config.proxy_bypass.push_back("7*"); config.proxy_bypass_local_names = true; - resolver = new MockProxyResolver(config); - net::ProxyService service3(resolver); + net::ProxyService service3(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url3("http://74.125.19.147"); net::ProxyInfo info3; rv = service3.ResolveProxy(test_url3, &info3, NULL, NULL); @@ -359,8 +384,8 @@ TEST(ProxyServiceTest, ProxyBypassList) { config.proxy_bypass.clear(); config.proxy_bypass.push_back("*.org"); config.proxy_bypass_local_names = true; - resolver = new MockProxyResolver(config); - net::ProxyService service4(resolver); + net::ProxyService service4(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url4("http://www.msn.com"); net::ProxyInfo info4; rv = service4.ResolveProxy(test_url4, &info4, NULL, NULL); @@ -370,8 +395,8 @@ TEST(ProxyServiceTest, ProxyBypassList) { config.proxy_bypass.clear(); config.proxy_bypass.push_back("*.MSN.COM"); config.proxy_bypass_local_names = true; - resolver = new MockProxyResolver(config); - net::ProxyService service5(resolver); + net::ProxyService service5(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url5("http://www.msnbc.msn.com"); net::ProxyInfo info5; rv = service5.ResolveProxy(test_url5, &info5, NULL, NULL); @@ -381,8 +406,8 @@ TEST(ProxyServiceTest, ProxyBypassList) { config.proxy_bypass.clear(); config.proxy_bypass.push_back("*.msn.com"); config.proxy_bypass_local_names = true; - resolver = new MockProxyResolver(config); - net::ProxyService service6(resolver); + net::ProxyService service6(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url6("HTTP://WWW.MSNBC.MSN.COM"); net::ProxyInfo info6; rv = service6.ResolveProxy(test_url6, &info6, NULL, NULL); @@ -395,7 +420,8 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { config.proxy_server = "http=foopy1:8080;https=foopy2:8080"; config.auto_detect = false; - net::ProxyService service1(new MockProxyResolver(config)); + net::ProxyService service1(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url1("http://www.msn.com"); net::ProxyInfo info1; int rv = service1.ResolveProxy(test_url1, &info1, NULL, NULL); @@ -403,7 +429,8 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { EXPECT_FALSE(info1.is_direct()); EXPECT_TRUE(info1.proxy_server() == "foopy1:8080"); - net::ProxyService service2(new MockProxyResolver(config)); + net::ProxyService service2(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url2("ftp://ftp.google.com"); net::ProxyInfo info2; rv = service2.ResolveProxy(test_url2, &info2, NULL, NULL); @@ -411,7 +438,8 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { EXPECT_TRUE(info2.is_direct()); EXPECT_TRUE(info2.proxy_server() == ""); - net::ProxyService service3(new MockProxyResolver(config)); + net::ProxyService service3(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url3("https://webbranch.techcu.com"); net::ProxyInfo info3; rv = service3.ResolveProxy(test_url3, &info3, NULL, NULL); @@ -419,9 +447,9 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { EXPECT_FALSE(info3.is_direct()); EXPECT_TRUE(info3.proxy_server() == "foopy2:8080"); - MockProxyResolver* resolver = new MockProxyResolver(config); - resolver->config.proxy_server = "foopy1:8080"; - net::ProxyService service4(resolver); + config.proxy_server = "foopy1:8080"; + net::ProxyService service4(new MockProxyConfigService(config), + new MockProxyResolver); GURL test_url4("www.microsoft.com"); net::ProxyInfo info4; rv = service4.ResolveProxy(test_url4, &info4, NULL, NULL); diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index d344319..be26da9 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -29,7 +29,6 @@ #include "net/disk_cache/disk_cache.h" #include "net/http/http_cache.h" #include "net/http/http_network_layer.h" -#include "net/proxy/proxy_resolver_null.h" #include "net/proxy/proxy_service.h" #include "net/url_request/url_request.h" #include "testing/gtest/include/gtest/gtest.h" @@ -42,7 +41,7 @@ namespace { class URLRequestHttpCacheContext : public URLRequestContext { public: URLRequestHttpCacheContext() { - proxy_service_ = new net::ProxyService(new net::ProxyResolverNull); + proxy_service_ = net::ProxyService::CreateNull(); http_transaction_factory_ = new net::HttpCache(net::HttpNetworkLayer::CreateFactory(proxy_service_), disk_cache::CreateInMemoryCacheBackend(0)); diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 52fa429..a33be39 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -23,7 +23,6 @@ #include "net/base/net_errors.h" #include "net/http/http_network_layer.h" #include "net/url_request/url_request.h" -#include "net/proxy/proxy_resolver_null.h" #include "net/proxy/proxy_service.h" #include "testing/gtest/include/gtest/gtest.h" #include "googleurl/src/url_util.h" @@ -35,7 +34,7 @@ const std::string kDefaultHostName("localhost"); class TestURLRequestContext : public URLRequestContext { public: TestURLRequestContext() { - proxy_service_ = new net::ProxyService(new net::ProxyResolverNull); + proxy_service_ = net::ProxyService::CreateNull(); http_transaction_factory_ = net::HttpNetworkLayer::CreateFactory(proxy_service_); } |