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 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 void URLRequestContextBuilder::SetCookieAndChannelIdStores( | 284 void URLRequestContextBuilder::SetCookieAndChannelIdStores( |
285 std::unique_ptr<CookieStore> cookie_store, | 285 std::unique_ptr<CookieStore> cookie_store, |
286 std::unique_ptr<ChannelIDService> channel_id_service) { | 286 std::unique_ptr<ChannelIDService> channel_id_service) { |
287 cookie_store_set_by_client_ = true; | 287 cookie_store_set_by_client_ = true; |
288 // If |cookie_store| is NULL, |channel_id_service| must be NULL too. | 288 // If |cookie_store| is NULL, |channel_id_service| must be NULL too. |
289 DCHECK(cookie_store || !channel_id_service); | 289 DCHECK(cookie_store || !channel_id_service); |
290 cookie_store_ = std::move(cookie_store); | 290 cookie_store_ = std::move(cookie_store); |
291 channel_id_service_ = std::move(channel_id_service); | 291 channel_id_service_ = std::move(channel_id_service); |
292 } | 292 } |
293 | 293 |
294 void URLRequestContextBuilder::SetFileTaskRunner( | 294 void URLRequestContextBuilder::SetCacheThreadTaskRunner( |
295 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 295 scoped_refptr<base::SingleThreadTaskRunner> cache_thread_task_runner) { |
296 file_task_runner_ = task_runner; | 296 cache_thread_task_runner_ = std::move(cache_thread_task_runner); |
297 } | 297 } |
298 | 298 |
299 void URLRequestContextBuilder::SetProtocolHandler( | 299 void URLRequestContextBuilder::SetProtocolHandler( |
300 const std::string& scheme, | 300 const std::string& scheme, |
301 std::unique_ptr<URLRequestJobFactory::ProtocolHandler> protocol_handler) { | 301 std::unique_ptr<URLRequestJobFactory::ProtocolHandler> protocol_handler) { |
302 DCHECK(protocol_handler); | 302 DCHECK(protocol_handler); |
303 protocol_handlers_[scheme] = std::move(protocol_handler); | 303 protocol_handlers_[scheme] = std::move(protocol_handler); |
304 } | 304 } |
305 | 305 |
306 void URLRequestContextBuilder::SetHttpAuthHandlerFactory( | 306 void URLRequestContextBuilder::SetHttpAuthHandlerFactory( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
376 std::unique_ptr<net::SdchManager>(new SdchManager())); | 376 std::unique_ptr<net::SdchManager>(new SdchManager())); |
377 } | 377 } |
378 | 378 |
379 storage->set_transport_security_state( | 379 storage->set_transport_security_state( |
380 base::MakeUnique<TransportSecurityState>()); | 380 base::MakeUnique<TransportSecurityState>()); |
381 if (!transport_security_persister_path_.empty()) { | 381 if (!transport_security_persister_path_.empty()) { |
382 // Use a low priority because saving this should not block anything | 382 // Use a low priority because saving this should not block anything |
383 // user-visible. Block shutdown to ensure it does get persisted to disk, | 383 // user-visible. Block shutdown to ensure it does get persisted to disk, |
384 // since it contains security-relevant information. | 384 // since it contains security-relevant information. |
385 scoped_refptr<base::SequencedTaskRunner> task_runner( | 385 scoped_refptr<base::SequencedTaskRunner> task_runner( |
386 GetFileSequencedTaskRunner( | 386 base::CreateSequencedTaskRunnerWithTraits( |
387 {base::MayBlock(), base::TaskPriority::BACKGROUND, | 387 {base::MayBlock(), base::TaskPriority::BACKGROUND, |
388 base::TaskShutdownBehavior::BLOCK_SHUTDOWN})); | 388 base::TaskShutdownBehavior::BLOCK_SHUTDOWN})); |
389 | 389 |
390 context->set_transport_security_persister( | 390 context->set_transport_security_persister( |
391 base::WrapUnique<TransportSecurityPersister>( | 391 base::WrapUnique<TransportSecurityPersister>( |
392 new TransportSecurityPersister(context->transport_security_state(), | 392 new TransportSecurityPersister(context->transport_security_state(), |
393 transport_security_persister_path_, | 393 transport_security_persister_path_, |
394 task_runner, false))); | 394 task_runner, false))); |
395 } | 395 } |
396 | 396 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 storage->set_proxy_delegate(std::move(proxy_delegate_)); | 452 storage->set_proxy_delegate(std::move(proxy_delegate_)); |
453 } | 453 } |
454 | 454 |
455 storage->set_http_network_session(base::MakeUnique<HttpNetworkSession>( | 455 storage->set_http_network_session(base::MakeUnique<HttpNetworkSession>( |
456 http_network_session_params_, network_session_context)); | 456 http_network_session_params_, network_session_context)); |
457 | 457 |
458 std::unique_ptr<HttpTransactionFactory> http_transaction_factory; | 458 std::unique_ptr<HttpTransactionFactory> http_transaction_factory; |
459 if (http_cache_enabled_) { | 459 if (http_cache_enabled_) { |
460 std::unique_ptr<HttpCache::BackendFactory> http_cache_backend; | 460 std::unique_ptr<HttpCache::BackendFactory> http_cache_backend; |
461 if (http_cache_params_.type != HttpCacheParams::IN_MEMORY) { | 461 if (http_cache_params_.type != HttpCacheParams::IN_MEMORY) { |
| 462 if (!cache_thread_task_runner_) { |
| 463 cache_thread_task_runner_ = |
| 464 base::CreateSingleThreadTaskRunnerWithTraits( |
| 465 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, |
| 466 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}); |
| 467 } |
462 BackendType backend_type = | 468 BackendType backend_type = |
463 http_cache_params_.type == HttpCacheParams::DISK | 469 http_cache_params_.type == HttpCacheParams::DISK |
464 ? CACHE_BACKEND_DEFAULT | 470 ? CACHE_BACKEND_DEFAULT |
465 : CACHE_BACKEND_SIMPLE; | 471 : CACHE_BACKEND_SIMPLE; |
466 http_cache_backend.reset(new HttpCache::DefaultBackend( | 472 http_cache_backend.reset(new HttpCache::DefaultBackend( |
467 DISK_CACHE, backend_type, http_cache_params_.path, | 473 DISK_CACHE, backend_type, http_cache_params_.path, |
468 http_cache_params_.max_size, | 474 http_cache_params_.max_size, cache_thread_task_runner_)); |
469 GetFileSingleThreadTaskRunner( | |
470 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, | |
471 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}))); | |
472 } else { | 475 } else { |
473 http_cache_backend = | 476 http_cache_backend = |
474 HttpCache::DefaultBackend::InMemory(http_cache_params_.max_size); | 477 HttpCache::DefaultBackend::InMemory(http_cache_params_.max_size); |
475 } | 478 } |
476 | 479 |
477 http_transaction_factory.reset(new HttpCache( | 480 http_transaction_factory.reset(new HttpCache( |
478 storage->http_network_session(), std::move(http_cache_backend), true)); | 481 storage->http_network_session(), std::move(http_cache_backend), true)); |
479 } else { | 482 } else { |
480 http_transaction_factory.reset( | 483 http_transaction_factory.reset( |
481 new HttpNetworkLayer(storage->http_network_session())); | 484 new HttpNetworkLayer(storage->http_network_session())); |
(...skipping 10 matching lines...) Expand all Loading... |
492 protocol_handlers_.clear(); | 495 protocol_handlers_.clear(); |
493 | 496 |
494 if (data_enabled_) | 497 if (data_enabled_) |
495 job_factory->SetProtocolHandler(url::kDataScheme, | 498 job_factory->SetProtocolHandler(url::kDataScheme, |
496 base::WrapUnique(new DataProtocolHandler)); | 499 base::WrapUnique(new DataProtocolHandler)); |
497 | 500 |
498 #if !BUILDFLAG(DISABLE_FILE_SUPPORT) | 501 #if !BUILDFLAG(DISABLE_FILE_SUPPORT) |
499 if (file_enabled_) { | 502 if (file_enabled_) { |
500 job_factory->SetProtocolHandler( | 503 job_factory->SetProtocolHandler( |
501 url::kFileScheme, | 504 url::kFileScheme, |
502 base::MakeUnique<FileProtocolHandler>(GetFileTaskRunner( | 505 base::MakeUnique<FileProtocolHandler>(base::CreateTaskRunnerWithTraits( |
503 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, | 506 {base::MayBlock(), base::TaskPriority::USER_BLOCKING, |
504 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}))); | 507 base::TaskShutdownBehavior::SKIP_ON_SHUTDOWN}))); |
505 } | 508 } |
506 #endif // !BUILDFLAG(DISABLE_FILE_SUPPORT) | 509 #endif // !BUILDFLAG(DISABLE_FILE_SUPPORT) |
507 | 510 |
508 #if !BUILDFLAG(DISABLE_FTP_SUPPORT) | 511 #if !BUILDFLAG(DISABLE_FTP_SUPPORT) |
509 if (ftp_enabled_) { | 512 if (ftp_enabled_) { |
510 job_factory->SetProtocolHandler( | 513 job_factory->SetProtocolHandler( |
511 url::kFtpScheme, FtpProtocolHandler::Create(context->host_resolver())); | 514 url::kFtpScheme, FtpProtocolHandler::Create(context->host_resolver())); |
512 } | 515 } |
(...skipping 25 matching lines...) Expand all Loading... |
538 std::unique_ptr<ProxyService> URLRequestContextBuilder::CreateProxyService( | 541 std::unique_ptr<ProxyService> URLRequestContextBuilder::CreateProxyService( |
539 std::unique_ptr<ProxyConfigService> proxy_config_service, | 542 std::unique_ptr<ProxyConfigService> proxy_config_service, |
540 URLRequestContext* url_request_context, | 543 URLRequestContext* url_request_context, |
541 HostResolver* host_resolver, | 544 HostResolver* host_resolver, |
542 NetworkDelegate* network_delegate, | 545 NetworkDelegate* network_delegate, |
543 NetLog* net_log) { | 546 NetLog* net_log) { |
544 return ProxyService::CreateUsingSystemProxyResolver( | 547 return ProxyService::CreateUsingSystemProxyResolver( |
545 std::move(proxy_config_service), net_log); | 548 std::move(proxy_config_service), net_log); |
546 } | 549 } |
547 | 550 |
548 scoped_refptr<base::TaskRunner> URLRequestContextBuilder::GetFileTaskRunner( | |
549 const base::TaskTraits& traits) { | |
550 if (file_task_runner_) | |
551 return file_task_runner_; | |
552 return base::CreateTaskRunnerWithTraits(traits); | |
553 } | |
554 | |
555 scoped_refptr<base::SequencedTaskRunner> | |
556 URLRequestContextBuilder::GetFileSequencedTaskRunner( | |
557 const base::TaskTraits& traits) { | |
558 if (file_task_runner_) | |
559 return file_task_runner_; | |
560 return base::CreateSequencedTaskRunnerWithTraits(traits); | |
561 } | |
562 | |
563 scoped_refptr<base::SingleThreadTaskRunner> | |
564 URLRequestContextBuilder::GetFileSingleThreadTaskRunner( | |
565 const base::TaskTraits& traits) { | |
566 if (file_task_runner_) | |
567 return file_task_runner_; | |
568 return base::CreateSingleThreadTaskRunnerWithTraits(traits); | |
569 } | |
570 | |
571 } // namespace net | 551 } // namespace net |
OLD | NEW |