diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 19:21:10 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-08 19:21:10 +0000 |
commit | b3764212576419eee2fe5b2b1c43d5aef28954a8 (patch) | |
tree | c59c39e8201d08f1fa4b417833b859ea909066fb /net/proxy/proxy_service.cc | |
parent | b5edb847c268532709058074328dd5565b7d9e7e (diff) | |
download | chromium_src-b3764212576419eee2fe5b2b1c43d5aef28954a8.zip chromium_src-b3764212576419eee2fe5b2b1c43d5aef28954a8.tar.gz chromium_src-b3764212576419eee2fe5b2b1c43d5aef28954a8.tar.bz2 |
Add the capability to run multiple proxy PAC scripts in parallel.
Refactors SingleThreadedProxyResolver into MultiThreadedProxyResolver.
New threads are created lazily on demand, up to a fixed maximum.
Note that this CL does NOT change the policy in Chrome -- it will continue to use a single thread for proxy resolving, but using the new code to do so.
BUG=11079
Review URL: http://codereview.chromium.org/2822043
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51877 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_service.cc')
-rw-r--r-- | net/proxy/proxy_service.cc | 96 |
1 files changed, 61 insertions, 35 deletions
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 26cb1b6..060745b 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -15,6 +15,7 @@ #include "net/base/net_errors.h" #include "net/base/net_util.h" #include "net/proxy/init_proxy_resolver.h" +#include "net/proxy/multi_threaded_proxy_resolver.h" #include "net/proxy/proxy_config_service_fixed.h" #include "net/proxy/proxy_script_fetcher.h" #if defined(OS_WIN) @@ -29,7 +30,6 @@ #include "net/proxy/proxy_resolver.h" #include "net/proxy/proxy_resolver_js_bindings.h" #include "net/proxy/proxy_resolver_v8.h" -#include "net/proxy/single_threaded_proxy_resolver.h" #include "net/proxy/sync_host_resolver_bridge.h" #include "net/url_request/url_request_context.h" @@ -75,6 +75,55 @@ class ProxyResolverNull : public ProxyResolver { } }; +// This factory creates V8ProxyResolvers with appropriate javascript bindings. +class ProxyResolverFactoryForV8 : public ProxyResolverFactory { + public: + // Both |async_host_resolver| and |host_resolver_loop| must remain valid for + // duration of our lifetime. + ProxyResolverFactoryForV8(HostResolver* async_host_resolver, + MessageLoop* host_resolver_loop) + : ProxyResolverFactory(true /*expects_pac_bytes*/), + async_host_resolver_(async_host_resolver), + host_resolver_loop_(host_resolver_loop) { + } + + virtual ProxyResolver* CreateProxyResolver() { + // Create a synchronous host resolver wrapper that operates + // |async_host_resolver_| on |host_resolver_loop_|. + SyncHostResolverBridge* sync_host_resolver = + new SyncHostResolverBridge(async_host_resolver_, host_resolver_loop_); + + ProxyResolverJSBindings* js_bindings = + ProxyResolverJSBindings::CreateDefault(sync_host_resolver); + + // ProxyResolverV8 takes ownership of |js_bindings|. + return new ProxyResolverV8(js_bindings); + } + + private: + scoped_refptr<HostResolver> async_host_resolver_; + MessageLoop* host_resolver_loop_; +}; + +// Creates ProxyResolvers using a non-V8 implementation. +class ProxyResolverFactoryForNonV8 : public ProxyResolverFactory { + public: + ProxyResolverFactoryForNonV8() + : ProxyResolverFactory(false /*expects_pac_bytes*/) {} + + virtual ProxyResolver* CreateProxyResolver() { +#if defined(OS_WIN) + return new ProxyResolverWinHttp(); +#elif defined(OS_MACOSX) + return new ProxyResolverMac(); +#else + LOG(WARNING) << "PAC support disabled because there is no fallback " + "non-V8 implementation"; + return new ProxyResolverNull(); +#endif + } +}; + // ProxyService::PacRequest --------------------------------------------------- class ProxyService::PacRequest @@ -218,32 +267,22 @@ ProxyService* ProxyService::Create( URLRequestContext* url_request_context, NetLog* net_log, MessageLoop* io_loop) { - ProxyResolver* proxy_resolver = NULL; + ProxyResolverFactory* sync_resolver_factory; if (use_v8_resolver) { - // Use the IO thread's host resolver (but since it is not threadsafe, - // bridge requests from the PAC thread over to the IO thread). - SyncHostResolverBridge* sync_host_resolver = - new SyncHostResolverBridge(url_request_context->host_resolver(), - io_loop); - - // Send javascript errors and alerts to LOG(INFO). - ProxyResolverJSBindings* js_bindings = - ProxyResolverJSBindings::CreateDefault(sync_host_resolver); - - // Wrap the (synchronous) ProxyResolver implementation in a single-threaded - // asynchronous resolver. This version of SingleThreadedProxyResolver - // additionally aborts any synchronous host resolves to avoid deadlock - // during shutdown. - proxy_resolver = - new SingleThreadedProxyResolverUsingBridgedHostResolver( - new ProxyResolverV8(js_bindings), - sync_host_resolver); + sync_resolver_factory = + new ProxyResolverFactoryForV8( + url_request_context->host_resolver(), + io_loop); } else { - proxy_resolver = - new SingleThreadedProxyResolver(CreateNonV8ProxyResolver()); + sync_resolver_factory = new ProxyResolverFactoryForNonV8(); } + const size_t kMaxNumResolverThreads = 1u; + ProxyResolver* proxy_resolver = + new MultiThreadedProxyResolver(sync_resolver_factory, + kMaxNumResolverThreads); + ProxyService* proxy_service = new ProxyService(proxy_config_service, proxy_resolver, net_log); @@ -559,19 +598,6 @@ ProxyConfigService* ProxyService::CreateSystemProxyConfigService( #endif } -// static -ProxyResolver* ProxyService::CreateNonV8ProxyResolver() { -#if defined(OS_WIN) - return new ProxyResolverWinHttp(); -#elif defined(OS_MACOSX) - return new ProxyResolverMac(); -#else - LOG(WARNING) << "PAC support disabled because there is no fallback " - "non-V8 implementation"; - return new ProxyResolverNull(); -#endif -} - void ProxyService::UpdateConfig(const BoundNetLog& net_log) { bool is_first_update = !config_has_been_initialized(); |