Commit f34bba7c authored by Matt Menke's avatar Matt Menke Committed by Commit Bot

Simplify in-process URLRequestContext creation with the NetworkService.

The old code hooked up things to the URLRequestContext that hadn't been
ported over to work with the NetworkService yet, when the NetworkService
was enabled. This CL just does the minimum setup that's needed to not
crash. It also makes requests made with the in-process URLRequestContext
fail when the network service is enabled. These changes will help
identify code that still depends on the legacy path, and allow for some
cleanup of URLRequestContextBuilderMojo and NetworkContext.

Cq-Include-Trybots: luci.chromium.try:linux_mojo
Change-Id: I4c3f40e6dc3c235844846bff7d1d43d0b1c986d0
Bug: 825242
Reviewed-on: https://chromium-review.googlesource.com/1096075
Commit-Queue: Matt Menke <mmenke@chromium.org>
Reviewed-by: default avatarJohn Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567879}
parent 07303144
...@@ -784,6 +784,8 @@ jumbo_split_static_library("browser") { ...@@ -784,6 +784,8 @@ jumbo_split_static_library("browser") {
"net/dns_probe_runner.h", "net/dns_probe_runner.h",
"net/dns_probe_service.cc", "net/dns_probe_service.cc",
"net/dns_probe_service.h", "net/dns_probe_service.h",
"net/failing_url_request_interceptor.cc",
"net/failing_url_request_interceptor.h",
"net/file_downloader.cc", "net/file_downloader.cc",
"net/file_downloader.h", "net/file_downloader.h",
"net/net_error_diagnostics_dialog.h", "net/net_error_diagnostics_dialog.h",
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h" #include "chrome/browser/data_use_measurement/chrome_data_use_ascriber.h"
#include "chrome/browser/net/chrome_network_delegate.h" #include "chrome/browser/net/chrome_network_delegate.h"
#include "chrome/browser/net/dns_probe_service.h" #include "chrome/browser/net/dns_probe_service.h"
#include "chrome/browser/net/failing_url_request_interceptor.h"
#include "chrome/browser/net/proxy_service_factory.h" #include "chrome/browser/net/proxy_service_factory.h"
#include "chrome/common/chrome_content_client.h" #include "chrome/common/chrome_content_client.h"
#include "chrome/common/chrome_features.h" #include "chrome/common/chrome_features.h"
...@@ -457,10 +458,33 @@ void IOThread::SetUpProxyService( ...@@ -457,10 +458,33 @@ void IOThread::SetUpProxyService(
} }
void IOThread::ConstructSystemRequestContext() { void IOThread::ConstructSystemRequestContext() {
std::unique_ptr<network::URLRequestContextBuilderMojo> builder = if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
std::make_unique<network::URLRequestContextBuilderMojo>(); globals_->deprecated_network_quality_estimator =
std::make_unique<net::NetworkQualityEstimator>(
std::make_unique<net::NetworkQualityEstimatorParams>(
std::map<std::string, std::string>()),
net_log_);
net::URLRequestContextBuilder builder;
std::vector<std::unique_ptr<net::URLRequestInterceptor>>
url_request_interceptors;
url_request_interceptors.emplace_back(
std::make_unique<FailingURLRequestInterceptor>());
builder.SetInterceptors(std::move(url_request_interceptors));
builder.set_network_quality_estimator(
globals_->deprecated_network_quality_estimator.get());
builder.SetCertVerifier(
std::make_unique<WrappedCertVerifierForIOThreadTesting>());
builder.set_proxy_resolution_service(
net::ProxyResolutionService::CreateDirect());
globals_->system_request_context_owner =
network::URLRequestContextOwner(nullptr, builder.Build());
globals_->system_request_context =
globals_->system_request_context_owner.url_request_context.get();
network_context_params_.reset();
} else {
std::unique_ptr<network::URLRequestContextBuilderMojo> builder =
std::make_unique<network::URLRequestContextBuilderMojo>();
if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
auto chrome_network_delegate = std::make_unique<ChromeNetworkDelegate>( auto chrome_network_delegate = std::make_unique<ChromeNetworkDelegate>(
extension_event_router_forwarder(), &system_enable_referrers_); extension_event_router_forwarder(), &system_enable_referrers_);
// By default, data usage is considered off the record. // By default, data usage is considered off the record.
...@@ -470,56 +494,39 @@ void IOThread::ConstructSystemRequestContext() { ...@@ -470,56 +494,39 @@ void IOThread::ConstructSystemRequestContext() {
builder->set_network_delegate( builder->set_network_delegate(
globals_->data_use_ascriber->CreateNetworkDelegate( globals_->data_use_ascriber->CreateNetworkDelegate(
std::move(chrome_network_delegate), GetMetricsDataUseForwarder())); std::move(chrome_network_delegate), GetMetricsDataUseForwarder()));
}
std::unique_ptr<net::HostResolver> host_resolver(
CreateGlobalHostResolver(net_log_));
std::unique_ptr<net::CertVerifier> cert_verifier; std::unique_ptr<net::CertVerifier> cert_verifier;
if (g_cert_verifier_for_io_thread_testing) { if (g_cert_verifier_for_io_thread_testing) {
cert_verifier = std::make_unique<WrappedCertVerifierForIOThreadTesting>(); cert_verifier = std::make_unique<WrappedCertVerifierForIOThreadTesting>();
} else { } else {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
// Creates a CertVerifyProc that doesn't allow any profile-provided certs. // Creates a CertVerifyProc that doesn't allow any profile-provided certs.
cert_verifier = std::make_unique<net::CachingCertVerifier>( cert_verifier = std::make_unique<net::CachingCertVerifier>(
std::make_unique<net::MultiThreadedCertVerifier>( std::make_unique<net::MultiThreadedCertVerifier>(
base::MakeRefCounted<chromeos::CertVerifyProcChromeOS>())); base::MakeRefCounted<chromeos::CertVerifyProcChromeOS>()));
#else #else
cert_verifier = std::make_unique<net::CachingCertVerifier>( cert_verifier = std::make_unique<net::CachingCertVerifier>(
std::make_unique<net::MultiThreadedCertVerifier>( std::make_unique<net::MultiThreadedCertVerifier>(
net::CertVerifyProc::CreateDefault())); net::CertVerifyProc::CreateDefault()));
#endif #endif
} }
const base::CommandLine& command_line = const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess(); *base::CommandLine::ForCurrentProcess();
builder->SetCertVerifier( builder->SetCertVerifier(
network::IgnoreErrorsCertVerifier::MaybeWrapCertVerifier( network::IgnoreErrorsCertVerifier::MaybeWrapCertVerifier(
command_line, switches::kUserDataDir, std::move(cert_verifier))); command_line, switches::kUserDataDir, std::move(cert_verifier)));
UMA_HISTOGRAM_BOOLEAN( UMA_HISTOGRAM_BOOLEAN(
"Net.Certificate.IgnoreCertificateErrorsSPKIListPresent", "Net.Certificate.IgnoreCertificateErrorsSPKIListPresent",
command_line.HasSwitch( command_line.HasSwitch(
network::switches::kIgnoreCertificateErrorsSPKIList)); network::switches::kIgnoreCertificateErrorsSPKIList));
SetUpProxyService(builder.get()); SetUpProxyService(builder.get());
if (!is_quic_allowed_on_init_)
globals_->quic_disabled = true;
if (!is_quic_allowed_on_init_)
globals_->quic_disabled = true;
if (base::FeatureList::IsEnabled(network::features::kNetworkService)) {
globals_->deprecated_network_quality_estimator =
std::make_unique<net::NetworkQualityEstimator>(
std::make_unique<net::NetworkQualityEstimatorParams>(
std::map<std::string, std::string>()),
net_log_);
globals_->deprecated_host_resolver = std::move(host_resolver);
globals_->system_request_context_owner = std::move(builder)->Create(
std::move(network_context_params_).get(), !is_quic_allowed_on_init_,
net_log_, globals_->deprecated_host_resolver.get(),
globals_->deprecated_network_quality_estimator.get());
globals_->system_request_context =
globals_->system_request_context_owner.url_request_context.get();
} else {
network::NetworkService* network_service = content::GetNetworkServiceImpl(); network::NetworkService* network_service = content::GetNetworkServiceImpl();
network_service->SetHostResolver(std::move(host_resolver)); network_service->SetHostResolver(CreateGlobalHostResolver(net_log_));
// These must be done after the SetHostResolver call. // These must be done after the SetHostResolver call.
network_service->SetUpHttpAuth(std::move(http_auth_static_params_)); network_service->SetUpHttpAuth(std::move(http_auth_static_params_));
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/net/failing_url_request_interceptor.h"
#include "net/base/net_errors.h"
#include "net/url_request/url_request_error_job.h"
FailingURLRequestInterceptor::FailingURLRequestInterceptor() {}
FailingURLRequestInterceptor::~FailingURLRequestInterceptor() {}
net::URLRequestJob* FailingURLRequestInterceptor::MaybeInterceptRequest(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const {
return new net::URLRequestErrorJob(request, network_delegate,
net::ERR_NOT_IMPLEMENTED);
}
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_NET_FAILING_URL_REQUEST_INTERCEPTOR_H_
#define CHROME_BROWSER_NET_FAILING_URL_REQUEST_INTERCEPTOR_H_
#include "net/url_request/url_request_interceptor.h"
// A URLRequestInterceptor that fails all network requests.
class FailingURLRequestInterceptor : public net::URLRequestInterceptor {
public:
FailingURLRequestInterceptor();
~FailingURLRequestInterceptor() override;
net::URLRequestJob* MaybeInterceptRequest(
net::URLRequest* request,
net::NetworkDelegate* network_delegate) const override;
private:
DISALLOW_COPY_AND_ASSIGN(FailingURLRequestInterceptor);
};
#endif // CHROME_BROWSER_NET_FAILING_URL_REQUEST_INTERCEPTOR_H_
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment