Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(210)

Side by Side Diff: chrome/browser/profiles/profile_impl_io_data.cc

Issue 1239393003: Refactor main URLRequestContext creation to use URLRequestContextBuilder Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/profiles/profile_impl_io_data.h" 5 #include "chrome/browser/profiles/profile_impl_io_data.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 #include "content/public/browser/storage_partition.h" 53 #include "content/public/browser/storage_partition.h"
54 #include "extensions/browser/extension_protocols.h" 54 #include "extensions/browser/extension_protocols.h"
55 #include "extensions/common/constants.h" 55 #include "extensions/common/constants.h"
56 #include "net/base/cache_type.h" 56 #include "net/base/cache_type.h"
57 #include "net/base/sdch_manager.h" 57 #include "net/base/sdch_manager.h"
58 #include "net/ftp/ftp_network_layer.h" 58 #include "net/ftp/ftp_network_layer.h"
59 #include "net/http/http_cache.h" 59 #include "net/http/http_cache.h"
60 #include "net/http/http_server_properties_manager.h" 60 #include "net/http/http_server_properties_manager.h"
61 #include "net/sdch/sdch_owner.h" 61 #include "net/sdch/sdch_owner.h"
62 #include "net/ssl/channel_id_service.h" 62 #include "net/ssl/channel_id_service.h"
63 #include "net/url_request/url_request_context_builder.h"
64 #include "net/url_request/url_request_context_storage.h"
63 #include "net/url_request/url_request_intercepting_job_factory.h" 65 #include "net/url_request/url_request_intercepting_job_factory.h"
64 #include "net/url_request/url_request_job_factory_impl.h" 66 #include "net/url_request/url_request_job_factory_impl.h"
65 #include "storage/browser/quota/special_storage_policy.h" 67 #include "storage/browser/quota/special_storage_policy.h"
66 68
67 namespace { 69 namespace {
68 70
69 net::BackendType ChooseCacheBackendType() { 71 net::BackendType ChooseCacheBackendType() {
70 #if defined(OS_ANDROID) 72 #if defined(OS_ANDROID)
71 return net::CACHE_BACKEND_SIMPLE; 73 return net::CACHE_BACKEND_SIMPLE;
72 #else 74 #else
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
439 DestroyResourceContext(); 441 DestroyResourceContext();
440 442
441 if (media_request_context_) 443 if (media_request_context_)
442 media_request_context_->AssertNoURLRequests(); 444 media_request_context_->AssertNoURLRequests();
443 } 445 }
444 446
445 void ProfileImplIOData::InitializeInternal( 447 void ProfileImplIOData::InitializeInternal(
446 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate, 448 scoped_ptr<ChromeNetworkDelegate> chrome_network_delegate,
447 ProfileParams* profile_params, 449 ProfileParams* profile_params,
448 content::ProtocolHandlerMap* protocol_handlers, 450 content::ProtocolHandlerMap* protocol_handlers,
449 content::URLRequestInterceptorScopedVector request_interceptors) const { 451 content::URLRequestInterceptorScopedVector request_interceptors,
452 net::URLRequestContextBuilder* context_builder) const {
450 // Set up a persistent store for use by the network stack on the IO thread. 453 // Set up a persistent store for use by the network stack on the IO thread.
451 base::FilePath network_json_store_filepath( 454 base::FilePath network_json_store_filepath(
452 profile_path_.Append(chrome::kNetworkPersistentStateFilename)); 455 profile_path_.Append(chrome::kNetworkPersistentStateFilename));
453 network_json_store_ = new JsonPrefStore( 456 network_json_store_ = new JsonPrefStore(
454 network_json_store_filepath, 457 network_json_store_filepath,
455 JsonPrefStore::GetTaskRunnerForFile(network_json_store_filepath, 458 JsonPrefStore::GetTaskRunnerForFile(network_json_store_filepath,
456 BrowserThread::GetBlockingPool()), 459 BrowserThread::GetBlockingPool()),
457 scoped_ptr<PrefFilter>()); 460 scoped_ptr<PrefFilter>());
458 network_json_store_->ReadPrefsAsync(nullptr); 461 network_json_store_->ReadPrefsAsync(nullptr);
459 462
460 net::URLRequestContext* main_context = main_request_context();
461
462 IOThread* const io_thread = profile_params->io_thread; 463 IOThread* const io_thread = profile_params->io_thread;
463 IOThread::Globals* const io_thread_globals = io_thread->globals(); 464 IOThread::Globals* const io_thread_globals = io_thread->globals();
464 465
465 chrome_network_delegate->set_predictor(predictor_.get()); 466 ApplyProfileParamsToContext(context_builder);
466
467 if (domain_reliability_monitor_) {
468 domain_reliability::DomainReliabilityMonitor* monitor =
469 domain_reliability_monitor_.get();
470 monitor->InitURLRequestContext(main_context);
471 monitor->AddBakedInConfigs();
472 monitor->SetDiscardUploads(!GetMetricsEnabledStateOnIOThread());
473 chrome_network_delegate->set_domain_reliability_monitor(monitor);
474 }
475
476 ApplyProfileParamsToContext(main_context);
477 467
478 if (http_server_properties_manager_) 468 if (http_server_properties_manager_)
479 http_server_properties_manager_->InitializeOnNetworkThread(); 469 http_server_properties_manager_->InitializeOnNetworkThread();
480 470
481 main_context->set_transport_security_state(transport_security_state()); 471 context_builder->set_net_log_unowned(io_thread->net_log());
482 472
483 main_context->set_net_log(io_thread->net_log()); 473 // The context receives a WeakPtr to the server properties.
474 // TODO(wjmaclean): presumably this value gets copied to other contexts ...
475 // it would be nice to avoid this.
476 context_builder->set_http_server_properties(http_server_properties());
484 477
485 network_delegate_ = data_reduction_proxy_io_data()->CreateNetworkDelegate( 478 context_builder->set_host_resolver_unowned(
486 chrome_network_delegate.Pass(), true).Pass();
487
488 main_context->set_network_delegate(network_delegate_.get());
489
490 main_context->set_http_server_properties(http_server_properties());
491
492 main_context->set_host_resolver(
493 io_thread_globals->host_resolver.get()); 479 io_thread_globals->host_resolver.get());
494 main_context->set_cert_transparency_verifier( 480 context_builder->set_cert_transparency_verifier_unowned(
495 io_thread_globals->cert_transparency_verifier.get()); 481 io_thread_globals->cert_transparency_verifier.get());
496 main_context->set_http_auth_handler_factory( 482 context_builder->set_http_auth_handler_factory_unowned(
497 io_thread_globals->http_auth_handler_factory.get()); 483 io_thread_globals->http_auth_handler_factory.get());
498 484
499 main_context->set_fraudulent_certificate_reporter( 485 // TODO(wjmaclean): proxy_service() is currently built with all sorts of stuff
500 fraudulent_certificate_reporter()); 486 // from io_globals, so we'll treat it as an unowned pointer for now.
501 487 context_builder->set_proxy_service_unowned(proxy_service());
502 main_context->set_proxy_service(proxy_service());
503 488
504 scoped_refptr<net::CookieStore> cookie_store = NULL; 489 scoped_refptr<net::CookieStore> cookie_store = NULL;
505 net::ChannelIDService* channel_id_service = NULL; 490 net::ChannelIDService* channel_id_service = NULL;
506 491
507 // Set up cookie store. 492 // Set up cookie store.
508 if (!cookie_store.get()) { 493 if (!cookie_store.get()) {
509 DCHECK(!lazy_params_->cookie_path.empty()); 494 DCHECK(!lazy_params_->cookie_path.empty());
510 495
511 content::CookieStoreConfig cookie_config( 496 content::CookieStoreConfig cookie_config(
512 lazy_params_->cookie_path, 497 lazy_params_->cookie_path,
513 lazy_params_->session_cookie_mode, 498 lazy_params_->session_cookie_mode,
514 lazy_params_->special_storage_policy.get(), 499 lazy_params_->special_storage_policy.get(),
515 profile_params->cookie_monster_delegate.get()); 500 profile_params->cookie_monster_delegate.get());
516 cookie_config.crypto_delegate = 501 cookie_config.crypto_delegate =
517 chrome_browser_net::GetCookieCryptoDelegate(); 502 chrome_browser_net::GetCookieCryptoDelegate();
518 cookie_store = content::CreateCookieStore(cookie_config); 503 cookie_store = content::CreateCookieStore(cookie_config);
519 } 504 }
520 505
521 main_context->set_cookie_store(cookie_store.get());
522
523 // Set up server bound cert service. 506 // Set up server bound cert service.
524 if (!channel_id_service) { 507 if (!channel_id_service) {
525 DCHECK(!lazy_params_->channel_id_path.empty()); 508 DCHECK(!lazy_params_->channel_id_path.empty());
526 509
527 scoped_refptr<QuotaPolicyChannelIDStore> channel_id_db = 510 scoped_refptr<QuotaPolicyChannelIDStore> channel_id_db =
528 new QuotaPolicyChannelIDStore( 511 new QuotaPolicyChannelIDStore(
529 lazy_params_->channel_id_path, 512 lazy_params_->channel_id_path,
530 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( 513 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
531 BrowserThread::GetBlockingPool()->GetSequenceToken()), 514 BrowserThread::GetBlockingPool()->GetSequenceToken()),
532 lazy_params_->special_storage_policy.get()); 515 lazy_params_->special_storage_policy.get());
533 channel_id_service = new net::ChannelIDService( 516 channel_id_service = new net::ChannelIDService(
534 new net::DefaultChannelIDStore(channel_id_db.get()), 517 new net::DefaultChannelIDStore(channel_id_db.get()),
535 base::WorkerPool::GetTaskRunner(true)); 518 base::WorkerPool::GetTaskRunner(true));
536 } 519 }
537 520
538 set_channel_id_service(channel_id_service); 521 context_builder->SetCookieAndChannelIdStores(
539 main_context->set_channel_id_service(channel_id_service); 522 cookie_store.get(), make_scoped_ptr(channel_id_service));
540 523
541 scoped_ptr<net::HttpCache> main_cache;
542 { 524 {
543 // TODO(ttuttle): Remove ScopedTracker below once crbug.com/436671 is fixed. 525 // TODO(ttuttle): Remove ScopedTracker below once crbug.com/436671 is fixed.
544 tracked_objects::ScopedTracker tracking_profile( 526 tracked_objects::ScopedTracker tracking_profile(
545 FROM_HERE_WITH_EXPLICIT_FUNCTION("436671 HttpCache construction")); 527 FROM_HERE_WITH_EXPLICIT_FUNCTION("436671 HttpCache construction"));
546 net::HttpCache::DefaultBackend* main_backend = 528 net::HttpCache::DefaultBackend* main_backend =
547 new net::HttpCache::DefaultBackend( 529 new net::HttpCache::DefaultBackend(
548 net::DISK_CACHE, 530 net::DISK_CACHE,
549 ChooseCacheBackendType(), 531 ChooseCacheBackendType(),
550 lazy_params_->cache_path, 532 lazy_params_->cache_path,
551 lazy_params_->cache_max_size, 533 lazy_params_->cache_max_size,
552 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 534 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
553 main_cache = CreateMainHttpFactory(profile_params, main_backend); 535 context_builder->set_http_transaction_factory_factory(
536 new ProfileIOData::HttpTransactionFactoryDelegate(this, profile_params,
537 main_backend));
554 } 538 }
555 539
556 main_http_factory_.reset(main_cache.release());
557 main_context->set_http_transaction_factory(main_http_factory_.get());
558
559 #if !defined(DISABLE_FTP_SUPPORT) 540 #if !defined(DISABLE_FTP_SUPPORT)
541 // The host_resolver used here should be the same one used for the main
542 // URLResourceContext.
560 ftp_factory_.reset( 543 ftp_factory_.reset(
561 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get())); 544 new net::FtpNetworkLayer(io_thread_globals->host_resolver.get()));
562 #endif // !defined(DISABLE_FTP_SUPPORT) 545 #endif // !defined(DISABLE_FTP_SUPPORT)
563 546
547 chrome_network_delegate->set_predictor(predictor_.get());
548
564 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory( 549 scoped_ptr<net::URLRequestJobFactoryImpl> main_job_factory(
565 new net::URLRequestJobFactoryImpl()); 550 new net::URLRequestJobFactoryImpl());
566 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); 551 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers);
567 552
568 // The data reduction proxy interceptor should be as close to the network 553 // The data reduction proxy interceptor should be as close to the network
569 // as possible. 554 // as possible.
570 request_interceptors.insert( 555 request_interceptors.insert(
571 request_interceptors.begin(), 556 request_interceptors.begin(),
572 data_reduction_proxy_io_data()->CreateInterceptor().release()); 557 data_reduction_proxy_io_data()->CreateInterceptor().release());
573 main_job_factory_ = SetUpJobFactoryDefaults( 558 scoped_ptr<net::NetworkDelegate> network_delegate =
559 data_reduction_proxy_io_data()->CreateNetworkDelegate(
560 chrome_network_delegate.Pass(), true);
561
562 context_builder->set_job_factory(SetUpJobFactoryDefaults(
574 main_job_factory.Pass(), 563 main_job_factory.Pass(),
575 request_interceptors.Pass(), 564 request_interceptors.Pass(),
576 profile_params->protocol_handler_interceptor.Pass(), 565 profile_params->protocol_handler_interceptor.Pass(),
577 main_context->network_delegate(), 566 network_delegate.get(),
578 ftp_factory_.get()); 567 ftp_factory_.get()).Pass());
579 main_context->set_job_factory(main_job_factory_.get()); 568 // TODO(wjmaclean): make this Pass(), not release().
580 main_context->set_network_quality_estimator( 569 context_builder->set_network_delegate(network_delegate.release());
570 context_builder->set_network_quality_estimator_unowned(
581 io_thread_globals->network_quality_estimator.get()); 571 io_thread_globals->network_quality_estimator.get());
582 572
583 #if defined(ENABLE_EXTENSIONS) 573 #if defined(ENABLE_EXTENSIONS)
574 // This call initializes the extensions URLRequestContext *independently* of
575 // the, as-yet unbuilt, main URLRequestContext. If that ever changes, then
576 // this should not be called in this function.
584 InitializeExtensionsRequestContext(profile_params); 577 InitializeExtensionsRequestContext(profile_params);
585 #endif 578 #endif
586 579
587 // Setup SDCH for this profile. 580 // Start setup of SDCH for this profile.
588 sdch_manager_.reset(new net::SdchManager); 581 context_builder->set_sdch_manager(new net::SdchManager);
589 sdch_policy_.reset(new net::SdchOwner(sdch_manager_.get(), main_context)); 582 }
590 main_context->set_sdch_manager(sdch_manager_.get()); 583
584 void ProfileImplIOData::InitPostContextSetup(
585 ChromeNetworkDelegate* chrome_network_delegate) const {
586 net::URLRequestContext* main_context = main_request_context();
587
588 if (domain_reliability_monitor_) {
589 domain_reliability::DomainReliabilityMonitor* monitor =
590 domain_reliability_monitor_.get();
591 monitor->InitURLRequestContext(main_context);
592 monitor->AddBakedInConfigs();
593 monitor->SetDiscardUploads(!GetMetricsEnabledStateOnIOThread());
594 chrome_network_delegate->set_domain_reliability_monitor(monitor);
595 }
596
597 // Finish setup of SDCH for this profile.
598 sdch_policy_.reset(
599 new net::SdchOwner(main_context->sdch_manager(), main_context));
591 if (ShouldUseSdchPersistence()) { 600 if (ShouldUseSdchPersistence()) {
592 sdch_policy_->EnablePersistentStorage(network_json_store_.get()); 601 sdch_policy_->EnablePersistentStorage(network_json_store_.get());
593 } 602 }
594 603
595 // Create a media request context based on the main context, but using a 604 // Create a media request context based on the main context, but using a
596 // media cache. It shares the same job factory as the main context. 605 // media cache. It shares the same job factory as the main context.
597 StoragePartitionDescriptor details(profile_path_, false); 606 StoragePartitionDescriptor details(profile_path_, false);
598 media_request_context_.reset(InitializeMediaRequestContext(main_context, 607 media_request_context_.reset(InitializeMediaRequestContext(main_context,
599 details)); 608 details));
600 609
610 // lazy_params_ are last used in InitializeMediaRequestContext().
601 lazy_params_.reset(); 611 lazy_params_.reset();
602 } 612 }
603 613
604 void ProfileImplIOData:: 614 void ProfileImplIOData::
605 InitializeExtensionsRequestContext(ProfileParams* profile_params) const { 615 InitializeExtensionsRequestContext(ProfileParams* profile_params) const {
606 net::URLRequestContext* extensions_context = extensions_request_context(); 616 net::URLRequestContext* extensions_context = extensions_request_context();
607 IOThread* const io_thread = profile_params->io_thread; 617 IOThread* const io_thread = profile_params->io_thread;
608 ApplyProfileParamsToContext(extensions_context); 618 ApplyProfileParamsToContext(extensions_context);
609 619
610 extensions_context->set_transport_security_state(transport_security_state()); 620 extensions_context->set_transport_security_state(transport_security_state());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 if (partition_descriptor.in_memory) { 676 if (partition_descriptor.in_memory) {
667 app_backend = net::HttpCache::DefaultBackend::InMemory(0); 677 app_backend = net::HttpCache::DefaultBackend::InMemory(0);
668 } else { 678 } else {
669 app_backend = new net::HttpCache::DefaultBackend( 679 app_backend = new net::HttpCache::DefaultBackend(
670 net::DISK_CACHE, 680 net::DISK_CACHE,
671 ChooseCacheBackendType(), 681 ChooseCacheBackendType(),
672 cache_path, 682 cache_path,
673 app_cache_max_size_, 683 app_cache_max_size_,
674 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 684 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
675 } 685 }
686 DCHECK(main_context->storage());
676 net::HttpNetworkSession* main_network_session = 687 net::HttpNetworkSession* main_network_session =
677 main_http_factory_->GetSession(); 688 main_context->storage()->http_transaction_factory()->GetSession();
678 scoped_ptr<net::HttpCache> app_http_cache = 689 scoped_ptr<net::HttpCache> app_http_cache =
679 CreateHttpFactory(main_network_session, app_backend); 690 CreateHttpFactory(main_network_session, app_backend);
680 691
681 scoped_refptr<net::CookieStore> cookie_store = NULL; 692 scoped_refptr<net::CookieStore> cookie_store = NULL;
682 if (partition_descriptor.in_memory) { 693 if (partition_descriptor.in_memory) {
683 cookie_store = content::CreateCookieStore(content::CookieStoreConfig()); 694 cookie_store = content::CreateCookieStore(content::CookieStoreConfig());
684 } 695 }
685 696
686 // Use an app-specific cookie store. 697 // Use an app-specific cookie store.
687 if (!cookie_store.get()) { 698 if (!cookie_store.get()) {
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 } 760 }
750 761
751 // Use a separate HTTP disk cache for isolated apps. 762 // Use a separate HTTP disk cache for isolated apps.
752 net::HttpCache::BackendFactory* media_backend = 763 net::HttpCache::BackendFactory* media_backend =
753 new net::HttpCache::DefaultBackend( 764 new net::HttpCache::DefaultBackend(
754 net::MEDIA_CACHE, 765 net::MEDIA_CACHE,
755 ChooseCacheBackendType(), 766 ChooseCacheBackendType(),
756 cache_path, 767 cache_path,
757 cache_max_size, 768 cache_max_size,
758 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE)); 769 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::CACHE));
770 DCHECK(original_context->storage());
759 net::HttpNetworkSession* main_network_session = 771 net::HttpNetworkSession* main_network_session =
760 main_http_factory_->GetSession(); 772 original_context->storage()->http_transaction_factory()->GetSession();
761 scoped_ptr<net::HttpCache> media_http_cache = 773 scoped_ptr<net::HttpCache> media_http_cache =
762 CreateHttpFactory(main_network_session, media_backend); 774 CreateHttpFactory(main_network_session, media_backend);
763 775
764 // Transfer ownership of the cache to MediaRequestContext. 776 // Transfer ownership of the cache to MediaRequestContext.
765 context->SetHttpTransactionFactory(media_http_cache.Pass()); 777 context->SetHttpTransactionFactory(media_http_cache.Pass());
766 778
767 // Note that we do not create a new URLRequestJobFactory because 779 // Note that we do not create a new URLRequestJobFactory because
768 // the media context should behave exactly like its parent context 780 // the media context should behave exactly like its parent context
769 // in all respects except for cache behavior on media subresources. 781 // in all respects except for cache behavior on media subresources.
770 // The CopyFrom() step above means that our media context will use 782 // The CopyFrom() step above means that our media context will use
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 const base::Closure& completion) { 825 const base::Closure& completion) {
814 DCHECK_CURRENTLY_ON(BrowserThread::IO); 826 DCHECK_CURRENTLY_ON(BrowserThread::IO);
815 DCHECK(initialized()); 827 DCHECK(initialized());
816 828
817 DCHECK(transport_security_state()); 829 DCHECK(transport_security_state());
818 // Completes synchronously. 830 // Completes synchronously.
819 transport_security_state()->DeleteAllDynamicDataSince(time); 831 transport_security_state()->DeleteAllDynamicDataSince(time);
820 DCHECK(http_server_properties_manager_); 832 DCHECK(http_server_properties_manager_);
821 http_server_properties_manager_->Clear(completion); 833 http_server_properties_manager_->Clear(completion);
822 } 834 }
OLDNEW
« no previous file with comments | « chrome/browser/profiles/profile_impl_io_data.h ('k') | chrome/browser/profiles/profile_io_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698