diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-23 23:52:57 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-23 23:52:57 +0000 |
commit | 2fb62920c987513f7b5f041c99be5a8ed09888ec (patch) | |
tree | 7c0355bb9fb4ecae13aeecc572a8261e94d89436 | |
parent | 24d5cc6bb1328948d7a0658a7fa3acf6de5b91f8 (diff) | |
download | chromium_src-2fb62920c987513f7b5f041c99be5a8ed09888ec.zip chromium_src-2fb62920c987513f7b5f041c99be5a8ed09888ec.tar.gz chromium_src-2fb62920c987513f7b5f041c99be5a8ed09888ec.tar.bz2 |
Create a URLRequestContext for PAC fetching.
Originally I was going to create a single "system" URLRequestContext. I realized that was wrong, I need one for proxy script fetching that uses a direct ProxyService. This way, we don't have the circular dependencies for URLRequestContext(A)=>ProxyService=>ProxyScriptFetcherImpl=>URLRequestContext(A). Instead, we have URLRequestContext(A)=>ProxyService=>ProxyScriptFetcherImpl=>URLRequestContext(special one for proxy).
This also exposes some setters in URLRequestContext that were in ChromeURLRequestContext. I guess this makes URLRequestContext a bit more "dangerous" since it could be mutated during runtime, but really we should probably pass around a const URLRequestContext within the network stack. I've filed http://crbug.com/67597 to track this.
BUG=67232
TEST=none
Review URL: http://codereview.chromium.org/5961005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70116 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/dom_ui/net_internals_ui.cc | 3 | ||||
-rw-r--r-- | chrome/browser/io_thread.cc | 95 | ||||
-rw-r--r-- | chrome/browser/io_thread.h | 21 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.cc | 12 | ||||
-rw-r--r-- | chrome/browser/net/chrome_url_request_context.h | 24 | ||||
-rw-r--r-- | chrome/browser/net/connection_tester.cc | 24 | ||||
-rw-r--r-- | chrome/browser/net/connection_tester.h | 8 | ||||
-rw-r--r-- | chrome/browser/net/connection_tester_unittest.cc | 73 | ||||
-rw-r--r-- | net/proxy/proxy_service.cc | 6 | ||||
-rw-r--r-- | net/proxy/proxy_service.h | 2 | ||||
-rw-r--r-- | net/url_request/url_request_context.cc | 4 | ||||
-rw-r--r-- | net/url_request/url_request_context.h | 41 |
12 files changed, 182 insertions, 131 deletions
diff --git a/chrome/browser/dom_ui/net_internals_ui.cc b/chrome/browser/dom_ui/net_internals_ui.cc index f44ac9e..0cea72a 100644 --- a/chrome/browser/dom_ui/net_internals_ui.cc +++ b/chrome/browser/dom_ui/net_internals_ui.cc @@ -833,7 +833,8 @@ void NetInternalsMessageHandler::IOThreadImpl::OnStartConnectionTests( // For example, turn "www.google.com" into "http://www.google.com". GURL url(URLFixerUpper::FixupURL(UTF16ToUTF8(url_str), std::string())); - connection_tester_.reset(new ConnectionTester(this, io_thread_)); + connection_tester_.reset(new ConnectionTester( + this, io_thread_->globals()->proxy_script_fetcher_context.get())); connection_tester_->RunAllTests(url); } diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index 1b1acf2..e337ba5 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -37,10 +37,13 @@ #include "net/base/net_util.h" #include "net/http/http_auth_filter.h" #include "net/http/http_auth_handler_factory.h" +#include "net/http/http_network_layer.h" #if defined(USE_NSS) #include "net/ocsp/nss_ocsp.h" #endif // defined(USE_NSS) #include "net/proxy/proxy_script_fetcher_impl.h" +#include "net/socket/client_socket_factory.h" +#include "net/spdy/spdy_session_pool.h" namespace { @@ -174,35 +177,37 @@ class LoggingNetworkChangeObserver DISALLOW_COPY_AND_ASSIGN(LoggingNetworkChangeObserver); }; -} // namespace - -// This is a wrapper class around ProxyScriptFetcherImpl that will -// keep track of live instances. -class IOThread::ManagedProxyScriptFetcher - : public net::ProxyScriptFetcherImpl { - public: - ManagedProxyScriptFetcher(URLRequestContext* context, - IOThread* io_thread) - : net::ProxyScriptFetcherImpl(context), - io_thread_(io_thread) { - DCHECK(!ContainsKey(*fetchers(), this)); - fetchers()->insert(this); - } - - virtual ~ManagedProxyScriptFetcher() { - DCHECK(ContainsKey(*fetchers(), this)); - fetchers()->erase(this); - } - - private: - ProxyScriptFetchers* fetchers() { - return &io_thread_->fetchers_; - } - - IOThread* io_thread_; +scoped_refptr<URLRequestContext> +ConstructProxyScriptFetcherContext(IOThread::Globals* globals, + net::NetLog* net_log) { + scoped_refptr<URLRequestContext> context(new URLRequestContext); + context->set_net_log(net_log); + context->set_host_resolver(globals->host_resolver.get()); + context->set_cert_verifier(globals->cert_verifier.get()); + context->set_dnsrr_resolver(globals->dnsrr_resolver.get()); + context->set_http_auth_handler_factory( + globals->http_auth_handler_factory.get()); + context->set_proxy_service(globals->proxy_script_fetcher_proxy_service.get()); + context->set_http_transaction_factory( + new net::HttpNetworkLayer( + globals->client_socket_factory, + globals->host_resolver.get(), + globals->cert_verifier.get(), + globals->dnsrr_resolver.get(), + NULL /* dns_cert_checker */, + NULL /* ssl_host_info_factory */, + globals->proxy_script_fetcher_proxy_service.get(), + globals->ssl_config_service.get(), + new net::SpdySessionPool(globals->ssl_config_service.get()), + globals->http_auth_handler_factory.get(), + &globals->network_delegate, + net_log)); + // In-memory cookie store. + context->set_cookie_store(new net::CookieMonster(NULL, NULL)); + return context; +} - DISALLOW_COPY_AND_ASSIGN(ManagedProxyScriptFetcher); -}; +} // namespace // The IOThread object must outlive any tasks posted to the IO thread before the // Quit task. @@ -301,11 +306,6 @@ void IOThread::ChangedToOnTheRecord() { &IOThread::ChangedToOnTheRecordOnIOThread)); } -net::ProxyScriptFetcher* IOThread::CreateAndRegisterProxyScriptFetcher( - URLRequestContext* url_request_context) { - return new ManagedProxyScriptFetcher(url_request_context, this); -} - void IOThread::Init() { #if !defined(OS_CHROMEOS) // TODO(evan): test and enable this on all platforms. @@ -331,12 +331,24 @@ void IOThread::Init() { network_change_observer_.reset( new LoggingNetworkChangeObserver(net_log_)); + globals_->client_socket_factory = + net::ClientSocketFactory::GetDefaultFactory(); globals_->host_resolver.reset( CreateGlobalHostResolver(net_log_)); globals_->cert_verifier.reset(new net::CertVerifier); globals_->dnsrr_resolver.reset(new net::DnsRRResolver); + // TODO(willchan): Use the real SSLConfigService. + globals_->ssl_config_service = + net::SSLConfigService::CreateSystemSSLConfigService(); globals_->http_auth_handler_factory.reset(CreateDefaultAuthHandlerFactory( globals_->host_resolver.get())); + // For the ProxyScriptFetcher, we use a direct ProxyService. + globals_->proxy_script_fetcher_proxy_service = + net::ProxyService::CreateDirectWithNetLog(net_log_); + + scoped_refptr<URLRequestContext> proxy_script_fetcher_context = + ConstructProxyScriptFetcherContext(globals_, net_log_); + globals_->proxy_script_fetcher_context = proxy_script_fetcher_context; if (CommandLine::ForCurrentProcess()->HasSwitch( switches::kEnablePagePrerender)) { @@ -355,23 +367,6 @@ void IOThread::CleanUp() { // Destroy all URLRequests started by URLFetchers. URLFetcher::CancelAll(); - // Break any cycles between the ProxyScriptFetcher and URLRequestContext. - for (ProxyScriptFetchers::const_iterator it = fetchers_.begin(); - it != fetchers_.end();) { - ManagedProxyScriptFetcher* fetcher = *it; - { - // Hang on to the context while cancelling to avoid problems - // with the cancellation causing the context to be destroyed - // (see http://crbug.com/63796 ). Ideally, the IOThread would - // own the URLRequestContexts. - scoped_refptr<URLRequestContext> context(fetcher->GetRequestContext()); - fetcher->Cancel(); - } - // Any number of fetchers may have been deleted at this point, so - // use upper_bound instead of a simple increment. - it = fetchers_.upper_bound(fetcher); - } - // If any child processes are still running, terminate them and // and delete the BrowserChildProcessHost instances to release whatever // IO thread only resources they are referencing. diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index d6361b0..8e52ca0 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -7,7 +7,6 @@ #pragma once #include <list> -#include <set> #include <string> #include "base/basictypes.h" #include "base/ref_counted.h" @@ -31,10 +30,13 @@ class Predictor; namespace net { class CertVerifier; +class ClientSocketFactory; class DnsRRResolver; class HostResolver; class HttpAuthHandlerFactory; class ProxyScriptFetcher; +class ProxyService; +class SSLConfigService; class URLSecurityManager; } // namespace net @@ -44,12 +46,16 @@ class IOThread : public BrowserProcessSubThread { Globals(); ~Globals(); + net::ClientSocketFactory* client_socket_factory; scoped_ptr<net::HostResolver> host_resolver; scoped_ptr<net::CertVerifier> cert_verifier; scoped_ptr<net::DnsRRResolver> dnsrr_resolver; + scoped_refptr<net::SSLConfigService> ssl_config_service; scoped_ptr<net::HttpAuthHandlerFactory> http_auth_handler_factory; + scoped_refptr<net::ProxyService> proxy_script_fetcher_proxy_service; scoped_ptr<net::URLSecurityManager> url_security_manager; ChromeNetworkDelegate network_delegate; + scoped_refptr<URLRequestContext> proxy_script_fetcher_context; }; // |net_log| must either outlive the IOThread or be NULL. @@ -93,22 +99,12 @@ class IOThread : public BrowserProcessSubThread { // IOThread's message loop. void ChangedToOnTheRecord(); - // Creates a ProxyScriptFetcherImpl which will be automatically aborted - // during shutdown. - // This is used to avoid cycles between the ProxyScriptFetcher and the - // URLRequestContext that owns it (indirectly via the ProxyService). - net::ProxyScriptFetcher* CreateAndRegisterProxyScriptFetcher( - URLRequestContext* url_request_context); - protected: virtual void Init(); virtual void CleanUp(); virtual void CleanUpAfterMessageLoopDestruction(); private: - class ManagedProxyScriptFetcher; - typedef std::set<ManagedProxyScriptFetcher*> ProxyScriptFetchers; - static void RegisterPrefs(PrefService* local_state); net::HttpAuthHandlerFactory* CreateDefaultAuthHandlerFactory( @@ -160,9 +156,6 @@ class IOThread : public BrowserProcessSubThread { chrome_browser_net::Predictor* predictor_; scoped_ptr<PrerenderInterceptor> prerender_interceptor_; - // List of live ProxyScriptFetchers. - ProxyScriptFetchers fetchers_; - // Keeps track of all live ChromeURLRequestContextGetters, so the // ChromeURLRequestContexts can be released during // IOThread::CleanUpAfterMessageLoopDestruction(). diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc index aa718b5..d06d806 100644 --- a/chrome/browser/net/chrome_url_request_context.cc +++ b/chrome/browser/net/chrome_url_request_context.cc @@ -33,7 +33,7 @@ #include "net/http/http_network_layer.h" #include "net/http/http_util.h" #include "net/proxy/proxy_config_service_fixed.h" -#include "net/proxy/proxy_script_fetcher.h" +#include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_service.h" #include "net/url_request/url_request.h" #include "webkit/glue/webkit_glue.h" @@ -95,8 +95,7 @@ net::ProxyService* CreateProxyService( net::NetLog* net_log, URLRequestContext* context, net::ProxyConfigService* proxy_config_service, - const CommandLine& command_line, - IOThread* io_thread) { + const CommandLine& command_line) { CheckCurrentlyOnIOThread(); bool use_v8 = !command_line.HasSwitch(switches::kWinHttpProxyResolver); @@ -127,7 +126,7 @@ net::ProxyService* CreateProxyService( return net::ProxyService::CreateUsingV8ProxyResolver( proxy_config_service, num_pac_threads, - io_thread->CreateAndRegisterProxyScriptFetcher(context), + new net::ProxyScriptFetcherImpl(context), context->host_resolver(), net_log); } @@ -275,10 +274,9 @@ ChromeURLRequestContext* FactoryForOriginal::Create() { context->set_proxy_service( CreateProxyService(io_thread()->net_log(), - context, + io_thread_globals->proxy_script_fetcher_context.get(), proxy_config_service_.release(), - command_line, - io_thread())); + command_line)); net::HttpCache::DefaultBackend* backend = new net::HttpCache::DefaultBackend( net::DISK_CACHE, disk_cache_path_, cache_size_, diff --git a/chrome/browser/net/chrome_url_request_context.h b/chrome/browser/net/chrome_url_request_context.h index 01998c0..8d1377b 100644 --- a/chrome/browser/net/chrome_url_request_context.h +++ b/chrome/browser/net/chrome_url_request_context.h @@ -120,37 +120,16 @@ class ChromeURLRequestContext : public URLRequestContext { void set_ssl_config_service(net::SSLConfigService* service) { ssl_config_service_ = service; } - void set_host_resolver(net::HostResolver* resolver) { - host_resolver_ = resolver; - } - void set_cert_verifier(net::CertVerifier* cert_verifier) { - cert_verifier_ = cert_verifier; - } - void set_dnsrr_resolver(net::DnsRRResolver* dnsrr_resolver) { - dnsrr_resolver_ = dnsrr_resolver; - } void set_dns_cert_checker(net::DnsCertProvenanceChecker* ctx) { dns_cert_checker_.reset(ctx); } - void set_http_transaction_factory(net::HttpTransactionFactory* factory) { - http_transaction_factory_ = factory; - } void set_ftp_transaction_factory(net::FtpTransactionFactory* factory) { ftp_transaction_factory_ = factory; } - void set_http_auth_handler_factory(net::HttpAuthHandlerFactory* factory) { - http_auth_handler_factory_ = factory; - } - void set_cookie_store(net::CookieStore* cookie_store) { - cookie_store_ = cookie_store; - } void set_cookie_policy(ChromeCookiePolicy* cookie_policy) { chrome_cookie_policy_ = cookie_policy; // Take a strong reference. cookie_policy_ = cookie_policy; } - void set_proxy_service(net::ProxyService* service) { - proxy_service_ = service; - } void set_user_script_dir_path(const FilePath& path) { user_script_dir_path_ = path; } @@ -182,9 +161,6 @@ class ChromeURLRequestContext : public URLRequestContext { void set_extension_info_map(ExtensionInfoMap* map) { extension_info_map_ = map; } - void set_net_log(net::NetLog* net_log) { - net_log_ = net_log; - } void set_network_delegate( net::HttpNetworkDelegate* network_delegate) { network_delegate_ = network_delegate; diff --git a/chrome/browser/net/connection_tester.cc b/chrome/browser/net/connection_tester.cc index abebac7..588cf57 100644 --- a/chrome/browser/net/connection_tester.cc +++ b/chrome/browser/net/connection_tester.cc @@ -8,9 +8,9 @@ #include "base/compiler_specific.h" #include "base/logging.h" #include "base/message_loop.h" +#include "base/thread_restrictions.h" #include "base/utf_string_conversions.h" #include "chrome/browser/importer/firefox_proxy_settings.h" -#include "chrome/browser/io_thread.h" #include "chrome/common/chrome_switches.h" #include "net/base/cert_verifier.h" #include "net/base/cookie_monster.h" @@ -27,6 +27,7 @@ #include "net/http/http_cache.h" #include "net/http/http_network_layer.h" #include "net/proxy/proxy_config_service_fixed.h" +#include "net/proxy/proxy_script_fetcher_impl.h" #include "net/url_request/url_request.h" #include "net/url_request/url_request_context.h" @@ -39,8 +40,8 @@ namespace { // to the specified "experiment". class ExperimentURLRequestContext : public URLRequestContext { public: - explicit ExperimentURLRequestContext(IOThread* io_thread) - : io_thread_(io_thread) {} + explicit ExperimentURLRequestContext(URLRequestContext* proxy_request_context) + : proxy_request_context_(proxy_request_context) {} int Init(const ConnectionTester::Experiment& experiment) { int rv; @@ -129,10 +130,14 @@ class ExperimentURLRequestContext : public URLRequestContext { int CreateProxyConfigService( ConnectionTester::ProxySettingsExperiment experiment, scoped_ptr<net::ProxyConfigService>* config_service) { + scoped_ptr<base::ThreadRestrictions::ScopedAllowIO> allow_io; switch (experiment) { case ConnectionTester::PROXY_EXPERIMENT_USE_SYSTEM_SETTINGS: return CreateSystemProxyConfigService(config_service); case ConnectionTester::PROXY_EXPERIMENT_USE_FIREFOX_SETTINGS: + // http://crbug.com/67664: This call can lead to blocking IO on the IO + // thread. This is a bug and should be fixed. + allow_io.reset(new base::ThreadRestrictions::ScopedAllowIO); return CreateFirefoxProxyConfigService(config_service); case ConnectionTester::PROXY_EXPERIMENT_USE_AUTO_DETECT: config_service->reset(new net::ProxyConfigServiceFixed( @@ -170,7 +175,7 @@ class ExperimentURLRequestContext : public URLRequestContext { *proxy_service = net::ProxyService::CreateUsingV8ProxyResolver( config_service.release(), 0u, - io_thread_->CreateAndRegisterProxyScriptFetcher(this), + new net::ProxyScriptFetcherImpl(proxy_request_context_), host_resolver(), NULL); @@ -217,7 +222,7 @@ class ExperimentURLRequestContext : public URLRequestContext { return net::ERR_FAILED; } - IOThread* io_thread_; + const scoped_refptr<URLRequestContext> proxy_request_context_; }; } // namespace @@ -305,7 +310,7 @@ void ConnectionTester::TestRunner::OnResponseCompleted( void ConnectionTester::TestRunner::Run(const Experiment& experiment) { // Try to create a URLRequestContext for this experiment. scoped_refptr<ExperimentURLRequestContext> context( - new ExperimentURLRequestContext(tester_->io_thread_)); + new ExperimentURLRequestContext(tester_->proxy_request_context_)); int rv = context->Init(experiment); if (rv != net::OK) { // Complete the experiment with a failure. @@ -321,10 +326,11 @@ void ConnectionTester::TestRunner::Run(const Experiment& experiment) { // ConnectionTester ---------------------------------------------------------- -ConnectionTester::ConnectionTester(Delegate* delegate, IOThread* io_thread) - : delegate_(delegate), io_thread_(io_thread) { +ConnectionTester::ConnectionTester(Delegate* delegate, + URLRequestContext* proxy_request_context) + : delegate_(delegate), proxy_request_context_(proxy_request_context) { DCHECK(delegate); - DCHECK(io_thread); + DCHECK(proxy_request_context); } ConnectionTester::~ConnectionTester() { diff --git a/chrome/browser/net/connection_tester.h b/chrome/browser/net/connection_tester.h index e0a7446..1d206ac 100644 --- a/chrome/browser/net/connection_tester.h +++ b/chrome/browser/net/connection_tester.h @@ -13,7 +13,7 @@ #include "googleurl/src/gurl.h" #include "net/base/completion_callback.h" -class IOThread; +class URLRequestContext; // ConnectionTester runs a suite of tests (also called "experiments"), // to try and discover why loading a particular URL is failing with an error @@ -125,7 +125,8 @@ class ConnectionTester { // Constructs a ConnectionTester that notifies test progress to |delegate|. // |delegate| is owned by the caller, and must remain valid for the lifetime // of ConnectionTester. - ConnectionTester(Delegate* delegate, IOThread* io_thread); + ConnectionTester(Delegate* delegate, + URLRequestContext* proxy_request_context); // Note that destruction cancels any in-progress tests. ~ConnectionTester(); @@ -171,10 +172,9 @@ class ConnectionTester { // of the list is the one currently in progress. ExperimentList remaining_experiments_; - IOThread* io_thread_; + const scoped_refptr<URLRequestContext> proxy_request_context_; DISALLOW_COPY_AND_ASSIGN(ConnectionTester); }; #endif // CHROME_BROWSER_NET_CONNECTION_TESTER_H_ - diff --git a/chrome/browser/net/connection_tester_unittest.cc b/chrome/browser/net/connection_tester_unittest.cc index 409c676..0ee05d2 100644 --- a/chrome/browser/net/connection_tester_unittest.cc +++ b/chrome/browser/net/connection_tester_unittest.cc @@ -4,10 +4,21 @@ #include "chrome/browser/net/connection_tester.h" -#include "chrome/browser/io_thread.h" +#include "chrome/browser/browser_thread.h" #include "chrome/test/testing_pref_service.h" +#include "net/base/cert_verifier.h" +#include "net/base/cookie_monster.h" +#include "net/base/dnsrr_resolver.h" #include "net/base/mock_host_resolver.h" +#include "net/base/ssl_config_service_defaults.h" +#include "net/ftp/ftp_network_layer.h" +#include "net/http/http_auth_handler_factory.h" +#include "net/http/http_network_layer.h" +#include "net/proxy/proxy_config_service_fixed.h" +#include "net/socket/client_socket_factory.h" +#include "net/spdy/spdy_session_pool.h" #include "net/test/test_server.h" +#include "net/url_request/url_request_context.h" #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" @@ -76,30 +87,63 @@ class ConnectionTesterTest : public PlatformTest { ConnectionTesterTest() : test_server_(net::TestServer::TYPE_HTTP, FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))), + client_socket_factory_(net::ClientSocketFactory::GetDefaultFactory()), + proxy_script_fetcher_context_(new URLRequestContext), message_loop_(MessageLoop::TYPE_IO), - pref_service(new TestingPrefService()), - io_thread_(pref_service.get(), NULL) { - scoped_refptr<net::RuleBasedHostResolverProc> catchall_resolver( - new net::RuleBasedHostResolverProc(NULL)); - - catchall_resolver->AddRule("*", "127.0.0.1"); - - scoped_host_resolver_proc_.Init(catchall_resolver); + io_thread_(BrowserThread::IO, &message_loop_) { + InitializeRequestContext(); } protected: - net::ScopedDefaultHostResolverProc scoped_host_resolver_proc_; net::TestServer test_server_; ConnectionTesterDelegate test_delegate_; + net::ClientSocketFactory* const client_socket_factory_; + net::MockHostResolver host_resolver_; + net::CertVerifier cert_verifier_; + net::DnsRRResolver dnsrr_resolver_; + scoped_refptr<net::ProxyService> proxy_service_; + scoped_refptr<net::SSLConfigService> ssl_config_service_; + scoped_ptr<net::HttpTransactionFactory> http_transaction_factory_; + net::HttpAuthHandlerRegistryFactory http_auth_handler_factory_; + scoped_refptr<URLRequestContext> proxy_script_fetcher_context_; + + private: + void InitializeRequestContext() { + proxy_script_fetcher_context_->set_host_resolver(&host_resolver_); + proxy_script_fetcher_context_->set_cert_verifier(&cert_verifier_); + proxy_script_fetcher_context_->set_dnsrr_resolver(&dnsrr_resolver_); + proxy_script_fetcher_context_->set_http_auth_handler_factory( + &http_auth_handler_factory_); + proxy_service_ = net::ProxyService::CreateDirect(); + proxy_script_fetcher_context_->set_proxy_service(proxy_service_); + ssl_config_service_ = net::SSLConfigService::CreateSystemSSLConfigService(); + proxy_script_fetcher_context_->set_http_transaction_factory( + new net::HttpNetworkLayer( + client_socket_factory_, + &host_resolver_, + &cert_verifier_, + &dnsrr_resolver_, + NULL /* DNS cert provenance checker */, + NULL /* ssl_host_info_factory */, + proxy_service_.get(), + ssl_config_service_, + new net::SpdySessionPool(ssl_config_service_), + &http_auth_handler_factory_, + NULL /* NetworkDelegate */, + NULL /* NetLog */)); + // In-memory cookie store. + proxy_script_fetcher_context_->set_cookie_store( + new net::CookieMonster(NULL, NULL)); + } + MessageLoop message_loop_; - scoped_ptr<PrefService> pref_service; - IOThread io_thread_; // Needed for creating ProxyScriptFetchers. + BrowserThread io_thread_; }; TEST_F(ConnectionTesterTest, RunAllTests) { ASSERT_TRUE(test_server_.Start()); - ConnectionTester tester(&test_delegate_, &io_thread_); + ConnectionTester tester(&test_delegate_, proxy_script_fetcher_context_); // Start the test suite on URL "echoall". // TODO(eroman): Is this URL right? @@ -124,7 +168,7 @@ TEST_F(ConnectionTesterTest, DeleteWhileInProgress) { ASSERT_TRUE(test_server_.Start()); scoped_ptr<ConnectionTester> tester( - new ConnectionTester(&test_delegate_, &io_thread_)); + new ConnectionTester(&test_delegate_, proxy_script_fetcher_context_)); // Start the test suite on URL "echoall". // TODO(eroman): Is this URL right? @@ -153,4 +197,3 @@ TEST_F(ConnectionTesterTest, DeleteWhileInProgress) { } } // namespace - diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index f321ef03..13d049e 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -468,9 +468,13 @@ ProxyService* ProxyService::CreateFixed(const std::string& proxy) { // static ProxyService* ProxyService::CreateDirect() { + return CreateDirectWithNetLog(NULL); +} + +ProxyService* ProxyService::CreateDirectWithNetLog(NetLog* net_log) { // Use direct connections. return new ProxyService(new ProxyConfigServiceDirect, new ProxyResolverNull, - NULL); + net_log); } // static diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index 8a161ea..ba56f4d6 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -193,6 +193,8 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>, // Creates a proxy service that uses a DIRECT connection for all requests. static ProxyService* CreateDirect(); + // |net_log|'s lifetime must exceed ProxyService. + static ProxyService* CreateDirectWithNetLog(NetLog* net_log); // This method is used by tests to create a ProxyService that returns a // hardcoded proxy fallback list (|pac_string|) for every URL. diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc index 04f0da0..3bc7da6 100644 --- a/net/url_request/url_request_context.cc +++ b/net/url_request/url_request_context.cc @@ -29,3 +29,7 @@ const std::string& URLRequestContext::GetUserAgent(const GURL& url) const { URLRequestContext::~URLRequestContext() { } + +void URLRequestContext::set_cookie_store(net::CookieStore* cookie_store) { + cookie_store_ = cookie_store; +} diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index d3ba85f..307da44 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -47,18 +47,34 @@ class URLRequestContext return net_log_; } + void set_net_log(net::NetLog* net_log) { + net_log_ = net_log; + } + net::HostResolver* host_resolver() const { return host_resolver_; } + void set_host_resolver(net::HostResolver* host_resolver) { + host_resolver_ = host_resolver; + } + net::CertVerifier* cert_verifier() const { return cert_verifier_; } + void set_cert_verifier(net::CertVerifier* cert_verifier) { + cert_verifier_ = cert_verifier; + } + net::DnsRRResolver* dnsrr_resolver() const { return dnsrr_resolver_; } + void set_dnsrr_resolver(net::DnsRRResolver* dnsrr_resolver) { + dnsrr_resolver_ = dnsrr_resolver; + } + net::DnsCertProvenanceChecker* dns_cert_checker() const { return dns_cert_checker_.get(); } @@ -68,16 +84,33 @@ class URLRequestContext return proxy_service_; } + void set_proxy_service(net::ProxyService* proxy_service) { + proxy_service_ = proxy_service; + } + // Get the ssl config service for this context. net::SSLConfigService* ssl_config_service() const { return ssl_config_service_; } + // Gets the HTTP Authentication Handler Factory for this context. + // The factory is only valid for the lifetime of this URLRequestContext + net::HttpAuthHandlerFactory* http_auth_handler_factory() { + return http_auth_handler_factory_; + } + void set_http_auth_handler_factory(net::HttpAuthHandlerFactory* factory) { + http_auth_handler_factory_ = factory; + } + // Gets the http transaction factory for this context. net::HttpTransactionFactory* http_transaction_factory() const { return http_transaction_factory_; } + void set_http_transaction_factory(net::HttpTransactionFactory* factory) { + http_transaction_factory_ = factory; + } + // Gets the ftp transaction factory for this context. net::FtpTransactionFactory* ftp_transaction_factory() { return ftp_transaction_factory_; @@ -87,6 +120,8 @@ class URLRequestContext // cookies are not stored). net::CookieStore* cookie_store() { return cookie_store_.get(); } + void set_cookie_store(net::CookieStore* cookie_store); + // Gets the cookie policy for this context (may be null, in which case // cookies are allowed). net::CookiePolicy* cookie_policy() { return cookie_policy_; } @@ -97,12 +132,6 @@ class URLRequestContext // Gets the FTP authentication cache for this context. net::FtpAuthCache* ftp_auth_cache() { return &ftp_auth_cache_; } - // Gets the HTTP Authentication Handler Factory for this context. - // The factory is only valid for the lifetime of this URLRequestContext - net::HttpAuthHandlerFactory* http_auth_handler_factory() { - return http_auth_handler_factory_; - } - // Gets the value of 'Accept-Charset' header field. const std::string& accept_charset() const { return accept_charset_; } |