| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/url_request/url_request_context_builder.h" | 5 #include "net/url_request/url_request_context_builder.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
| 15 #include "net/base/cert_verifier.h" | 15 #include "net/base/cert_verifier.h" |
| 16 #include "net/base/host_resolver.h" | 16 #include "net/base/host_resolver.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/base/network_delegate.h" | 18 #include "net/base/network_delegate.h" |
| 19 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
| 20 #include "net/ftp/ftp_network_layer.h" | 20 #include "net/ftp/ftp_network_layer.h" |
| 21 #include "net/http/http_auth_handler_factory.h" | 21 #include "net/http/http_auth_handler_factory.h" |
| 22 #include "net/http/http_cache.h" | 22 #include "net/http/http_cache.h" |
| 23 #include "net/http/http_network_layer.h" | 23 #include "net/http/http_network_layer.h" |
| 24 #include "net/http/http_network_session.h" | 24 #include "net/http/http_network_session.h" |
| 25 #include "net/http/http_server_properties_impl.h" | 25 #include "net/http/http_server_properties_impl.h" |
| 26 #include "net/http/transport_security_state.h" | 26 #include "net/http/transport_security_state.h" |
| 27 #include "net/proxy/proxy_service.h" | 27 #include "net/proxy/proxy_service.h" |
| 28 #include "net/ssl/ssl_config_service_defaults.h" | 28 #include "net/ssl/ssl_config_service_defaults.h" |
| 29 #include "net/url_request/data_protocol_handler.h" | |
| 30 #include "net/url_request/file_protocol_handler.h" | |
| 31 #include "net/url_request/ftp_protocol_handler.h" | |
| 32 #include "net/url_request/static_http_user_agent_settings.h" | 29 #include "net/url_request/static_http_user_agent_settings.h" |
| 33 #include "net/url_request/url_request_context.h" | 30 #include "net/url_request/url_request_context.h" |
| 34 #include "net/url_request/url_request_context_storage.h" | 31 #include "net/url_request/url_request_context_storage.h" |
| 35 #include "net/url_request/url_request_job_factory_impl.h" | |
| 36 | 32 |
| 37 namespace net { | 33 namespace net { |
| 38 | 34 |
| 39 namespace { | 35 namespace { |
| 40 | 36 |
| 41 class BasicNetworkDelegate : public NetworkDelegate { | 37 class BasicNetworkDelegate : public NetworkDelegate { |
| 42 public: | 38 public: |
| 43 BasicNetworkDelegate() {} | 39 BasicNetworkDelegate() {} |
| 44 virtual ~BasicNetworkDelegate() {} | 40 virtual ~BasicNetworkDelegate() {} |
| 45 | 41 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 host_mapping_rules(NULL), | 173 host_mapping_rules(NULL), |
| 178 http_pipelining_enabled(false), | 174 http_pipelining_enabled(false), |
| 179 testing_fixed_http_port(0), | 175 testing_fixed_http_port(0), |
| 180 testing_fixed_https_port(0), | 176 testing_fixed_https_port(0), |
| 181 trusted_spdy_proxy() {} | 177 trusted_spdy_proxy() {} |
| 182 | 178 |
| 183 URLRequestContextBuilder::HttpNetworkSessionParams::~HttpNetworkSessionParams() | 179 URLRequestContextBuilder::HttpNetworkSessionParams::~HttpNetworkSessionParams() |
| 184 {} | 180 {} |
| 185 | 181 |
| 186 URLRequestContextBuilder::URLRequestContextBuilder() | 182 URLRequestContextBuilder::URLRequestContextBuilder() |
| 187 : data_enabled_(false), | 183 : ftp_enabled_(false), |
| 188 file_enabled_(false), | |
| 189 #if !defined(DISABLE_FTP_SUPPORT) | |
| 190 ftp_enabled_(false), | |
| 191 #endif | |
| 192 http_cache_enabled_(true) {} | 184 http_cache_enabled_(true) {} |
| 193 URLRequestContextBuilder::~URLRequestContextBuilder() {} | 185 URLRequestContextBuilder::~URLRequestContextBuilder() {} |
| 194 | 186 |
| 195 #if defined(OS_LINUX) || defined(OS_ANDROID) | 187 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 196 void URLRequestContextBuilder::set_proxy_config_service( | 188 void URLRequestContextBuilder::set_proxy_config_service( |
| 197 ProxyConfigService* proxy_config_service) { | 189 ProxyConfigService* proxy_config_service) { |
| 198 proxy_config_service_.reset(proxy_config_service); | 190 proxy_config_service_.reset(proxy_config_service); |
| 199 } | 191 } |
| 200 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 192 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 201 | 193 |
| 202 URLRequestContext* URLRequestContextBuilder::Build() { | 194 URLRequestContext* URLRequestContextBuilder::Build() { |
| 203 BasicURLRequestContext* context = new BasicURLRequestContext; | 195 BasicURLRequestContext* context = new BasicURLRequestContext; |
| 204 URLRequestContextStorage* storage = context->storage(); | 196 URLRequestContextStorage* storage = context->storage(); |
| 205 | 197 |
| 206 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( | 198 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( |
| 207 accept_language_, user_agent_)); | 199 accept_language_, user_agent_)); |
| 208 | 200 |
| 209 if (!network_delegate_) | 201 if (!network_delegate_) |
| 210 network_delegate_.reset(new BasicNetworkDelegate); | 202 network_delegate_.reset(new BasicNetworkDelegate); |
| 211 NetworkDelegate* network_delegate = network_delegate_.release(); | 203 NetworkDelegate* network_delegate = network_delegate_.release(); |
| 212 storage->set_network_delegate(network_delegate); | 204 storage->set_network_delegate(network_delegate); |
| 213 | 205 |
| 214 storage->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); | 206 storage->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); |
| 215 | 207 |
| 208 if (ftp_enabled_) { |
| 209 storage->set_ftp_transaction_factory( |
| 210 new FtpNetworkLayer(context->host_resolver())); |
| 211 } |
| 212 |
| 216 context->StartFileThread(); | 213 context->StartFileThread(); |
| 217 | 214 |
| 218 // TODO(willchan): Switch to using this code when | 215 // TODO(willchan): Switch to using this code when |
| 219 // ProxyService::CreateSystemProxyConfigService()'s signature doesn't suck. | 216 // ProxyService::CreateSystemProxyConfigService()'s signature doesn't suck. |
| 220 #if defined(OS_LINUX) || defined(OS_ANDROID) | 217 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 221 ProxyConfigService* proxy_config_service = proxy_config_service_.release(); | 218 ProxyConfigService* proxy_config_service = proxy_config_service_.release(); |
| 222 #else | 219 #else |
| 223 ProxyConfigService* proxy_config_service = | 220 ProxyConfigService* proxy_config_service = |
| 224 ProxyService::CreateSystemProxyConfigService( | 221 ProxyService::CreateSystemProxyConfigService( |
| 225 base::ThreadTaskRunnerHandle::Get(), | 222 base::ThreadTaskRunnerHandle::Get(), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 http_transaction_factory = new HttpCache( | 283 http_transaction_factory = new HttpCache( |
| 287 network_session_params, http_cache_backend); | 284 network_session_params, http_cache_backend); |
| 288 } else { | 285 } else { |
| 289 scoped_refptr<net::HttpNetworkSession> network_session( | 286 scoped_refptr<net::HttpNetworkSession> network_session( |
| 290 new net::HttpNetworkSession(network_session_params)); | 287 new net::HttpNetworkSession(network_session_params)); |
| 291 | 288 |
| 292 http_transaction_factory = new HttpNetworkLayer(network_session); | 289 http_transaction_factory = new HttpNetworkLayer(network_session); |
| 293 } | 290 } |
| 294 storage->set_http_transaction_factory(http_transaction_factory); | 291 storage->set_http_transaction_factory(http_transaction_factory); |
| 295 | 292 |
| 296 URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl; | |
| 297 if (data_enabled_) | |
| 298 job_factory->SetProtocolHandler("data", new DataProtocolHandler); | |
| 299 if (file_enabled_) | |
| 300 job_factory->SetProtocolHandler("file", new FileProtocolHandler); | |
| 301 #if !defined(DISABLE_FTP_SUPPORT) | |
| 302 if (ftp_enabled_) { | |
| 303 ftp_transaction_factory_.reset( | |
| 304 new FtpNetworkLayer(context->host_resolver())); | |
| 305 job_factory->SetProtocolHandler("ftp", | |
| 306 new FtpProtocolHandler(ftp_transaction_factory_.get())); | |
| 307 } | |
| 308 #endif | |
| 309 storage->set_job_factory(job_factory); | |
| 310 | |
| 311 // TODO(willchan): Support sdch. | 293 // TODO(willchan): Support sdch. |
| 312 | 294 |
| 313 return context; | 295 return context; |
| 314 } | 296 } |
| 315 | 297 |
| 316 } // namespace net | 298 } // namespace net |
| OLD | NEW |