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/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/thread_task_runner_handle.h" | 14 #include "base/thread_task_runner_handle.h" |
15 #include "base/threading/thread.h" | 15 #include "base/threading/thread.h" |
16 #include "net/base/cache_type.h" | 16 #include "net/base/cache_type.h" |
17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
18 #include "net/base/network_delegate_impl.h" | 18 #include "net/base/network_delegate_impl.h" |
19 #include "net/base/sdch_manager.h" | 19 #include "net/base/sdch_manager.h" |
20 #include "net/cert/cert_verifier.h" | 20 #include "net/cert/cert_verifier.h" |
21 #include "net/cookies/cookie_monster.h" | 21 #include "net/cookies/cookie_monster.h" |
22 #include "net/dns/host_resolver.h" | 22 #include "net/dns/host_resolver.h" |
23 #include "net/ftp/ftp_network_layer.h" | 23 #include "net/ftp/ftp_network_layer.h" |
24 #include "net/http/http_auth_handler_factory.h" | 24 #include "net/http/http_auth_handler_factory.h" |
25 #include "net/http/http_cache.h" | 25 #include "net/http/http_cache.h" |
26 #include "net/http/http_network_layer.h" | 26 #include "net/http/http_network_layer.h" |
27 #include "net/http/http_network_session.h" | 27 #include "net/http/http_network_session.h" |
28 #include "net/http/http_server_properties_impl.h" | 28 #include "net/http/http_server_properties_impl.h" |
| 29 #include "net/http/http_transaction_factory.h" |
29 #include "net/http/transport_security_persister.h" | 30 #include "net/http/transport_security_persister.h" |
30 #include "net/http/transport_security_state.h" | 31 #include "net/http/transport_security_state.h" |
31 #include "net/ssl/channel_id_service.h" | 32 #include "net/ssl/channel_id_service.h" |
32 #include "net/ssl/default_channel_id_store.h" | 33 #include "net/ssl/default_channel_id_store.h" |
33 #include "net/ssl/ssl_config_service_defaults.h" | 34 #include "net/ssl/ssl_config_service_defaults.h" |
34 #include "net/url_request/data_protocol_handler.h" | 35 #include "net/url_request/data_protocol_handler.h" |
35 #include "net/url_request/static_http_user_agent_settings.h" | 36 #include "net/url_request/static_http_user_agent_settings.h" |
36 #include "net/url_request/url_request_context.h" | 37 #include "net/url_request/url_request_context.h" |
37 #include "net/url_request/url_request_context_storage.h" | 38 #include "net/url_request/url_request_context_storage.h" |
38 #include "net/url_request/url_request_intercepting_job_factory.h" | 39 #include "net/url_request/url_request_intercepting_job_factory.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 123 |
123 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); | 124 DISALLOW_COPY_AND_ASSIGN(BasicNetworkDelegate); |
124 }; | 125 }; |
125 | 126 |
126 class BasicURLRequestContext : public URLRequestContext { | 127 class BasicURLRequestContext : public URLRequestContext { |
127 public: | 128 public: |
128 explicit BasicURLRequestContext( | 129 explicit BasicURLRequestContext( |
129 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) | 130 const scoped_refptr<base::SingleThreadTaskRunner>& file_task_runner) |
130 : file_task_runner_(file_task_runner), storage_(this) {} | 131 : file_task_runner_(file_task_runner), storage_(this) {} |
131 | 132 |
132 URLRequestContextStorage* storage() { | 133 URLRequestContextStorage* storage() override { |
133 return &storage_; | 134 return &storage_; |
134 } | 135 } |
135 | 136 |
136 scoped_refptr<base::SingleThreadTaskRunner>& GetFileTaskRunner() { | 137 scoped_refptr<base::SingleThreadTaskRunner>& GetFileTaskRunner() { |
137 // Create a new thread to run file tasks, if needed. | 138 // Create a new thread to run file tasks, if needed. |
138 if (!file_task_runner_) { | 139 if (!file_task_runner_) { |
139 DCHECK(!file_thread_); | 140 DCHECK(!file_thread_); |
140 file_thread_.reset(new base::Thread("Network File Thread")); | 141 file_thread_.reset(new base::Thread("Network File Thread")); |
141 file_thread_->StartWithOptions( | 142 file_thread_->StartWithOptions( |
142 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); | 143 base::Thread::Options(base::MessageLoop::TYPE_DEFAULT, 0)); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
196 URLRequestContextBuilder::URLRequestContextBuilder() | 197 URLRequestContextBuilder::URLRequestContextBuilder() |
197 : data_enabled_(false), | 198 : data_enabled_(false), |
198 #if !defined(DISABLE_FILE_SUPPORT) | 199 #if !defined(DISABLE_FILE_SUPPORT) |
199 file_enabled_(false), | 200 file_enabled_(false), |
200 #endif | 201 #endif |
201 #if !defined(DISABLE_FTP_SUPPORT) | 202 #if !defined(DISABLE_FTP_SUPPORT) |
202 ftp_enabled_(false), | 203 ftp_enabled_(false), |
203 #endif | 204 #endif |
204 http_cache_enabled_(true), | 205 http_cache_enabled_(true), |
205 throttling_enabled_(false), | 206 throttling_enabled_(false), |
206 sdch_enabled_(false) { | 207 sdch_enabled_(false), |
| 208 net_log_unowned_(nullptr), |
| 209 http_user_agent_settings_unowned_(nullptr), |
| 210 host_resolver_unowned_(nullptr), |
| 211 cert_transparency_verifier_unowned_(nullptr), |
| 212 http_auth_handler_factory_unowned_(nullptr), |
| 213 network_quality_estimator_unowned_(nullptr), |
| 214 proxy_service_unowned_(nullptr) { |
207 } | 215 } |
208 | 216 |
209 URLRequestContextBuilder::~URLRequestContextBuilder() {} | 217 URLRequestContextBuilder::~URLRequestContextBuilder() {} |
210 | 218 |
211 void URLRequestContextBuilder::EnableHttpCache(const HttpCacheParams& params) { | 219 void URLRequestContextBuilder::EnableHttpCache(const HttpCacheParams& params) { |
212 http_cache_enabled_ = true; | 220 http_cache_enabled_ = true; |
213 http_cache_params_ = params; | 221 http_cache_params_ = params; |
214 } | 222 } |
215 | 223 |
216 void URLRequestContextBuilder::DisableHttpCache() { | 224 void URLRequestContextBuilder::DisableHttpCache() { |
(...skipping 19 matching lines...) Expand all Loading... |
236 DCHECK(cookie_store); | 244 DCHECK(cookie_store); |
237 cookie_store_ = cookie_store; | 245 cookie_store_ = cookie_store; |
238 channel_id_service_ = channel_id_service.Pass(); | 246 channel_id_service_ = channel_id_service.Pass(); |
239 } | 247 } |
240 | 248 |
241 void URLRequestContextBuilder::SetFileTaskRunner( | 249 void URLRequestContextBuilder::SetFileTaskRunner( |
242 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 250 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
243 file_task_runner_ = task_runner; | 251 file_task_runner_ = task_runner; |
244 } | 252 } |
245 | 253 |
| 254 void URLRequestContextBuilder::set_sdch_manager(SdchManager* manager) { |
| 255 sdch_manager_.reset(manager); |
| 256 } |
| 257 |
| 258 void URLRequestContextBuilder::set_job_factory( |
| 259 scoped_ptr<URLRequestJobFactory> factory) { |
| 260 job_factory_ = factory.Pass(); |
| 261 } |
| 262 |
| 263 URLRequestContext* URLRequestContextBuilder::BuildMainContext() { |
| 264 BasicURLRequestContext* context = |
| 265 new BasicURLRequestContext(file_task_runner_); |
| 266 URLRequestContextStorage* storage = context->storage(); |
| 267 |
| 268 // The ordering of the code in this function is important. For example, |
| 269 // the HttpTransactionFactory cannot be created before setting the |
| 270 // CertVerifier. |
| 271 // Do not change the ordering unless you are sure you know what depends on |
| 272 // what. |
| 273 // TODO(wjmaclean): Can this function provide default creation of the |
| 274 // various elements in a manner that would work for a main context? |
| 275 if (fraudulent_certificate_reporter_factory_) { |
| 276 storage->set_fraudulent_certificate_reporter( |
| 277 fraudulent_certificate_reporter_factory_->Create(context)); |
| 278 } else { |
| 279 NOTIMPLEMENTED(); |
| 280 } |
| 281 |
| 282 if (cert_verifier_delegate_) |
| 283 context->set_cert_verifier(cert_verifier_delegate_->Get(context)); |
| 284 else |
| 285 NOTIMPLEMENTED(); |
| 286 |
| 287 if (transport_security_state_.get()) |
| 288 storage->set_transport_security_state(transport_security_state_.release()); |
| 289 else |
| 290 NOTIMPLEMENTED(); |
| 291 |
| 292 if (http_user_agent_settings_unowned_) |
| 293 context->set_http_user_agent_settings(http_user_agent_settings_unowned_); |
| 294 else |
| 295 NOTIMPLEMENTED(); |
| 296 |
| 297 if (ssl_config_service_) |
| 298 context->set_ssl_config_service(ssl_config_service_.get()); |
| 299 else |
| 300 NOTIMPLEMENTED(); |
| 301 |
| 302 if (net_log_unowned_) |
| 303 context->set_net_log(net_log_unowned_); |
| 304 else |
| 305 NOTIMPLEMENTED(); |
| 306 |
| 307 if (network_delegate_) |
| 308 storage->set_network_delegate(network_delegate_.release()); |
| 309 else |
| 310 NOTIMPLEMENTED(); |
| 311 |
| 312 if (http_server_properties_) |
| 313 context->set_http_server_properties(http_server_properties_); |
| 314 else |
| 315 NOTIMPLEMENTED(); |
| 316 |
| 317 if (host_resolver_unowned_) |
| 318 context->set_host_resolver(host_resolver_unowned_); |
| 319 else |
| 320 NOTIMPLEMENTED(); |
| 321 |
| 322 if (cert_transparency_verifier_unowned_) |
| 323 context->set_cert_transparency_verifier(cert_transparency_verifier_unowned_)
; |
| 324 else |
| 325 NOTIMPLEMENTED(); |
| 326 |
| 327 if (http_auth_handler_factory_unowned_) |
| 328 context->set_http_auth_handler_factory(http_auth_handler_factory_unowned_); |
| 329 else |
| 330 NOTIMPLEMENTED(); |
| 331 |
| 332 if (proxy_service_unowned_) |
| 333 context->set_proxy_service(proxy_service_unowned_); |
| 334 else |
| 335 NOTIMPLEMENTED(); |
| 336 |
| 337 if (cookie_store_) { |
| 338 storage->set_cookie_store(cookie_store_.get()); |
| 339 storage->set_channel_id_service(channel_id_service_.Pass()); |
| 340 } else { |
| 341 NOTIMPLEMENTED(); |
| 342 } |
| 343 |
| 344 |
| 345 if (http_transaction_factory_factory_) { |
| 346 storage->set_http_transaction_factory( |
| 347 http_transaction_factory_factory_->Create(context)); |
| 348 } else { |
| 349 NOTIMPLEMENTED(); |
| 350 } |
| 351 |
| 352 if (sdch_manager_) |
| 353 storage->set_sdch_manager(sdch_manager_.Pass()); |
| 354 else |
| 355 NOTIMPLEMENTED(); |
| 356 |
| 357 if (job_factory_) |
| 358 storage->set_job_factory(job_factory_.release()); |
| 359 else |
| 360 NOTIMPLEMENTED(); |
| 361 |
| 362 |
| 363 if (network_quality_estimator_unowned_) |
| 364 context->set_network_quality_estimator(network_quality_estimator_unowned_); |
| 365 else |
| 366 NOTIMPLEMENTED(); |
| 367 |
| 368 return context; |
| 369 } |
| 370 |
246 URLRequestContext* URLRequestContextBuilder::Build() { | 371 URLRequestContext* URLRequestContextBuilder::Build() { |
247 BasicURLRequestContext* context = | 372 BasicURLRequestContext* context = |
248 new BasicURLRequestContext(file_task_runner_); | 373 new BasicURLRequestContext(file_task_runner_); |
249 URLRequestContextStorage* storage = context->storage(); | 374 URLRequestContextStorage* storage = context->storage(); |
250 | 375 |
251 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( | 376 storage->set_http_user_agent_settings(new StaticHttpUserAgentSettings( |
252 accept_language_, user_agent_)); | 377 accept_language_, user_agent_)); |
253 | 378 |
254 if (!network_delegate_) | 379 if (!network_delegate_) |
255 network_delegate_.reset(new BasicNetworkDelegate); | 380 network_delegate_.reset(new BasicNetworkDelegate); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 } | 546 } |
422 url_request_interceptors_.weak_clear(); | 547 url_request_interceptors_.weak_clear(); |
423 } | 548 } |
424 storage->set_job_factory(top_job_factory.release()); | 549 storage->set_job_factory(top_job_factory.release()); |
425 // TODO(willchan): Support sdch. | 550 // TODO(willchan): Support sdch. |
426 | 551 |
427 return context; | 552 return context; |
428 } | 553 } |
429 | 554 |
430 } // namespace net | 555 } // namespace net |
OLD | NEW |