diff options
Diffstat (limited to 'chromium/net/url_request/url_request_context_builder.cc')
-rw-r--r-- | chromium/net/url_request/url_request_context_builder.cc | 119 |
1 files changed, 72 insertions, 47 deletions
diff --git a/chromium/net/url_request/url_request_context_builder.cc b/chromium/net/url_request/url_request_context_builder.cc index 465aa87a1b7..93f5b1c0b74 100644 --- a/chromium/net/url_request/url_request_context_builder.cc +++ b/chromium/net/url_request/url_request_context_builder.cc @@ -28,13 +28,19 @@ #include "net/proxy/proxy_service.h" #include "net/ssl/ssl_config_service_defaults.h" #include "net/url_request/data_protocol_handler.h" -#include "net/url_request/file_protocol_handler.h" -#include "net/url_request/ftp_protocol_handler.h" #include "net/url_request/static_http_user_agent_settings.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_storage.h" #include "net/url_request/url_request_job_factory_impl.h" +#if !defined(DISABLE_FILE_SUPPORT) +#include "net/url_request/file_protocol_handler.h" +#endif + +#if !defined(DISABLE_FTP_SUPPORT) +#include "net/url_request/ftp_protocol_handler.h" +#endif + namespace net { namespace { @@ -64,8 +70,8 @@ class BasicNetworkDelegate : public NetworkDelegate { URLRequest* request, const CompletionCallback& callback, const HttpResponseHeaders* original_response_headers, - scoped_refptr<HttpResponseHeaders>* override_response_headers) - OVERRIDE { + scoped_refptr<HttpResponseHeaders>* override_response_headers, + GURL* allowed_unsafe_redirect_url) OVERRIDE { return OK; } @@ -118,55 +124,42 @@ class BasicNetworkDelegate : public NetworkDelegate { return OK; } - virtual void OnRequestWaitStateChange(const URLRequest& request, - RequestWaitState state) OVERRIDE { - } - DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); }; class BasicURLRequestContext : public URLRequestContext { public: BasicURLRequestContext() - : cache_thread_("Cache Thread"), - file_thread_("File Thread"), - storage_(this) {} + : storage_(this) {} URLRequestContextStorage* storage() { return &storage_; } - void StartCacheThread() { - cache_thread_.StartWithOptions( - base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); - } - - scoped_refptr<base::MessageLoopProxy> cache_message_loop_proxy() { - DCHECK(cache_thread_.IsRunning()); - return cache_thread_.message_loop_proxy(); - } - - void StartFileThread() { - file_thread_.StartWithOptions( - base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); - } - - base::MessageLoop* file_message_loop() { - DCHECK(file_thread_.IsRunning()); - return file_thread_.message_loop(); + base::Thread* GetCacheThread() { + if (!cache_thread_) { + cache_thread_.reset(new base::Thread("Cache Thread")); + cache_thread_->StartWithOptions( + base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); + } + return cache_thread_.get(); } - scoped_refptr<base::MessageLoopProxy> file_message_loop_proxy() { - DCHECK(file_thread_.IsRunning()); - return file_thread_.message_loop_proxy(); + base::Thread* GetFileThread() { + if (!file_thread_) { + file_thread_.reset(new base::Thread("File Thread")); + file_thread_->StartWithOptions( + base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); + } + return file_thread_.get(); } protected: virtual ~BasicURLRequestContext() {} private: - base::Thread cache_thread_; - base::Thread file_thread_; + scoped_ptr<base::Thread> cache_thread_; + scoped_ptr<base::Thread> file_thread_; URLRequestContextStorage storage_; DISALLOW_COPY_AND_ASSIGN(BasicURLRequestContext); }; @@ -181,17 +174,29 @@ 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() {} + next_protos(NextProtosDefaults()), + use_alternate_protocols(true) { +} URLRequestContextBuilder::HttpNetworkSessionParams::~HttpNetworkSessionParams() {} +URLRequestContextBuilder::SchemeFactory::SchemeFactory( + const std::string& auth_scheme, + net::HttpAuthHandlerFactory* auth_handler_factory) + : scheme(auth_scheme), factory(auth_handler_factory) { +} + +URLRequestContextBuilder::SchemeFactory::~SchemeFactory() { +} + URLRequestContextBuilder::URLRequestContextBuilder() : data_enabled_(false), +#if !defined(DISABLE_FILE_SUPPORT) file_enabled_(false), +#endif #if !defined(DISABLE_FTP_SUPPORT) ftp_enabled_(false), #endif @@ -205,6 +210,12 @@ void URLRequestContextBuilder::set_proxy_config_service( proxy_config_service_.reset(proxy_config_service); } +void URLRequestContextBuilder::SetSpdyAndQuicEnabled(bool spdy_enabled, + bool quic_enabled) { + http_network_session_params_.next_protos = + NextProtosWithSpdyAndQuic(spdy_enabled, quic_enabled); +} + URLRequestContext* URLRequestContextBuilder::Build() { BasicURLRequestContext* context = new BasicURLRequestContext; URLRequestContextStorage* storage = context->storage(); @@ -221,7 +232,7 @@ URLRequestContext* URLRequestContextBuilder::Build() { host_resolver_ = net::HostResolver::CreateDefaultResolver(NULL); storage->set_host_resolver(host_resolver_.Pass()); - context->StartFileThread(); + storage->set_net_log(new net::NetLog); // TODO(willchan): Switch to using this code when // ProxyService::CreateSystemProxyConfigService()'s signature doesn't suck. @@ -235,7 +246,7 @@ URLRequestContext* URLRequestContextBuilder::Build() { proxy_config_service = ProxyService::CreateSystemProxyConfigService( base::ThreadTaskRunnerHandle::Get().get(), - context->file_message_loop()); + context->GetFileThread()->message_loop()); } #endif // defined(OS_LINUX) || defined(OS_ANDROID) storage->set_proxy_service( @@ -244,9 +255,15 @@ URLRequestContext* URLRequestContextBuilder::Build() { 4, // TODO(willchan): Find a better constant somewhere. context->net_log())); storage->set_ssl_config_service(new net::SSLConfigServiceDefaults); - storage->set_http_auth_handler_factory( + HttpAuthHandlerRegistryFactory* http_auth_handler_registry_factory = net::HttpAuthHandlerRegistryFactory::CreateDefault( - context->host_resolver())); + context->host_resolver()); + for (size_t i = 0; i < extra_http_auth_handlers_.size(); ++i) { + http_auth_handler_registry_factory->RegisterSchemeFactory( + extra_http_auth_handlers_[i].scheme, + extra_http_auth_handlers_[i].factory); + } + storage->set_http_auth_handler_factory(http_auth_handler_registry_factory); storage->set_cookie_store(new CookieMonster(NULL, NULL)); storage->set_transport_security_state(new net::TransportSecurityState()); storage->set_http_server_properties( @@ -268,18 +285,20 @@ URLRequestContext* URLRequestContextBuilder::Build() { 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.use_alternate_protocols = + http_network_session_params_.use_alternate_protocols; network_session_params.trusted_spdy_proxy = http_network_session_params_.trusted_spdy_proxy; + network_session_params.next_protos = http_network_session_params_.next_protos; HttpTransactionFactory* http_transaction_factory = NULL; if (http_cache_enabled_) { @@ -287,13 +306,12 @@ URLRequestContext* URLRequestContextBuilder::Build() { context->server_bound_cert_service(); HttpCache::BackendFactory* http_cache_backend = NULL; if (http_cache_params_.type == HttpCacheParams::DISK) { - context->StartCacheThread(); http_cache_backend = new HttpCache::DefaultBackend( DISK_CACHE, net::CACHE_BACKEND_DEFAULT, http_cache_params_.path, http_cache_params_.max_size, - context->cache_message_loop_proxy().get()); + context->GetCacheThread()->message_loop_proxy().get()); } else { http_cache_backend = HttpCache::DefaultBackend::InMemory(http_cache_params_.max_size); @@ -312,9 +330,15 @@ URLRequestContext* URLRequestContextBuilder::Build() { URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl; if (data_enabled_) job_factory->SetProtocolHandler("data", new DataProtocolHandler); - if (file_enabled_) + +#if !defined(DISABLE_FILE_SUPPORT) + if (file_enabled_) { job_factory->SetProtocolHandler( - "file", new FileProtocolHandler(context->file_message_loop_proxy())); + "file", + new FileProtocolHandler(context->GetFileThread()->message_loop_proxy())); + } +#endif // !defined(DISABLE_FILE_SUPPORT) + #if !defined(DISABLE_FTP_SUPPORT) if (ftp_enabled_) { ftp_transaction_factory_.reset( @@ -322,7 +346,8 @@ URLRequestContext* URLRequestContextBuilder::Build() { job_factory->SetProtocolHandler("ftp", new FtpProtocolHandler(ftp_transaction_factory_.get())); } -#endif +#endif // !defined(DISABLE_FTP_SUPPORT) + storage->set_job_factory(job_factory); // TODO(willchan): Support sdch. |