diff options
32 files changed, 316 insertions, 303 deletions
diff --git a/chrome/browser/chrome_browser_main.cc b/chrome/browser/chrome_browser_main.cc index da0a4dc..4eda935 100644 --- a/chrome/browser/chrome_browser_main.cc +++ b/chrome/browser/chrome_browser_main.cc @@ -208,13 +208,6 @@ void InitializeNetworkOptions(const CommandLine& parsed_command_line) { net::CookieMonster::EnableFileScheme(); } - if (parsed_command_line.HasSwitch(switches::kIgnoreCertificateErrors)) - net::HttpStreamFactory::set_ignore_certificate_errors(true); - - if (parsed_command_line.HasSwitch(switches::kHostRules)) - net::HttpStreamFactory::SetHostMappingRules( - parsed_command_line.GetSwitchValueASCII(switches::kHostRules)); - if (parsed_command_line.HasSwitch(switches::kEnableIPPooling)) net::SpdySessionPool::enable_ip_pooling(true); @@ -238,27 +231,6 @@ void InitializeNetworkOptions(const CommandLine& parsed_command_line) { net::WebSocketJob::set_websocket_over_spdy_enabled(true); } - if (parsed_command_line.HasSwitch(switches::kEnableHttpPipelining)) - net::HttpStreamFactory::set_http_pipelining_enabled(true); - - if (parsed_command_line.HasSwitch(switches::kTestingFixedHttpPort)) { - int value; - base::StringToInt( - parsed_command_line.GetSwitchValueASCII( - switches::kTestingFixedHttpPort), - &value); - net::HttpStreamFactory::set_testing_fixed_http_port(value); - } - - if (parsed_command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { - int value; - base::StringToInt( - parsed_command_line.GetSwitchValueASCII( - switches::kTestingFixedHttpsPort), - &value); - net::HttpStreamFactory::set_testing_fixed_https_port(value); - } - bool used_spdy_switch = false; if (parsed_command_line.HasSwitch(switches::kUseSpdy)) { std::string spdy_mode = diff --git a/chrome/browser/io_thread.cc b/chrome/browser/io_thread.cc index b442637..037868a 100644 --- a/chrome/browser/io_thread.cc +++ b/chrome/browser/io_thread.cc @@ -39,6 +39,7 @@ #include "net/base/cert_verifier.h" #include "net/base/default_server_bound_cert_store.h" #include "net/base/host_cache.h" +#include "net/base/host_mapping_rules.h" #include "net/base/host_resolver.h" #include "net/base/mapped_host_resolver.h" #include "net/base/net_util.h" @@ -322,7 +323,12 @@ SystemRequestContextLeakChecker::~SystemRequestContextLeakChecker() { IOThread::Globals::Globals() : ALLOW_THIS_IN_INITIALIZER_LIST( - system_request_context_leak_checker(this)) {} + system_request_context_leak_checker(this)), + ignore_certificate_errors(false), + http_pipelining_enabled(false), + testing_fixed_http_port(0), + testing_fixed_https_port(0) {} + IOThread::Globals::~Globals() {} // |local_state| is passed in explicitly in order to (1) reduce implicit @@ -401,6 +407,8 @@ void IOThread::Init() { net::SetMessageLoopForNSSHttpIO(); #endif // defined(USE_NSS) + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + DCHECK(!globals_); globals_ = new Globals; @@ -424,10 +432,8 @@ void IOThread::Init() { NULL, &system_enable_referrers_, NULL); - if (CommandLine::ForCurrentProcess()->HasSwitch( - switches::kDisableExtensionsHttpThrottling)) { + if (command_line.HasSwitch(switches::kDisableExtensionsHttpThrottling)) network_delegate->NeverThrottleRequests(); - } globals_->system_network_delegate.reset(network_delegate); globals_->host_resolver.reset( CreateGlobalHostResolver(net_log_)); @@ -448,6 +454,32 @@ void IOThread::Init() { new net::DefaultServerBoundCertStore(NULL), base::WorkerPool::GetTaskRunner(true))); globals_->load_time_stats.reset(new chrome_browser_net::LoadTimeStats()); + globals_->host_mapping_rules.reset(new net::HostMappingRules()); + if (command_line.HasSwitch(switches::kHostRules)) { + globals_->host_mapping_rules->SetRulesFromString( + command_line.GetSwitchValueASCII(switches::kHostRules)); + } + if (command_line.HasSwitch(switches::kIgnoreCertificateErrors)) + globals_->ignore_certificate_errors = true; + if (command_line.HasSwitch(switches::kEnableHttpPipelining)) + globals_->http_pipelining_enabled = true; + if (command_line.HasSwitch(switches::kTestingFixedHttpPort)) { + int value; + base::StringToInt( + command_line.GetSwitchValueASCII( + switches::kTestingFixedHttpPort), + &value); + globals_->testing_fixed_http_port = value; + } + if (command_line.HasSwitch(switches::kTestingFixedHttpsPort)) { + int value; + base::StringToInt( + command_line.GetSwitchValueASCII( + switches::kTestingFixedHttpsPort), + &value); + globals_->testing_fixed_https_port = value; + } + net::HttpNetworkSession::Params session_params; session_params.host_resolver = globals_->host_resolver.get(); session_params.cert_verifier = globals_->cert_verifier.get(); @@ -457,16 +489,23 @@ void IOThread::Init() { globals_->transport_security_state.get(); session_params.proxy_service = globals_->proxy_script_fetcher_proxy_service.get(); + session_params.ssl_config_service = globals_->ssl_config_service.get(); session_params.http_auth_handler_factory = globals_->http_auth_handler_factory.get(); + session_params.http_server_properties = + globals_->http_server_properties.get(); session_params.network_delegate = globals_->system_network_delegate.get(); // TODO(rtenneti): We should probably use HttpServerPropertiesManager for the // system URLRequestContext too. There's no reason this should be tied to a // profile. - session_params.http_server_properties = - globals_->http_server_properties.get(); session_params.net_log = net_log_; - session_params.ssl_config_service = globals_->ssl_config_service; + session_params.host_mapping_rules = globals_->host_mapping_rules.get(); + session_params.ignore_certificate_errors = + globals_->ignore_certificate_errors; + session_params.http_pipelining_enabled = globals_->http_pipelining_enabled; + session_params.testing_fixed_http_port = globals_->testing_fixed_http_port; + session_params.testing_fixed_https_port = globals_->http_pipelining_enabled; + scoped_refptr<net::HttpNetworkSession> network_session( new net::HttpNetworkSession(session_params)); globals_->proxy_script_fetcher_http_transaction_factory.reset( @@ -628,6 +667,7 @@ void IOThread::InitSystemRequestContextOnIOThread() { globals_->proxy_script_fetcher_context.get(), system_proxy_config_service_.release(), command_line)); + net::HttpNetworkSession::Params system_params; system_params.host_resolver = globals_->host_resolver.get(); system_params.cert_verifier = globals_->cert_verifier.get(); @@ -642,6 +682,12 @@ void IOThread::InitSystemRequestContextOnIOThread() { system_params.http_server_properties = globals_->http_server_properties.get(); system_params.network_delegate = globals_->system_network_delegate.get(); system_params.net_log = net_log_; + system_params.host_mapping_rules = globals_->host_mapping_rules.get(); + system_params.ignore_certificate_errors = globals_->ignore_certificate_errors; + system_params.http_pipelining_enabled = globals_->http_pipelining_enabled; + system_params.testing_fixed_http_port = globals_->testing_fixed_http_port; + system_params.testing_fixed_https_port = globals_->testing_fixed_https_port; + globals_->system_http_transaction_factory.reset( new net::HttpNetworkLayer( new net::HttpNetworkSession(system_params))); diff --git a/chrome/browser/io_thread.h b/chrome/browser/io_thread.h index cf1e3ba..180ae24 100644 --- a/chrome/browser/io_thread.h +++ b/chrome/browser/io_thread.h @@ -36,6 +36,7 @@ namespace net { class CertVerifier; class CookieStore; class FtpTransactionFactory; +class HostMappingRules; class HostResolver; class HttpAuthHandlerFactory; class HttpServerProperties; @@ -113,6 +114,11 @@ class IOThread : public content::BrowserThreadDelegate { scoped_ptr<chrome_browser_net::HttpPipeliningCompatibilityClient> http_pipelining_compatibility_client; scoped_ptr<chrome_browser_net::LoadTimeStats> load_time_stats; + scoped_ptr<net::HostMappingRules> host_mapping_rules; + bool ignore_certificate_errors; + bool http_pipelining_enabled; + uint16 testing_fixed_http_port; + uint16 testing_fixed_https_port; }; // |net_log| must either outlive the IOThread or be NULL. diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc index df070b5..2f17b35 100644 --- a/chrome/browser/profiles/off_the_record_profile_io_data.cc +++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc @@ -29,6 +29,7 @@ #include "net/base/server_bound_cert_service.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_cache.h" +#include "net/http/http_network_session.h" #include "net/http/http_server_properties_impl.h" #include "net/url_request/file_protocol_handler.h" #include "net/url_request/ftp_protocol_handler.h" @@ -166,7 +167,6 @@ void OffTheRecordProfileIOData::LazyInitializeInternal( IOThread* const io_thread = profile_params->io_thread; IOThread::Globals* const io_thread_globals = io_thread->globals(); - const CommandLine& command_line = *CommandLine::ForCurrentProcess(); ApplyProfileParamsToContext(main_context); ApplyProfileParamsToContext(extensions_context); @@ -221,27 +221,10 @@ void OffTheRecordProfileIOData::LazyInitializeInternal( net::HttpCache::BackendFactory* main_backend = net::HttpCache::DefaultBackend::InMemory(0); - - std::string trusted_spdy_proxy; - if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { - trusted_spdy_proxy = command_line.GetSwitchValueASCII( - switches::kTrustedSpdyProxy); - } - - net::HttpCache* cache = - new net::HttpCache(main_context->host_resolver(), - main_context->cert_verifier(), - main_context->server_bound_cert_service(), - main_context->transport_security_state(), - main_context->proxy_service(), - GetSSLSessionCacheShard(), - main_context->ssl_config_service(), - main_context->http_auth_handler_factory(), - main_context->network_delegate(), - main_context->http_server_properties(), - main_context->net_log(), - main_backend, - trusted_spdy_proxy); + net::HttpNetworkSession::Params network_session_params; + PopulateNetworkSessionParams(profile_params, &network_session_params); + net::HttpCache* cache = new net::HttpCache( + network_session_params, main_backend); main_http_factory_.reset(cache); main_context->set_http_transaction_factory(cache); diff --git a/chrome/browser/profiles/profile_impl_io_data.cc b/chrome/browser/profiles/profile_impl_io_data.cc index d7ca583..ed86c63 100644 --- a/chrome/browser/profiles/profile_impl_io_data.cc +++ b/chrome/browser/profiles/profile_impl_io_data.cc @@ -406,31 +406,16 @@ void ProfileImplIOData::LazyInitializeInternal( set_server_bound_cert_service(server_bound_cert_service); main_context->set_server_bound_cert_service(server_bound_cert_service); - std::string trusted_spdy_proxy; - if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { - trusted_spdy_proxy = command_line.GetSwitchValueASCII( - switches::kTrustedSpdyProxy); - } net::HttpCache::DefaultBackend* main_backend = new net::HttpCache::DefaultBackend( net::DISK_CACHE, lazy_params_->cache_path, lazy_params_->cache_max_size, BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); + net::HttpNetworkSession::Params network_session_params; + PopulateNetworkSessionParams(profile_params, &network_session_params); net::HttpCache* main_cache = new net::HttpCache( - main_context->host_resolver(), - main_context->cert_verifier(), - main_context->server_bound_cert_service(), - main_context->transport_security_state(), - main_context->proxy_service(), - GetSSLSessionCacheShard(), - main_context->ssl_config_service(), - main_context->http_auth_handler_factory(), - main_context->network_delegate(), - main_context->http_server_properties(), - main_context->net_log(), - main_backend, - trusted_spdy_proxy); + network_session_params, main_backend); if (record_mode || playback_mode) { main_cache->set_mode( diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index df18869..078a621 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -652,3 +652,36 @@ void ProfileIOData::set_server_bound_cert_service( void ProfileIOData::DestroyResourceContext() { resource_context_.reset(); } + +void ProfileIOData::PopulateNetworkSessionParams( + const ProfileParams* profile_params, + net::HttpNetworkSession::Params* params) const { + + ChromeURLRequestContext* context = main_request_context(); + + IOThread* const io_thread = profile_params->io_thread; + IOThread::Globals* const globals = io_thread->globals(); + + params->host_resolver = context->host_resolver(); + params->cert_verifier = context->cert_verifier(); + params->server_bound_cert_service = context->server_bound_cert_service(); + params->transport_security_state = context->transport_security_state(); + params->proxy_service = context->proxy_service(); + params->ssl_session_cache_shard = GetSSLSessionCacheShard(); + params->ssl_config_service = context->ssl_config_service(); + params->http_auth_handler_factory = context->http_auth_handler_factory(); + params->network_delegate = context->network_delegate(); + params->http_server_properties = context->http_server_properties(); + params->net_log = context->net_log(); + params->host_mapping_rules = globals->host_mapping_rules.get(); + params->ignore_certificate_errors = globals->ignore_certificate_errors; + params->http_pipelining_enabled = globals->http_pipelining_enabled; + params->testing_fixed_http_port = globals->testing_fixed_http_port; + params->testing_fixed_https_port = globals->testing_fixed_https_port; + + const CommandLine& command_line = *CommandLine::ForCurrentProcess(); + if (command_line.HasSwitch(switches::kTrustedSpdyProxy)) { + params->trusted_spdy_proxy = command_line.GetSwitchValueASCII( + switches::kTrustedSpdyProxy); + } +} diff --git a/chrome/browser/profiles/profile_io_data.h b/chrome/browser/profiles/profile_io_data.h index 2047351..9087f14 100644 --- a/chrome/browser/profiles/profile_io_data.h +++ b/chrome/browser/profiles/profile_io_data.h @@ -19,6 +19,7 @@ #include "chrome/browser/net/chrome_url_request_context.h" #include "content/public/browser/resource_context.h" #include "net/cookies/cookie_monster.h" +#include "net/http/http_network_session.h" #include "net/url_request/url_request_job_factory.h" class CookieSettings; @@ -270,6 +271,12 @@ class ProfileIOData { // URLRequests may be accessing. void DestroyResourceContext(); + // Fills in fields of params using values from main_request_context_ and the + // IOThread associated with profile_params. + void PopulateNetworkSessionParams( + const ProfileParams* profile_params, + net::HttpNetworkSession::Params* params) const; + private: class ResourceContext : public content::ResourceContext { public: diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc index 613b5277..62d54d9 100644 --- a/chrome/browser/ui/webui/net_internals/net_internals_ui.cc +++ b/chrome/browser/ui/webui/net_internals/net_internals_ui.cc @@ -1449,12 +1449,10 @@ void NetInternalsMessageHandler::IOThreadImpl::OnGetHttpPipeliningStatus( DCHECK(!list); DictionaryValue* status_dict = new DictionaryValue(); - status_dict->Set("pipelining_enabled", - Value::CreateBooleanValue( - net::HttpStreamFactory::http_pipelining_enabled())); - net::HttpNetworkSession* http_network_session = GetHttpNetworkSession(context_getter_->GetURLRequestContext()); + status_dict->Set("pipelining_enabled", Value::CreateBooleanValue( + http_network_session->params().http_pipelining_enabled)); Value* pipelined_connection_info = NULL; if (http_network_session) { pipelined_connection_info = diff --git a/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc b/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc index 806d6b6..42b984b 100644 --- a/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc +++ b/chrome/browser/ui/webui/net_internals/net_internals_ui_browsertest.cc @@ -96,9 +96,13 @@ void AddDummyHttpPipelineFeedbackOnIOThread( // Called on IO thread. Adds an entry to the list of known HTTP pipelining // hosts. -void EnableHttpPipeliningOnIOThread(bool enable) { +void EnableHttpPipeliningOnIOThread( + net::URLRequestContextGetter* context_getter, bool enable) { ASSERT_TRUE(BrowserThread::CurrentlyOn(BrowserThread::IO)); - net::HttpStreamFactory::set_http_pipelining_enabled(enable); + net::URLRequestContext* context = context_getter->GetURLRequestContext(); + net::HttpNetworkSession* http_network_session = + context->http_transaction_factory()->GetSession(); + http_network_session->set_http_pipelining_enabled(enable); } } // namespace @@ -275,7 +279,9 @@ void NetInternalsTest::MessageHandler::EnableHttpPipelining( ASSERT_TRUE(list_value->GetBoolean(0, &enable)); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, - base::Bind(&EnableHttpPipeliningOnIOThread, enable)); + base::Bind(&EnableHttpPipeliningOnIOThread, + make_scoped_refptr(browser()->profile()->GetRequestContext()), + enable)); } void NetInternalsTest::MessageHandler::AddDummyHttpPipelineFeedback( diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index b0da3ae..1bcb347 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -28,7 +28,8 @@ namespace content { ShellBrowserContext::ShellBrowserContext(bool off_the_record) - : off_the_record_(off_the_record) { + : off_the_record_(off_the_record), + ignore_certificate_errors_(false) { InitWhileIOAllowed(); } @@ -41,6 +42,8 @@ ShellBrowserContext::~ShellBrowserContext() { void ShellBrowserContext::InitWhileIOAllowed() { CommandLine* cmd_line = CommandLine::ForCurrentProcess(); + if (cmd_line->HasSwitch(switches::kDumpRenderTree)) + ignore_certificate_errors_ = true; if (cmd_line->HasSwitch(switches::kDumpRenderTree)) { CHECK(testing_path_.CreateUniqueTempDir()); path_ = testing_path_.path(); @@ -96,6 +99,7 @@ DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() { net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { if (!url_request_getter_) { url_request_getter_ = new ShellURLRequestContextGetter( + ignore_certificate_errors_, GetPath(), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index a89b99c..41c60c5 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -47,6 +47,7 @@ class ShellBrowserContext : public BrowserContext { void InitWhileIOAllowed(); bool off_the_record_; + bool ignore_certificate_errors_; ScopedTempDir testing_path_; FilePath path_; scoped_ptr<ResourceContext> resource_context_; diff --git a/content/shell/shell_main_delegate.cc b/content/shell/shell_main_delegate.cc index 7a64d2d..35a9350 100644 --- a/content/shell/shell_main_delegate.cc +++ b/content/shell/shell_main_delegate.cc @@ -91,7 +91,7 @@ bool ShellMainDelegate::BasicStartupComplete(int* exit_code) { switches::kAllowFileAccessFromFiles); CommandLine::ForCurrentProcess()->AppendSwitch( switches::kForceCompositingMode); - net::HttpStreamFactory::set_ignore_certificate_errors(true); + //net::HttpStreamFactory::set_ignore_certificate_errors(true); net::CookieMonster::EnableFileScheme(); } SetContentClient(&content_client_); diff --git a/content/shell/shell_url_request_context_getter.cc b/content/shell/shell_url_request_context_getter.cc index cba69cb..b8a6f03 100644 --- a/content/shell/shell_url_request_context_getter.cc +++ b/content/shell/shell_url_request_context_getter.cc @@ -4,6 +4,7 @@ #include "content/shell/shell_url_request_context_getter.h" +#include "base/command_line.h" #include "base/logging.h" #include "base/string_split.h" #include "base/threading/worker_pool.h" @@ -17,6 +18,7 @@ #include "net/cookies/cookie_monster.h" #include "net/http/http_auth_handler_factory.h" #include "net/http/http_cache.h" +#include "net/http/http_network_session.h" #include "net/http/http_server_properties_impl.h" #include "net/proxy/proxy_service.h" #include "net/url_request/url_request_context.h" @@ -26,10 +28,12 @@ namespace content { ShellURLRequestContextGetter::ShellURLRequestContextGetter( + bool ignore_certificate_errors, const FilePath& base_path, MessageLoop* io_loop, MessageLoop* file_loop) - : base_path_(base_path), + : ignore_certificate_errors_(ignore_certificate_errors), + base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop) { // Must first be created on the UI thread. @@ -88,20 +92,28 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { BrowserThread::GetMessageLoopProxyForThread( BrowserThread::CACHE)); + net::HttpNetworkSession::Params network_session_params; + network_session_params.host_resolver = + url_request_context_->host_resolver(); + network_session_params.cert_verifier = + url_request_context_->cert_verifier(); + network_session_params.server_bound_cert_service = + url_request_context_->server_bound_cert_service(); + network_session_params.proxy_service = + url_request_context_->proxy_service(); + network_session_params.ssl_config_service = + url_request_context_->ssl_config_service(); + network_session_params.http_auth_handler_factory = + url_request_context_->http_auth_handler_factory(); + network_session_params.network_delegate = + url_request_context_->network_delegate(); + network_session_params.http_server_properties = + url_request_context_->http_server_properties(); + network_session_params.ignore_certificate_errors = + ignore_certificate_errors_; + net::HttpCache* main_cache = new net::HttpCache( - url_request_context_->host_resolver(), - url_request_context_->cert_verifier(), - url_request_context_->server_bound_cert_service(), - NULL, /* transport_security_state */ - url_request_context_->proxy_service(), - "", /* ssl_session_cache_shard */ - url_request_context_->ssl_config_service(), - url_request_context_->http_auth_handler_factory(), - url_request_context_->network_delegate(), - url_request_context_->http_server_properties(), - NULL, - main_backend, - "" /* trusted_spdy_proxy */ ); + network_session_params, main_backend); storage_->set_http_transaction_factory(main_cache); storage_->set_job_factory(new net::URLRequestJobFactoryImpl); diff --git a/content/shell/shell_url_request_context_getter.h b/content/shell/shell_url_request_context_getter.h index 7c9401f..98fa03c 100644 --- a/content/shell/shell_url_request_context_getter.h +++ b/content/shell/shell_url_request_context_getter.h @@ -25,6 +25,7 @@ namespace content { class ShellURLRequestContextGetter : public net::URLRequestContextGetter { public: ShellURLRequestContextGetter( + bool ignore_certificate_errors, const FilePath& base_path, MessageLoop* io_loop, MessageLoop* file_loop); @@ -40,6 +41,7 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { virtual ~ShellURLRequestContextGetter(); private: + bool ignore_certificate_errors_; FilePath base_path_; MessageLoop* io_loop_; MessageLoop* file_loop_; diff --git a/jingle/glue/proxy_resolving_client_socket.cc b/jingle/glue/proxy_resolving_client_socket.cc index 02df488..839daf2 100644 --- a/jingle/glue/proxy_resolving_client_socket.cc +++ b/jingle/glue/proxy_resolving_client_socket.cc @@ -46,6 +46,7 @@ ProxyResolvingClientSocket::ProxyResolvingClientSocket( DCHECK(request_context); DCHECK(!dest_host_port_pair_.host().empty()); DCHECK_GT(dest_host_port_pair_.port(), 0); + net::HttpNetworkSession::Params session_params; session_params.client_socket_factory = socket_factory; session_params.host_resolver = request_context->host_resolver(); @@ -62,6 +63,22 @@ ProxyResolvingClientSocket::ProxyResolvingClientSocket( session_params.http_server_properties = request_context->http_server_properties(); session_params.net_log = request_context->net_log(); + + const net::HttpNetworkSession::Params* reference_params = + request_context->GetNetworkSessionParams(); + if (reference_params) { + session_params.host_mapping_rules = reference_params->host_mapping_rules; + session_params.ignore_certificate_errors = + reference_params->ignore_certificate_errors; + session_params.http_pipelining_enabled = + reference_params->http_pipelining_enabled; + session_params.testing_fixed_http_port = + reference_params->testing_fixed_http_port; + session_params.testing_fixed_https_port = + reference_params->testing_fixed_https_port; + session_params.trusted_spdy_proxy = reference_params->trusted_spdy_proxy; + } + network_session_ = new net::HttpNetworkSession(session_params); } diff --git a/net/http/http_cache.cc b/net/http/http_cache.cc index 8579471..f7dfc2d 100644 --- a/net/http/http_cache.cc +++ b/net/http/http_cache.cc @@ -38,39 +38,6 @@ namespace net { -namespace { - -HttpNetworkSession* CreateNetworkSession( - HostResolver* host_resolver, - CertVerifier* cert_verifier, - ServerBoundCertService* server_bound_cert_service, - TransportSecurityState* transport_security_state, - ProxyService* proxy_service, - const std::string& ssl_session_cache_shard, - SSLConfigService* ssl_config_service, - HttpAuthHandlerFactory* http_auth_handler_factory, - NetworkDelegate* network_delegate, - HttpServerProperties* http_server_properties, - NetLog* net_log, - const std::string& trusted_spdy_proxy) { - HttpNetworkSession::Params params; - params.host_resolver = host_resolver; - params.cert_verifier = cert_verifier; - params.server_bound_cert_service = server_bound_cert_service; - params.transport_security_state = transport_security_state; - params.proxy_service = proxy_service; - params.ssl_session_cache_shard = ssl_session_cache_shard; - params.ssl_config_service = ssl_config_service; - params.http_auth_handler_factory = http_auth_handler_factory; - params.network_delegate = network_delegate; - params.http_server_properties = http_server_properties; - params.net_log = net_log; - params.trusted_spdy_proxy = trusted_spdy_proxy; - return new HttpNetworkSession(params); -} - -} // namespace - HttpCache::DefaultBackend::DefaultBackend(CacheType type, const FilePath& path, int max_bytes, @@ -275,38 +242,13 @@ void HttpCache::MetadataWriter::OnIOComplete(int result) { //----------------------------------------------------------------------------- -HttpCache::HttpCache(HostResolver* host_resolver, - CertVerifier* cert_verifier, - ServerBoundCertService* server_bound_cert_service, - TransportSecurityState* transport_security_state, - ProxyService* proxy_service, - const std::string& ssl_session_cache_shard, - SSLConfigService* ssl_config_service, - HttpAuthHandlerFactory* http_auth_handler_factory, - NetworkDelegate* network_delegate, - HttpServerProperties* http_server_properties, - NetLog* net_log, - BackendFactory* backend_factory, - const std::string& trusted_spdy_proxy) - : net_log_(net_log), +HttpCache::HttpCache(const net::HttpNetworkSession::Params& params, + BackendFactory* backend_factory) + : net_log_(params.net_log), backend_factory_(backend_factory), building_backend_(false), mode_(NORMAL), - network_layer_( - new HttpNetworkLayer( - CreateNetworkSession( - host_resolver, - cert_verifier, - server_bound_cert_service, - transport_security_state, - proxy_service, - ssl_session_cache_shard, - ssl_config_service, - http_auth_handler_factory, - network_delegate, - http_server_properties, - net_log, - trusted_spdy_proxy))) { + network_layer_(new HttpNetworkLayer(new HttpNetworkSession(params))) { } diff --git a/net/http/http_cache.h b/net/http/http_cache.h index 4ff00b5..60e5875 100644 --- a/net/http/http_cache.h +++ b/net/http/http_cache.h @@ -30,6 +30,7 @@ #include "net/base/completion_callback.h" #include "net/base/load_states.h" #include "net/base/net_export.h" +#include "net/http/http_network_session.h" #include "net/http/http_transaction_factory.h" class GURL; @@ -118,19 +119,8 @@ class NET_EXPORT HttpCache : public HttpTransactionFactory, // The disk cache is initialized lazily (by CreateTransaction) in this case. // The HttpCache takes ownership of the |backend_factory|. - HttpCache(HostResolver* host_resolver, - CertVerifier* cert_verifier, - ServerBoundCertService* server_bound_cert_service, - TransportSecurityState* transport_security_state, - ProxyService* proxy_service, - const std::string& ssl_session_cache_shard, - SSLConfigService* ssl_config_service, - HttpAuthHandlerFactory* http_auth_handler_factory, - NetworkDelegate* network_delegate, - HttpServerProperties* http_server_properties, - NetLog* net_log, - BackendFactory* backend_factory, - const std::string& trusted_spdy_proxy); + HttpCache(const net::HttpNetworkSession::Params& params, + BackendFactory* backend_factory); // The disk cache is initialized lazily (by CreateTransaction) in this case. // Provide an existing HttpNetworkSession, the cache can construct a diff --git a/net/http/http_network_session.cc b/net/http/http_network_session.cc index 124c570..c54325cf 100644 --- a/net/http/http_network_session.cc +++ b/net/http/http_network_session.cc @@ -58,7 +58,12 @@ HttpNetworkSession::Params::Params() network_delegate(NULL), http_server_properties(NULL), net_log(NULL), - force_http_pipelining(false) {} + host_mapping_rules(NULL), + force_http_pipelining(false), + ignore_certificate_errors(false), + http_pipelining_enabled(false), + testing_fixed_http_port(0), + testing_fixed_https_port(0) {} // TODO(mbelshe): Move the socket factories into HttpStreamFactory. HttpNetworkSession::HttpNetworkSession(const Params& params) diff --git a/net/http/http_network_session.h b/net/http/http_network_session.h index 3a9d72c..47abaec 100644 --- a/net/http/http_network_session.h +++ b/net/http/http_network_session.h @@ -61,7 +61,12 @@ class NET_EXPORT HttpNetworkSession NetworkDelegate* network_delegate; HttpServerProperties* http_server_properties; NetLog* net_log; + HostMappingRules* host_mapping_rules; bool force_http_pipelining; + bool ignore_certificate_errors; + bool http_pipelining_enabled; + uint16 testing_fixed_http_port; + uint16 testing_fixed_https_port; std::string trusted_spdy_proxy; }; @@ -130,6 +135,10 @@ class NET_EXPORT HttpNetworkSession // Returns the original Params used to construct this session. const Params& params() const { return params_; } + void set_http_pipelining_enabled(bool enable) { + params_.http_pipelining_enabled = enable; + } + private: friend class base::RefCounted<HttpNetworkSession>; friend class HttpNetworkSessionPeer; diff --git a/net/http/http_pipelined_network_transaction_unittest.cc b/net/http/http_pipelined_network_transaction_unittest.cc index ecdb07a4..d5d87d0 100644 --- a/net/http/http_pipelined_network_transaction_unittest.cc +++ b/net/http/http_pipelined_network_transaction_unittest.cc @@ -72,16 +72,6 @@ class HttpPipelinedNetworkTransactionTest : public testing::Test { pool_(1, 1, &histograms_, &factory_) { } - virtual void SetUp() OVERRIDE { - default_pipelining_enabled_ = HttpStreamFactory::http_pipelining_enabled(); - HttpStreamFactory::set_http_pipelining_enabled(true); - } - - virtual void TearDown() OVERRIDE { - MessageLoop::current()->RunAllPending(); - HttpStreamFactory::set_http_pipelining_enabled(default_pipelining_enabled_); - } - void Initialize(bool force_http_pipelining) { // Normally, this code could just go in SetUp(). For a few of these tests, // we change the default number of sockets per group. That needs to be done @@ -99,6 +89,7 @@ class HttpPipelinedNetworkTransactionTest : public testing::Test { session_params.http_auth_handler_factory = auth_handler_factory_.get(); session_params.http_server_properties = &http_server_properties_; session_params.force_http_pipelining = force_http_pipelining; + session_params.http_pipelining_enabled = true; session_ = new HttpNetworkSession(session_params); } @@ -231,7 +222,6 @@ class HttpPipelinedNetworkTransactionTest : public testing::Test { ScopedVector<DeterministicSocketData> data_vector_; TestCompletionCallback callback_; ScopedVector<HttpRequestInfo> request_info_vector_; - bool default_pipelining_enabled_; SimpleProxyConfigService* proxy_config_service_; scoped_ptr<ProxyService> proxy_service_; diff --git a/net/http/http_stream_factory.cc b/net/http/http_stream_factory.cc index ca3b294..a92f9fc 100644 --- a/net/http/http_stream_factory.cc +++ b/net/http/http_stream_factory.cc @@ -17,8 +17,6 @@ namespace net { // with |ResetStaticSettingsToInit|. This is critical for unit test isolation. // static -const HostMappingRules* HttpStreamFactory::host_mapping_rules_ = NULL; -// static std::vector<std::string>* HttpStreamFactory::next_protos_ = NULL; // static bool HttpStreamFactory::enabled_protocols_[NUM_ALTERNATE_PROTOCOLS]; @@ -32,31 +30,20 @@ bool HttpStreamFactory::force_spdy_over_ssl_ = true; bool HttpStreamFactory::force_spdy_always_ = false; // static std::list<HostPortPair>* HttpStreamFactory::forced_spdy_exclusions_ = NULL; -// static -bool HttpStreamFactory::ignore_certificate_errors_ = false; -// static -bool HttpStreamFactory::http_pipelining_enabled_ = false; -// static -uint16 HttpStreamFactory::testing_fixed_http_port_ = 0; -// static -uint16 HttpStreamFactory::testing_fixed_https_port_ = 0; HttpStreamFactory::~HttpStreamFactory() {} // static void HttpStreamFactory::ResetStaticSettingsToInit() { // WARNING: These must match the initializers above. - delete host_mapping_rules_; delete next_protos_; delete forced_spdy_exclusions_; - host_mapping_rules_ = NULL; next_protos_ = NULL; spdy_enabled_ = true; use_alternate_protocols_ = false; force_spdy_over_ssl_ = true; force_spdy_always_ = false; forced_spdy_exclusions_ = NULL; - ignore_certificate_errors_ = false; for (int i = 0; i < NUM_ALTERNATE_PROTOCOLS; ++i) enabled_protocols_[i] = false; } @@ -100,7 +87,9 @@ void HttpStreamFactory::ProcessAlternateProtocol( } HostPortPair host_port(http_host_port_pair); - host_mapping_rules().RewriteHost(&host_port); + const HostMappingRules* mapping_rules = GetHostMappingRules(); + if (mapping_rules) + mapping_rules->RewriteHost(&host_port); if (http_server_properties->HasAlternateProtocol(host_port)) { const PortAlternateProtocolPair existing_alternate = @@ -115,7 +104,8 @@ void HttpStreamFactory::ProcessAlternateProtocol( GURL HttpStreamFactory::ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint) { - if (host_mapping_rules().RewriteHost(endpoint)) { + const HostMappingRules* mapping_rules = GetHostMappingRules(); + if (mapping_rules && mapping_rules->RewriteHost(endpoint)) { url_canon::Replacements<char> replacements; const std::string port_str = base::IntToString(endpoint->port()); replacements.SetPort(port_str.c_str(), @@ -202,21 +192,6 @@ void HttpStreamFactory::SetNextProtos(const std::vector<std::string>& value) { enabled_protocols_[NPN_SPDY_1] = false; } -// static -void HttpStreamFactory::SetHostMappingRules(const std::string& rules) { - HostMappingRules* host_mapping_rules = new HostMappingRules; - host_mapping_rules->SetRulesFromString(rules); - delete host_mapping_rules_; - host_mapping_rules_ = host_mapping_rules; -} - HttpStreamFactory::HttpStreamFactory() {} -// static -const HostMappingRules& HttpStreamFactory::host_mapping_rules() { - if (!host_mapping_rules_) - host_mapping_rules_ = new HostMappingRules; - return *host_mapping_rules_; -} - } // namespace net diff --git a/net/http/http_stream_factory.h b/net/http/http_stream_factory.h index df9cecf..7371010 100644 --- a/net/http/http_stream_factory.h +++ b/net/http/http_stream_factory.h @@ -163,6 +163,8 @@ class NET_EXPORT HttpStreamFactory { const std::string& alternate_protocol_str, const HostPortPair& http_host_port_pair); + GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); + // Virtual interface methods. // Request a stream. @@ -185,13 +187,13 @@ class NET_EXPORT HttpStreamFactory { // returns an empty Value. virtual base::Value* PipelineInfoToValue() const = 0; + virtual const HostMappingRules* GetHostMappingRules() const = 0; + // Static settings // Reset all static settings to initialized values. Used to init test suite. static void ResetStaticSettingsToInit(); - static GURL ApplyHostMappingRules(const GURL& url, HostPortPair* endpoint); - // Turns spdy on or off. static void set_spdy_enabled(bool value) { spdy_enabled_ = value; @@ -245,39 +247,10 @@ class NET_EXPORT HttpStreamFactory { return *next_protos_; } - // Sets the HttpStreamFactoryImpl into a mode where it can ignore certificate - // errors. This is for testing. - static void set_ignore_certificate_errors(bool value) { - ignore_certificate_errors_ = value; - } - static bool ignore_certificate_errors() { - return ignore_certificate_errors_; - } - - static void SetHostMappingRules(const std::string& rules); - - static void set_http_pipelining_enabled(bool value) { - http_pipelining_enabled_ = value; - } - static bool http_pipelining_enabled() { return http_pipelining_enabled_; } - - static void set_testing_fixed_http_port(int port) { - testing_fixed_http_port_ = port; - } - static uint16 testing_fixed_http_port() { return testing_fixed_http_port_; } - - static void set_testing_fixed_https_port(int port) { - testing_fixed_https_port_ = port; - } - static uint16 testing_fixed_https_port() { return testing_fixed_https_port_; } - protected: HttpStreamFactory(); private: - static const HostMappingRules& host_mapping_rules(); - - static const HostMappingRules* host_mapping_rules_; static std::vector<std::string>* next_protos_; static bool enabled_protocols_[NUM_ALTERNATE_PROTOCOLS]; static bool spdy_enabled_; @@ -285,10 +258,6 @@ class NET_EXPORT HttpStreamFactory { static bool force_spdy_over_ssl_; static bool force_spdy_always_; static std::list<HostPortPair>* forced_spdy_exclusions_; - static bool ignore_certificate_errors_; - static bool http_pipelining_enabled_; - static uint16 testing_fixed_http_port_; - static uint16 testing_fixed_https_port_; DISALLOW_COPY_AND_ASSIGN(HttpStreamFactory); }; diff --git a/net/http/http_stream_factory_impl.cc b/net/http/http_stream_factory_impl.cc index 75e7365..5896a93 100644 --- a/net/http/http_stream_factory_impl.cc +++ b/net/http/http_stream_factory_impl.cc @@ -123,6 +123,10 @@ base::Value* HttpStreamFactoryImpl::PipelineInfoToValue() const { return http_pipelined_host_pool_.PipelineInfoToValue(); } +const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { + return session_->params().host_mapping_rules; +} + bool HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( const GURL& original_url, GURL* alternate_url) const { diff --git a/net/http/http_stream_factory_impl.h b/net/http/http_stream_factory_impl.h index 2542298..213d96a 100644 --- a/net/http/http_stream_factory_impl.h +++ b/net/http/http_stream_factory_impl.h @@ -43,6 +43,7 @@ class NET_EXPORT_PRIVATE HttpStreamFactoryImpl : const SSLConfig& server_ssl_config, const SSLConfig& proxy_ssl_config) OVERRIDE; virtual base::Value* PipelineInfoToValue() const OVERRIDE; + virtual const HostMappingRules* GetHostMappingRules() const OVERRIDE; // HttpPipelinedHostPool::Delegate interface virtual void OnHttpPipelinedHostHasAdditionalCapacity( diff --git a/net/http/http_stream_factory_impl_job.cc b/net/http/http_stream_factory_impl_job.cc index cdab39b..ddd5ae6 100644 --- a/net/http/http_stream_factory_impl_job.cc +++ b/net/http/http_stream_factory_impl_job.cc @@ -561,7 +561,7 @@ int HttpStreamFactoryImpl::Job::StartInternal() { int HttpStreamFactoryImpl::Job::DoStart() { int port = request_info_.url.EffectiveIntPort(); origin_ = HostPortPair(request_info_.url.HostNoBrackets(), port); - origin_url_ = HttpStreamFactory::ApplyHostMappingRules( + origin_url_ = stream_factory_->ApplyHostMappingRules( request_info_.url, &origin_); http_pipelining_key_.reset(new HttpPipelinedHost::Key(origin_)); @@ -1206,7 +1206,7 @@ int HttpStreamFactoryImpl::Job::HandleCertificateError(int error) { server_ssl_config_.allowed_bad_certs.push_back(bad_cert); int load_flags = request_info_.load_flags; - if (HttpStreamFactory::ignore_certificate_errors()) + if (session_->params().ignore_certificate_errors) load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; if (ssl_socket->IgnoreCertError(error, load_flags)) return OK; @@ -1268,7 +1268,7 @@ bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() { if (session_->force_http_pipelining()) { return true; } - if (!HttpStreamFactory::http_pipelining_enabled()) { + if (!session_->params().http_pipelining_enabled) { return false; } if (using_ssl_) { diff --git a/net/socket/client_socket_pool_manager.cc b/net/socket/client_socket_pool_manager.cc index d5591b7..5884e08 100644 --- a/net/socket/client_socket_pool_manager.cc +++ b/net/socket/client_socket_pool_manager.cc @@ -93,10 +93,10 @@ int InitSocketPoolHelper(const GURL& request_url, HostPortPair(request_url.HostNoBrackets(), request_url.EffectiveIntPort()); - if (!using_ssl && HttpStreamFactory::testing_fixed_http_port() != 0) { - origin_host_port.set_port(HttpStreamFactory::testing_fixed_http_port()); - } else if (using_ssl && HttpStreamFactory::testing_fixed_https_port() != 0) { - origin_host_port.set_port(HttpStreamFactory::testing_fixed_https_port()); + if (!using_ssl && session->params().testing_fixed_http_port != 0) { + origin_host_port.set_port(session->params().testing_fixed_http_port); + } else if (using_ssl && session->params().testing_fixed_https_port != 0) { + origin_host_port.set_port(session->params().testing_fixed_https_port); } bool disable_resolver_cache = @@ -105,7 +105,7 @@ int InitSocketPoolHelper(const GURL& request_url, request_load_flags & LOAD_DISABLE_CACHE; int load_flags = request_load_flags; - if (HttpStreamFactory::ignore_certificate_errors()) + if (session->params().ignore_certificate_errors) load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; // Build the string used to uniquely identify connections of this type. diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index f656cb8..41d77ed 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -1301,9 +1301,12 @@ int SocketStream::HandleCertificateError(int result) { SSLClientSocket* ssl_socket = static_cast<SSLClientSocket*>(socket_.get()); DCHECK(ssl_socket); - if (HttpStreamFactory::ignore_certificate_errors() && - ssl_socket->IgnoreCertError(result, LOAD_IGNORE_ALL_CERT_ERRORS)) - return OK; + if (SSLClientSocket::IgnoreCertError(result, LOAD_IGNORE_ALL_CERT_ERRORS)) { + const HttpNetworkSession::Params* session_params = + context_->GetNetworkSessionParams(); + if (session_params && session_params->ignore_certificate_errors) + return OK; + } if (!delegate_) return result; diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc index 5b7af63..b9ee75f 100644 --- a/net/url_request/url_request_context.cc +++ b/net/url_request/url_request_context.cc @@ -65,6 +65,17 @@ void URLRequestContext::CopyFrom(const URLRequestContext* other) { set_throttler_manager(other->throttler_manager_); } +const HttpNetworkSession::Params* URLRequestContext::GetNetworkSessionParams( + ) const { + HttpTransactionFactory* transaction_factory = http_transaction_factory(); + if (!transaction_factory) + return NULL; + HttpNetworkSession* network_session = transaction_factory->GetSession(); + if (!network_session) + return NULL; + return &network_session->params(); +} + URLRequest* URLRequestContext::CreateRequest( const GURL& url, URLRequest::Delegate* delegate) const { return new URLRequest(url, delegate, this, network_delegate_); diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h index 8e8e3cc..cea9de5 100644 --- a/net/url_request/url_request_context.h +++ b/net/url_request/url_request_context.h @@ -20,6 +20,7 @@ #include "net/base/net_log.h" #include "net/base/ssl_config_service.h" #include "net/base/transport_security_state.h" +#include "net/http/http_network_session.h" #include "net/http/http_server_properties.h" #include "net/ftp/ftp_auth_cache.h" #include "net/url_request/url_request.h" @@ -52,6 +53,9 @@ class NET_EXPORT URLRequestContext // Copies the state from |other| into this context. void CopyFrom(const URLRequestContext* other); + // May return NULL if this context doesn't have an associated network session. + const HttpNetworkSession::Params* GetNetworkSessionParams() const; + URLRequest* CreateRequest( const GURL& url, URLRequest::Delegate* delegate) const; diff --git a/net/url_request/url_request_context_builder.cc b/net/url_request/url_request_context_builder.cc index 415cb11..3228bfb 100644 --- a/net/url_request/url_request_context_builder.cc +++ b/net/url_request/url_request_context_builder.cc @@ -181,6 +181,17 @@ URLRequestContextBuilder::HttpCacheParams::HttpCacheParams() max_size(0) {} URLRequestContextBuilder::HttpCacheParams::~HttpCacheParams() {} +URLRequestContextBuilder::HttpNetworkSessionParams::HttpNetworkSessionParams() + : ignore_certificate_errors(false), + host_mapping_rules(NULL), + http_pipelining_enabled(false), + testing_fixed_http_port(0), + testing_fixed_https_port(0), + trusted_spdy_proxy() {} + +URLRequestContextBuilder::HttpNetworkSessionParams::~HttpNetworkSessionParams() +{} + URLRequestContextBuilder::URLRequestContextBuilder() : ftp_enabled_(false), http_cache_enabled_(true) {} @@ -237,8 +248,38 @@ URLRequestContext* URLRequestContextBuilder::Build() { storage->set_http_server_properties(new net::HttpServerPropertiesImpl); storage->set_cert_verifier(CertVerifier::CreateDefault()); + net::HttpNetworkSession::Params network_session_params; + network_session_params.host_resolver = host_resolver; + network_session_params.cert_verifier = context->cert_verifier(); + network_session_params.transport_security_state = + context->transport_security_state(); + network_session_params.proxy_service = context->proxy_service(); + network_session_params.ssl_config_service = + context->ssl_config_service(); + network_session_params.http_auth_handler_factory = + context->http_auth_handler_factory(); + network_session_params.network_delegate = + context->network_delegate(); + network_session_params.http_server_properties = + context->http_server_properties(); + network_session_params.net_log = context->net_log(); + network_session_params.ignore_certificate_errors = + http_network_session_params_.ignore_certificate_errors; + network_session_params.host_mapping_rules = + http_network_session_params_.host_mapping_rules; + network_session_params.http_pipelining_enabled = + http_network_session_params_.http_pipelining_enabled; + network_session_params.testing_fixed_http_port = + http_network_session_params_.testing_fixed_http_port; + network_session_params.testing_fixed_https_port = + http_network_session_params_.testing_fixed_https_port; + network_session_params.trusted_spdy_proxy = + http_network_session_params_.trusted_spdy_proxy; + HttpTransactionFactory* http_transaction_factory = NULL; if (http_cache_enabled_) { + network_session_params.server_bound_cert_service = + context->server_bound_cert_service(); HttpCache::BackendFactory* http_cache_backend = NULL; if (http_cache_params_.type == HttpCacheParams::DISK) { context->StartCacheThread(); @@ -251,36 +292,12 @@ URLRequestContext* URLRequestContextBuilder::Build() { http_cache_backend = HttpCache::DefaultBackend::InMemory(http_cache_params_.max_size); } + http_transaction_factory = new HttpCache( - context->host_resolver(), - context->cert_verifier(), - context->server_bound_cert_service(), - context->transport_security_state(), - context->proxy_service(), - "", - context->ssl_config_service(), - context->http_auth_handler_factory(), - context->network_delegate(), - context->http_server_properties(), - context->net_log(), - http_cache_backend, - "" /* trusted_spdy_proxy */ ); + network_session_params, http_cache_backend); } else { - HttpNetworkSession::Params session_params; - session_params.host_resolver = context->host_resolver(); - session_params.cert_verifier = context->cert_verifier(); - session_params.transport_security_state = - context->transport_security_state(); - session_params.proxy_service = context->proxy_service(); - session_params.ssl_config_service = context->ssl_config_service(); - session_params.http_auth_handler_factory = - context->http_auth_handler_factory(); - session_params.network_delegate = context->network_delegate(); - session_params.http_server_properties = - context->http_server_properties(); - session_params.net_log = context->net_log(); scoped_refptr<net::HttpNetworkSession> network_session( - new net::HttpNetworkSession(session_params)); + new net::HttpNetworkSession(network_session_params)); http_transaction_factory = new HttpNetworkLayer(network_session); } diff --git a/net/url_request/url_request_context_builder.h b/net/url_request/url_request_context_builder.h index 7d19236..ddbca53 100644 --- a/net/url_request/url_request_context_builder.h +++ b/net/url_request/url_request_context_builder.h @@ -25,6 +25,7 @@ namespace net { +class HostMappingRules; class ProxyConfigService; class URLRequestContext; @@ -62,6 +63,19 @@ class NET_EXPORT URLRequestContextBuilder { FilePath path; }; + struct NET_EXPORT HttpNetworkSessionParams { + HttpNetworkSessionParams(); + ~HttpNetworkSessionParams(); + + // These fields mirror those in net::HttpNetworkSession::Params; + bool ignore_certificate_errors; + HostMappingRules* host_mapping_rules; + bool http_pipelining_enabled; + uint16 testing_fixed_http_port; + uint16 testing_fixed_https_port; + std::string trusted_spdy_proxy; + }; + URLRequestContextBuilder(); ~URLRequestContextBuilder(); @@ -90,6 +104,12 @@ class NET_EXPORT URLRequestContextBuilder { void EnableHttpCache(const HttpCacheParams& params); void DisableHttpCache(); + // Override default net::HttpNetworkSession::Params settings. + void set_http_network_session_params( + const HttpNetworkSessionParams& http_network_session_params) { + http_network_session_params_ = http_network_session_params; + } + URLRequestContext* Build(); private: @@ -98,6 +118,7 @@ class NET_EXPORT URLRequestContextBuilder { HostResolverParams host_resolver_params_; bool http_cache_enabled_; HttpCacheParams http_cache_params_; + HttpNetworkSessionParams http_network_session_params_; #if defined(OS_LINUX) scoped_ptr<ProxyConfigService> proxy_config_service_; #endif // defined(OS_LINUX) diff --git a/webkit/tools/test_shell/test_shell_request_context.cc b/webkit/tools/test_shell/test_shell_request_context.cc index b5b8dd3..3427da0 100644 --- a/webkit/tools/test_shell/test_shell_request_context.cc +++ b/webkit/tools/test_shell/test_shell_request_context.cc @@ -18,6 +18,7 @@ #include "net/cookies/cookie_monster.h" #include "net/ftp/ftp_network_layer.h" #include "net/http/http_auth_handler_factory.h" +#include "net/http/http_network_session.h" #include "net/http/http_server_properties_impl.h" #include "net/proxy/proxy_config_service.h" #include "net/proxy/proxy_config_service_fixed.h" @@ -95,21 +96,20 @@ void TestShellRequestContext::Init( cache_path.empty() ? net::MEMORY_CACHE : net::DISK_CACHE, cache_path, 0, SimpleResourceLoaderBridge::GetCacheThread()); - net::HttpCache* cache = - new net::HttpCache(host_resolver(), - cert_verifier(), - server_bound_cert_service(), - NULL, /* transport_security_state */ - proxy_service(), - "", /* ssl_session_cache_shard */ - ssl_config_service(), - http_auth_handler_factory(), - NULL, /* network_delegate */ - http_server_properties(), - NULL, /* netlog */ - backend, - "" /* trusted_spdy_proxy */ ); - + net::HttpNetworkSession::Params network_session_params; + network_session_params.host_resolver = host_resolver(); + network_session_params.cert_verifier = cert_verifier(); + network_session_params.server_bound_cert_service = + server_bound_cert_service(); + network_session_params.proxy_service = proxy_service(); + network_session_params.ssl_config_service = ssl_config_service(); + network_session_params.http_auth_handler_factory = + http_auth_handler_factory(); + network_session_params.http_server_properties = http_server_properties(); + network_session_params.host_resolver = host_resolver(); + + net::HttpCache* cache = new net::HttpCache( + network_session_params, backend); cache->set_mode(cache_mode); storage_.set_http_transaction_factory(cache); |