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

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

Issue 2978443002: Make ProfileIOData use URLRequestContextBuilder (Closed)
Patch Set: ? Created 3 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 <memory> 7 #include <memory>
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "extensions/features/features.h" 61 #include "extensions/features/features.h"
62 #include "net/base/cache_type.h" 62 #include "net/base/cache_type.h"
63 #include "net/cookies/cookie_store.h" 63 #include "net/cookies/cookie_store.h"
64 #include "net/http/http_cache.h" 64 #include "net/http/http_cache.h"
65 #include "net/http/http_network_session.h" 65 #include "net/http/http_network_session.h"
66 #include "net/http/http_server_properties_manager.h" 66 #include "net/http/http_server_properties_manager.h"
67 #include "net/reporting/reporting_feature.h" 67 #include "net/reporting/reporting_feature.h"
68 #include "net/reporting/reporting_policy.h" 68 #include "net/reporting/reporting_policy.h"
69 #include "net/reporting/reporting_service.h" 69 #include "net/reporting/reporting_service.h"
70 #include "net/ssl/channel_id_service.h" 70 #include "net/ssl/channel_id_service.h"
71 #include "net/url_request/url_request_context_storage.h" 71 #include "net/url_request/url_request_context_builder.h"
72 #include "net/url_request/url_request_intercepting_job_factory.h" 72 #include "net/url_request/url_request_intercepting_job_factory.h"
73 #include "net/url_request/url_request_job_factory_impl.h" 73 #include "net/url_request/url_request_job_factory_impl.h"
74 #include "storage/browser/quota/special_storage_policy.h" 74 #include "storage/browser/quota/special_storage_policy.h"
75 75
76 #if defined(OS_ANDROID) 76 #if defined(OS_ANDROID)
77 #include "chrome/browser/android/offline_pages/offline_page_request_interceptor. h" 77 #include "chrome/browser/android/offline_pages/offline_page_request_interceptor. h"
78 #endif // defined(OS_ANDROID) 78 #endif // defined(OS_ANDROID)
79 79
80 namespace { 80 namespace {
81 81
82 net::BackendType ChooseCacheBackendType() { 82 // Returns the URLRequestContextBuilder::HttpCacheParams::Type that the disk
83 // cache should use.
84 net::URLRequestContextBuilder::HttpCacheParams::Type ChooseCacheType() {
83 #if !defined(OS_ANDROID) 85 #if !defined(OS_ANDROID)
84 const base::CommandLine& command_line = 86 const base::CommandLine& command_line =
85 *base::CommandLine::ForCurrentProcess(); 87 *base::CommandLine::ForCurrentProcess();
86 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) { 88 if (command_line.HasSwitch(switches::kUseSimpleCacheBackend)) {
87 const std::string opt_value = 89 const std::string opt_value =
88 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend); 90 command_line.GetSwitchValueASCII(switches::kUseSimpleCacheBackend);
89 if (base::LowerCaseEqualsASCII(opt_value, "off")) 91 if (base::LowerCaseEqualsASCII(opt_value, "off"))
90 return net::CACHE_BACKEND_BLOCKFILE; 92 return net::URLRequestContextBuilder::HttpCacheParams::DISK_BLOCKFILE;
91 if (opt_value.empty() || base::LowerCaseEqualsASCII(opt_value, "on")) 93 if (opt_value.empty() || base::LowerCaseEqualsASCII(opt_value, "on"))
92 return net::CACHE_BACKEND_SIMPLE; 94 return net::URLRequestContextBuilder::HttpCacheParams::DISK_SIMPLE;
93 } 95 }
94 const std::string experiment_name = 96 const std::string experiment_name =
95 base::FieldTrialList::FindFullName("SimpleCacheTrial"); 97 base::FieldTrialList::FindFullName("SimpleCacheTrial");
96 if (base::StartsWith(experiment_name, "Disable", 98 if (base::StartsWith(experiment_name, "Disable",
97 base::CompareCase::INSENSITIVE_ASCII)) { 99 base::CompareCase::INSENSITIVE_ASCII)) {
98 return net::CACHE_BACKEND_BLOCKFILE; 100 return net::URLRequestContextBuilder::HttpCacheParams::DISK_BLOCKFILE;
99 } 101 }
100 if (base::StartsWith(experiment_name, "ExperimentYes", 102 if (base::StartsWith(experiment_name, "ExperimentYes",
101 base::CompareCase::INSENSITIVE_ASCII)) { 103 base::CompareCase::INSENSITIVE_ASCII)) {
102 return net::CACHE_BACKEND_SIMPLE; 104 return net::URLRequestContextBuilder::HttpCacheParams::DISK_SIMPLE;
103 } 105 }
104 #endif // #if !defined(OS_ANDROID) 106 #endif // #if !defined(OS_ANDROID)
105 107
106 #if defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_CHROMEOS) 108 #if defined(OS_ANDROID) || defined(OS_LINUX) || defined(OS_CHROMEOS)
107 return net::CACHE_BACKEND_SIMPLE; 109 return net::URLRequestContextBuilder::HttpCacheParams::DISK_SIMPLE;
108 #else 110 #else
109 return net::CACHE_BACKEND_BLOCKFILE; 111 return net::URLRequestContextBuilder::HttpCacheParams::DISK_BLOCKFILE;
110 #endif 112 #endif
111 } 113 }
112 114
115 // Returns the BackendType that the disk cache should use.
116 // TODO(mmenke): Once all URLRequestContexts are set up using
117 // URLRequestContextBuilders, and the media URLRequestContext is take care of
118 // (In one way or another), this should be removed.
119 net::BackendType ChooseCacheBackendType() {
120 switch (ChooseCacheType()) {
121 case net::URLRequestContextBuilder::HttpCacheParams::DISK_BLOCKFILE:
122 return net::CACHE_BACKEND_BLOCKFILE;
123 case net::URLRequestContextBuilder::HttpCacheParams::DISK_SIMPLE:
124 return net::CACHE_BACKEND_SIMPLE;
125 case net::URLRequestContextBuilder::HttpCacheParams::DISK:
126 return net::CACHE_BACKEND_DEFAULT;
127 case net::URLRequestContextBuilder::HttpCacheParams::IN_MEMORY:
128 NOTREACHED();
129 break;
130 }
131 return net::CACHE_BACKEND_DEFAULT;
132 }
133
113 } // namespace 134 } // namespace
114 135
115 using content::BrowserThread; 136 using content::BrowserThread;
116 137
117 ProfileImplIOData::Handle::Handle(Profile* profile) 138 ProfileImplIOData::Handle::Handle(Profile* profile)
118 : io_data_(new ProfileImplIOData), 139 : io_data_(new ProfileImplIOData),
119 profile_(profile), 140 profile_(profile),
120 initialized_(false) { 141 initialized_(false) {
121 DCHECK_CURRENTLY_ON(BrowserThread::UI); 142 DCHECK_CURRENTLY_ON(BrowserThread::UI);
122 DCHECK(profile); 143 DCHECK(profile);
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 } 473 }
453 474
454 return data_reduction_proxy_io_data()->CreateNetworkDelegate( 475 return data_reduction_proxy_io_data()->CreateNetworkDelegate(
455 io_thread->globals()->data_use_ascriber->CreateNetworkDelegate( 476 io_thread->globals()->data_use_ascriber->CreateNetworkDelegate(
456 std::move(chrome_network_delegate), 477 std::move(chrome_network_delegate),
457 io_thread->GetMetricsDataUseForwarder()), 478 io_thread->GetMetricsDataUseForwarder()),
458 true); 479 true);
459 } 480 }
460 481
461 void ProfileImplIOData::InitializeInternal( 482 void ProfileImplIOData::InitializeInternal(
483 net::URLRequestContextBuilder* builder,
462 ProfileParams* profile_params, 484 ProfileParams* profile_params,
463 content::ProtocolHandlerMap* protocol_handlers, 485 content::ProtocolHandlerMap* protocol_handlers,
464 content::URLRequestInterceptorScopedVector request_interceptors) const { 486 content::URLRequestInterceptorScopedVector request_interceptors) const {
465 net::URLRequestContext* main_context = main_request_context();
466 net::URLRequestContextStorage* main_context_storage =
467 main_request_context_storage();
468
469 IOThread* const io_thread = profile_params->io_thread; 487 IOThread* const io_thread = profile_params->io_thread;
470 IOThread::Globals* const io_thread_globals = io_thread->globals(); 488 IOThread::Globals* const io_thread_globals = io_thread->globals();
471 489
472 if (lazy_params_->http_server_properties_manager) { 490 if (lazy_params_->http_server_properties_manager) {
473 lazy_params_->http_server_properties_manager->InitializeOnNetworkSequence(); 491 lazy_params_->http_server_properties_manager->InitializeOnNetworkSequence();
474 main_context_storage->set_http_server_properties( 492 builder->SetHttpServerProperties(
475 std::move(lazy_params_->http_server_properties_manager)); 493 std::move(lazy_params_->http_server_properties_manager));
476 } 494 }
477 495
478 main_context->set_network_quality_estimator( 496 builder->set_network_quality_estimator(
479 io_thread_globals->network_quality_estimator.get()); 497 io_thread_globals->network_quality_estimator.get());
480 498
481 // Create a single task runner to use with the CookieStore and ChannelIDStore. 499 // Create a single task runner to use with the CookieStore and ChannelIDStore.
482 scoped_refptr<base::SequencedTaskRunner> cookie_background_task_runner = 500 scoped_refptr<base::SequencedTaskRunner> cookie_background_task_runner =
483 base::CreateSequencedTaskRunnerWithTraits( 501 base::CreateSequencedTaskRunnerWithTraits(
484 {base::MayBlock(), base::TaskPriority::BACKGROUND, 502 {base::MayBlock(), base::TaskPriority::BACKGROUND,
485 base::TaskShutdownBehavior::BLOCK_SHUTDOWN}); 503 base::TaskShutdownBehavior::BLOCK_SHUTDOWN});
486 504
487 // Set up server bound cert service. 505 // Set up server bound cert service.
488 DCHECK(!lazy_params_->channel_id_path.empty()); 506 DCHECK(!lazy_params_->channel_id_path.empty());
489 scoped_refptr<QuotaPolicyChannelIDStore> channel_id_db = 507 scoped_refptr<QuotaPolicyChannelIDStore> channel_id_db =
490 new QuotaPolicyChannelIDStore(lazy_params_->channel_id_path, 508 new QuotaPolicyChannelIDStore(lazy_params_->channel_id_path,
491 cookie_background_task_runner, 509 cookie_background_task_runner,
492 lazy_params_->special_storage_policy.get()); 510 lazy_params_->special_storage_policy.get());
493 main_context_storage->set_channel_id_service( 511 std::unique_ptr<net::ChannelIDService> channel_id_service(
494 base::MakeUnique<net::ChannelIDService>( 512 base::MakeUnique<net::ChannelIDService>(
495 new net::DefaultChannelIDStore(channel_id_db.get()))); 513 new net::DefaultChannelIDStore(channel_id_db.get())));
496 514
497 // Set up cookie store. 515 // Set up cookie store.
498 DCHECK(!lazy_params_->cookie_path.empty()); 516 DCHECK(!lazy_params_->cookie_path.empty());
499 517
500 content::CookieStoreConfig cookie_config( 518 content::CookieStoreConfig cookie_config(
501 lazy_params_->cookie_path, lazy_params_->session_cookie_mode, 519 lazy_params_->cookie_path, lazy_params_->session_cookie_mode,
502 lazy_params_->special_storage_policy.get(), 520 lazy_params_->special_storage_policy.get(),
503 profile_params->cookie_monster_delegate.get()); 521 profile_params->cookie_monster_delegate.get());
504 cookie_config.crypto_delegate = cookie_config::GetCookieCryptoDelegate(); 522 cookie_config.crypto_delegate = cookie_config::GetCookieCryptoDelegate();
505 cookie_config.channel_id_service = main_context->channel_id_service(); 523 cookie_config.channel_id_service = channel_id_service.get();
506 cookie_config.background_task_runner = cookie_background_task_runner; 524 cookie_config.background_task_runner = cookie_background_task_runner;
507 main_context_storage->set_cookie_store( 525 std::unique_ptr<net::CookieStore> cookie_store(
508 content::CreateCookieStore(cookie_config)); 526 content::CreateCookieStore(cookie_config));
509 527
510 main_context->cookie_store()->SetChannelIDServiceID( 528 cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
511 main_context->channel_id_service()->GetUniqueID());
512 529
513 std::unique_ptr<net::HttpCache::BackendFactory> main_backend( 530 builder->SetCookieAndChannelIdStores(std::move(cookie_store),
514 new net::HttpCache::DefaultBackend( 531 std::move(channel_id_service));
515 net::DISK_CACHE, ChooseCacheBackendType(), lazy_params_->cache_path,
516 lazy_params_->cache_max_size,
517 BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE)));
518 main_context_storage->set_http_network_session(
519 CreateHttpNetworkSession(*profile_params));
520 main_context_storage->set_http_transaction_factory(CreateMainHttpFactory(
521 main_context_storage->http_network_session(), std::move(main_backend)));
522 532
523 std::unique_ptr<net::URLRequestJobFactoryImpl> main_job_factory( 533 net::URLRequestContextBuilder::HttpCacheParams cache_params;
524 new net::URLRequestJobFactoryImpl()); 534 cache_params.type = ChooseCacheType();
525 InstallProtocolHandlers(main_job_factory.get(), protocol_handlers); 535 cache_params.path = lazy_params_->cache_path;
536 cache_params.max_size = lazy_params_->cache_max_size;
537 builder->EnableHttpCache(cache_params);
538 builder->SetCacheThreadTaskRunner(
539 BrowserThread::GetTaskRunnerForThread(BrowserThread::CACHE));
540
541 AddProtocolHandlersToBuilder(builder, protocol_handlers);
526 542
527 // Install the Offline Page Interceptor. 543 // Install the Offline Page Interceptor.
528 #if defined(OS_ANDROID) 544 #if defined(OS_ANDROID)
529 request_interceptors.push_back( 545 request_interceptors.push_back(
530 base::MakeUnique<offline_pages::OfflinePageRequestInterceptor>( 546 base::MakeUnique<offline_pages::OfflinePageRequestInterceptor>(
531 previews_io_data())); 547 previews_io_data()));
532 #endif 548 #endif
533 549
534 // The data reduction proxy interceptor should be as close to the network 550 // The data reduction proxy interceptor should be as close to the network
535 // as possible. 551 // as possible.
536 request_interceptors.insert( 552 request_interceptors.insert(
537 request_interceptors.begin(), 553 request_interceptors.begin(),
538 data_reduction_proxy_io_data()->CreateInterceptor()); 554 data_reduction_proxy_io_data()->CreateInterceptor());
539 data_reduction_proxy_io_data()->SetDataUseAscriber( 555 data_reduction_proxy_io_data()->SetDataUseAscriber(
540 io_thread_globals->data_use_ascriber.get()); 556 io_thread_globals->data_use_ascriber.get());
541 main_context_storage->set_job_factory(SetUpJobFactoryDefaults( 557 SetUpJobFactoryDefaultsForBuilder(
542 std::move(main_job_factory), std::move(request_interceptors), 558 builder, std::move(request_interceptors),
543 std::move(profile_params->protocol_handler_interceptor), 559 std::move(profile_params->protocol_handler_interceptor),
544 main_context->network_delegate(), 560 io_thread_globals->system_request_context->host_resolver());
545 io_thread_globals->system_request_context->host_resolver())); 561
562 builder->set_reporting_policy(MaybeCreateReportingPolicy());
563 }
564
565 void ProfileImplIOData::OnMainRequestContextCreated(
566 ProfileParams* profile_params) const {
567 DCHECK(lazy_params_);
546 568
547 #if BUILDFLAG(ENABLE_EXTENSIONS) 569 #if BUILDFLAG(ENABLE_EXTENSIONS)
548 InitializeExtensionsRequestContext(profile_params); 570 InitializeExtensionsRequestContext(profile_params);
549 #endif 571 #endif
550 572
551 main_context_storage->set_reporting_service(
552 MaybeCreateReportingService(main_context));
553
554 // Create a media request context based on the main context, but using a 573 // Create a media request context based on the main context, but using a
555 // media cache. It shares the same job factory as the main context. 574 // media cache. It shares the same job factory as the main context.
556 StoragePartitionDescriptor details(profile_path_, false); 575 StoragePartitionDescriptor details(profile_path_, false);
557 media_request_context_.reset( 576 media_request_context_.reset(InitializeMediaRequestContext(
558 InitializeMediaRequestContext(main_context, details, "main_media")); 577 main_request_context(), details, "main_media"));
559 lazy_params_.reset(); 578 lazy_params_.reset();
560 } 579 }
561 580
562 void ProfileImplIOData:: 581 void ProfileImplIOData::
563 InitializeExtensionsRequestContext(ProfileParams* profile_params) const { 582 InitializeExtensionsRequestContext(ProfileParams* profile_params) const {
564 // The extensions context only serves to hold onto the extensions cookie 583 // The extensions context only serves to hold onto the extensions cookie
565 // store. 584 // store.
566 net::URLRequestContext* extensions_context = extensions_request_context(); 585 net::URLRequestContext* extensions_context = extensions_request_context();
567 586
568 content::CookieStoreConfig cookie_config( 587 content::CookieStoreConfig cookie_config(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 cookie_config.channel_id_service = channel_id_service.get(); 655 cookie_config.channel_id_service = channel_id_service.get();
637 cookie_config.background_task_runner = cookie_background_task_runner; 656 cookie_config.background_task_runner = cookie_background_task_runner;
638 cookie_store = content::CreateCookieStore(cookie_config); 657 cookie_store = content::CreateCookieStore(cookie_config);
639 cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID()); 658 cookie_store->SetChannelIDServiceID(channel_id_service->GetUniqueID());
640 659
641 // Build a new HttpNetworkSession that uses the new ChannelIDService. 660 // Build a new HttpNetworkSession that uses the new ChannelIDService.
642 // TODO(mmenke): It's weird to combine state from 661 // TODO(mmenke): It's weird to combine state from
643 // main_request_context_storage() objects and the argumet to this method, 662 // main_request_context_storage() objects and the argumet to this method,
644 // |main_context|. Remove |main_context| as an argument, and just use 663 // |main_context|. Remove |main_context| as an argument, and just use
645 // main_context() instead. 664 // main_context() instead.
646 net::HttpNetworkSession::Context session_context = 665 net::HttpNetworkSession* network_session =
647 main_request_context_storage()->http_network_session()->context(); 666 main_context->http_transaction_factory()->GetSession();
667 net::HttpNetworkSession::Context session_context = network_session->context();
648 session_context.channel_id_service = channel_id_service.get(); 668 session_context.channel_id_service = channel_id_service.get();
649 std::unique_ptr<net::HttpNetworkSession> http_network_session( 669 std::unique_ptr<net::HttpNetworkSession> http_network_session(
650 new net::HttpNetworkSession( 670 new net::HttpNetworkSession(network_session->params(), session_context));
651 main_request_context_storage()->http_network_session()->params(),
652 session_context));
653 std::unique_ptr<net::HttpCache> app_http_cache = 671 std::unique_ptr<net::HttpCache> app_http_cache =
654 CreateMainHttpFactory(http_network_session.get(), std::move(app_backend)); 672 CreateMainHttpFactory(http_network_session.get(), std::move(app_backend));
655 673
656 // Transfer ownership of the ChannelIDStore and the HttpNetworkSession to the 674 // Transfer ownership of the ChannelIDStore and the HttpNetworkSession to the
657 // AppRequestContext. 675 // AppRequestContext.
658 context->SetChannelIDService(std::move(channel_id_service)); 676 context->SetChannelIDService(std::move(channel_id_service));
659 context->SetHttpNetworkSession(std::move(http_network_session)); 677 context->SetHttpNetworkSession(std::move(http_network_session));
660 678
661 // Transfer ownership of the cookies and cache to AppRequestContext. 679 // Transfer ownership of the cookies and cache to AppRequestContext.
662 context->SetCookieStore(std::move(cookie_store)); 680 context->SetCookieStore(std::move(cookie_store));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 return media_request_context; 782 return media_request_context;
765 } 783 }
766 784
767 chrome_browser_net::Predictor* ProfileImplIOData::GetPredictor() { 785 chrome_browser_net::Predictor* ProfileImplIOData::GetPredictor() {
768 return predictor_.get(); 786 return predictor_.get();
769 } 787 }
770 788
771 std::unique_ptr<net::ReportingService> 789 std::unique_ptr<net::ReportingService>
772 ProfileImplIOData::MaybeCreateReportingService( 790 ProfileImplIOData::MaybeCreateReportingService(
773 net::URLRequestContext* url_request_context) const { 791 net::URLRequestContext* url_request_context) const {
774 if (!base::FeatureList::IsEnabled(features::kReporting)) 792 std::unique_ptr<net::ReportingPolicy> reporting_policy(
793 MaybeCreateReportingPolicy());
794 if (!reporting_policy)
775 return std::unique_ptr<net::ReportingService>(); 795 return std::unique_ptr<net::ReportingService>();
776 796
777 return net::ReportingService::Create(net::ReportingPolicy(), 797 return net::ReportingService::Create(*reporting_policy, url_request_context);
778 url_request_context); 798 }
799
800 std::unique_ptr<net::ReportingPolicy>
801 ProfileImplIOData::MaybeCreateReportingPolicy() {
802 if (!base::FeatureList::IsEnabled(features::kReporting))
803 return std::unique_ptr<net::ReportingPolicy>();
804
805 return base::MakeUnique<net::ReportingPolicy>();
779 } 806 }
780 807
781 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread( 808 void ProfileImplIOData::ClearNetworkingHistorySinceOnIOThread(
782 base::Time time, 809 base::Time time,
783 const base::Closure& completion) { 810 const base::Closure& completion) {
784 DCHECK_CURRENTLY_ON(BrowserThread::IO); 811 DCHECK_CURRENTLY_ON(BrowserThread::IO);
785 DCHECK(initialized()); 812 DCHECK(initialized());
786 813
787 // Completes synchronously. 814 // Completes synchronously.
788 main_request_context()->transport_security_state()->DeleteAllDynamicDataSince( 815 main_request_context()->transport_security_state()->DeleteAllDynamicDataSince(
789 time); 816 time);
790 DCHECK(http_server_properties_manager_); 817 DCHECK(http_server_properties_manager_);
791 http_server_properties_manager_->Clear(completion); 818 http_server_properties_manager_->Clear(completion);
792 } 819 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698