| 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/threading/thread.h" | 13 #include "base/threading/thread.h" |
| 14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.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/base/ssl_config_service_defaults.h" | 19 #include "net/base/ssl_config_service_defaults.h" |
| 20 #include "net/base/transport_security_state.h" | 20 #include "net/base/transport_security_state.h" |
| 21 #include "net/cookies/cookie_monster.h" | 21 #include "net/cookies/cookie_monster.h" |
| 22 #include "net/ftp/ftp_network_layer.h" | 22 #include "net/ftp/ftp_network_layer.h" |
| 23 #include "net/http/http_auth_handler_factory.h" | 23 #include "net/http/http_auth_handler_factory.h" |
| 24 #include "net/http/http_cache.h" | 24 #include "net/http/http_cache.h" |
| 25 #include "net/http/http_network_layer.h" | 25 #include "net/http/http_network_layer.h" |
| 26 #include "net/http/http_network_session.h" | 26 #include "net/http/http_network_session.h" |
| 27 #include "net/http/http_server_properties_impl.h" | 27 #include "net/http/http_server_properties_impl.h" |
| 28 #include "net/proxy/proxy_service.h" | 28 #include "net/proxy/proxy_service.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" |
| 29 #include "net/url_request/static_http_user_agent_settings.h" | 32 #include "net/url_request/static_http_user_agent_settings.h" |
| 30 #include "net/url_request/url_request_context.h" | 33 #include "net/url_request/url_request_context.h" |
| 31 #include "net/url_request/url_request_context_storage.h" | 34 #include "net/url_request/url_request_context_storage.h" |
| 35 #include "net/url_request/url_request_job_factory_impl.h" |
| 32 | 36 |
| 33 namespace net { | 37 namespace net { |
| 34 | 38 |
| 35 namespace { | 39 namespace { |
| 36 | 40 |
| 37 class BasicNetworkDelegate : public NetworkDelegate { | 41 class BasicNetworkDelegate : public NetworkDelegate { |
| 38 public: | 42 public: |
| 39 BasicNetworkDelegate() {} | 43 BasicNetworkDelegate() {} |
| 40 virtual ~BasicNetworkDelegate() {} | 44 virtual ~BasicNetworkDelegate() {} |
| 41 | 45 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 host_mapping_rules(NULL), | 177 host_mapping_rules(NULL), |
| 174 http_pipelining_enabled(false), | 178 http_pipelining_enabled(false), |
| 175 testing_fixed_http_port(0), | 179 testing_fixed_http_port(0), |
| 176 testing_fixed_https_port(0), | 180 testing_fixed_https_port(0), |
| 177 trusted_spdy_proxy() {} | 181 trusted_spdy_proxy() {} |
| 178 | 182 |
| 179 URLRequestContextBuilder::HttpNetworkSessionParams::~HttpNetworkSessionParams() | 183 URLRequestContextBuilder::HttpNetworkSessionParams::~HttpNetworkSessionParams() |
| 180 {} | 184 {} |
| 181 | 185 |
| 182 URLRequestContextBuilder::URLRequestContextBuilder() | 186 URLRequestContextBuilder::URLRequestContextBuilder() |
| 183 : ftp_enabled_(false), | 187 : data_enabled_(false), |
| 188 file_enabled_(false), |
| 189 ftp_enabled_(false), |
| 184 http_cache_enabled_(true) {} | 190 http_cache_enabled_(true) {} |
| 185 URLRequestContextBuilder::~URLRequestContextBuilder() {} | 191 URLRequestContextBuilder::~URLRequestContextBuilder() {} |
| 186 | 192 |
| 187 #if defined(OS_LINUX) || defined(OS_ANDROID) | 193 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 188 void URLRequestContextBuilder::set_proxy_config_service( | 194 void URLRequestContextBuilder::set_proxy_config_service( |
| 189 ProxyConfigService* proxy_config_service) { | 195 ProxyConfigService* proxy_config_service) { |
| 190 proxy_config_service_.reset(proxy_config_service); | 196 proxy_config_service_.reset(proxy_config_service); |
| 191 } | 197 } |
| 192 #endif // defined(OS_LINUX) || defined(OS_ANDROID) | 198 #endif // defined(OS_LINUX) || defined(OS_ANDROID) |
| 193 | 199 |
| 194 URLRequestContext* URLRequestContextBuilder::Build() { | 200 URLRequestContext* URLRequestContextBuilder::Build() { |
| 195 BasicURLRequestContext* context = new BasicURLRequestContext; | 201 BasicURLRequestContext* context = new BasicURLRequestContext; |
| 196 URLRequestContextStorage* storage = context->storage(); | 202 URLRequestContextStorage* storage = context->storage(); |
| 197 | 203 |
| 198 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( | 204 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( |
| 199 accept_language_, accept_charset_, user_agent_)); | 205 accept_language_, accept_charset_, user_agent_)); |
| 200 | 206 |
| 201 if (!network_delegate_) | 207 if (!network_delegate_) |
| 202 network_delegate_.reset(new BasicNetworkDelegate); | 208 network_delegate_.reset(new BasicNetworkDelegate); |
| 203 storage->set_network_delegate(network_delegate_.release()); | 209 storage->set_network_delegate(network_delegate_.release()); |
| 204 | 210 |
| 205 storage->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); | 211 storage->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL)); |
| 206 | 212 |
| 207 if (ftp_enabled_) { | |
| 208 storage->set_ftp_transaction_factory( | |
| 209 new FtpNetworkLayer(context->host_resolver())); | |
| 210 } | |
| 211 | |
| 212 context->StartFileThread(); | 213 context->StartFileThread(); |
| 213 | 214 |
| 214 // TODO(willchan): Switch to using this code when | 215 // TODO(willchan): Switch to using this code when |
| 215 // ProxyService::CreateSystemProxyConfigService()'s signature doesn't suck. | 216 // ProxyService::CreateSystemProxyConfigService()'s signature doesn't suck. |
| 216 #if defined(OS_LINUX) || defined(OS_ANDROID) | 217 #if defined(OS_LINUX) || defined(OS_ANDROID) |
| 217 ProxyConfigService* proxy_config_service = proxy_config_service_.release(); | 218 ProxyConfigService* proxy_config_service = proxy_config_service_.release(); |
| 218 #else | 219 #else |
| 219 ProxyConfigService* proxy_config_service = | 220 ProxyConfigService* proxy_config_service = |
| 220 ProxyService::CreateSystemProxyConfigService( | 221 ProxyService::CreateSystemProxyConfigService( |
| 221 base::ThreadTaskRunnerHandle::Get(), | 222 base::ThreadTaskRunnerHandle::Get(), |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 http_transaction_factory = new HttpCache( | 284 http_transaction_factory = new HttpCache( |
| 284 network_session_params, http_cache_backend); | 285 network_session_params, http_cache_backend); |
| 285 } else { | 286 } else { |
| 286 scoped_refptr<net::HttpNetworkSession> network_session( | 287 scoped_refptr<net::HttpNetworkSession> network_session( |
| 287 new net::HttpNetworkSession(network_session_params)); | 288 new net::HttpNetworkSession(network_session_params)); |
| 288 | 289 |
| 289 http_transaction_factory = new HttpNetworkLayer(network_session); | 290 http_transaction_factory = new HttpNetworkLayer(network_session); |
| 290 } | 291 } |
| 291 storage->set_http_transaction_factory(http_transaction_factory); | 292 storage->set_http_transaction_factory(http_transaction_factory); |
| 292 | 293 |
| 294 URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl; |
| 295 if (data_enabled_) |
| 296 job_factory->SetProtocolHandler("data", new DataProtocolHandler); |
| 297 if (file_enabled_) |
| 298 job_factory->SetProtocolHandler("file", new FileProtocolHandler); |
| 299 if (ftp_enabled_) { |
| 300 ftp_transaction_factory_.reset( |
| 301 new FtpNetworkLayer(context->host_resolver())); |
| 302 job_factory->SetProtocolHandler("ftp", |
| 303 new FtpProtocolHandler(ftp_transaction_factory_.get())); |
| 304 } |
| 305 storage->set_job_factory(job_factory); |
| 306 |
| 293 // TODO(willchan): Support sdch. | 307 // TODO(willchan): Support sdch. |
| 294 | 308 |
| 295 return context; | 309 return context; |
| 296 } | 310 } |
| 297 | 311 |
| 298 } // namespace net | 312 } // namespace net |
| OLD | NEW |