// Copyright 2014 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 "remoting/base/url_request_context_getter.h" #include #include "base/task/single_thread_task_runner.h" #include "build/build_config.h" #include "net/cert/cert_verifier.h" #include "net/proxy_resolution/configured_proxy_resolution_service.h" #include "net/proxy_resolution/proxy_config_service.h" #include "net/url_request/url_request_context.h" #include "net/url_request/url_request_context_builder.h" #include "remoting/base/vlog_net_log.h" #if BUILDFLAG(IS_WIN) #include "base/win/windows_version.h" #include "net/log/net_log.h" #endif // BUILDFLAG(IS_WIN) namespace remoting { URLRequestContextGetter::URLRequestContextGetter( scoped_refptr network_task_runner) : network_task_runner_(network_task_runner), proxy_config_service_( net::ProxyConfigService::CreateSystemProxyConfigService( network_task_runner)) {} net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { if (!url_request_context_.get()) { CreateVlogNetLogObserver(); net::URLRequestContextBuilder builder; builder.DisableHttpCache(); #if BUILDFLAG(IS_WIN) if (base::win::GetVersion() <= base::win::Version::WIN7) { // The network stack of Windows 7 and older systems has a bug such that // proxy resolution always fails and blocks each request for ~10-30 // seconds. We don't support proxied connection right now, so just disable // it on Windows 7 HTTP requests. auto proxy_resolution_service = net::ConfiguredProxyResolutionService::CreateWithoutProxyResolver( std::move(proxy_config_service_), net::NetLog::Get()); builder.set_proxy_resolution_service(std::move(proxy_resolution_service)); } #endif // BUILDFLAG(IS_WIN) if (proxy_config_service_) { builder.set_proxy_config_service(std::move(proxy_config_service_)); } cert_net_fetcher_ = base::MakeRefCounted(); auto cert_verifier = net::CertVerifier::CreateDefault(cert_net_fetcher_); builder.SetCertVerifier(std::move(cert_verifier)); url_request_context_ = builder.Build(); cert_net_fetcher_->SetURLRequestContext(url_request_context_.get()); } return url_request_context_.get(); } scoped_refptr URLRequestContextGetter::GetNetworkTaskRunner() const { return network_task_runner_; } URLRequestContextGetter::~URLRequestContextGetter() { if (cert_net_fetcher_) { cert_net_fetcher_->Shutdown(); } } } // namespace remoting