2018-10-04 18:08:56 +00:00
|
|
|
// Copyright (c) 2017 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "atom/browser/io_thread.h"
|
2018-11-07 14:24:05 +00:00
|
|
|
|
|
|
|
#include <utility>
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
#include "components/net_log/chrome_net_log.h"
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
2018-10-05 20:34:45 +00:00
|
|
|
#include "content/public/browser/network_service_instance.h"
|
2018-11-07 14:24:05 +00:00
|
|
|
#include "net/cert/caching_cert_verifier.h"
|
|
|
|
#include "net/cert/cert_verifier.h"
|
|
|
|
#include "net/cert/cert_verify_proc.h"
|
|
|
|
#include "net/cert/multi_threaded_cert_verifier.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "net/proxy_resolution/proxy_resolution_service.h"
|
|
|
|
#include "net/url_request/url_request_context.h"
|
2018-10-05 20:34:45 +00:00
|
|
|
#include "services/network/network_service.h"
|
2018-11-07 14:24:05 +00:00
|
|
|
#include "services/network/url_request_context_builder_mojo.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
2018-11-07 14:24:05 +00:00
|
|
|
IOThread::IOThread(net_log::ChromeNetLog* net_log,
|
|
|
|
SystemNetworkContextManager* system_network_context_manager)
|
|
|
|
: net_log_(net_log) {
|
2018-10-04 18:08:56 +00:00
|
|
|
BrowserThread::SetIOThreadDelegate(this);
|
2018-11-07 14:24:05 +00:00
|
|
|
|
|
|
|
system_network_context_manager->SetUp(
|
|
|
|
&network_context_request_, &network_context_params_,
|
|
|
|
&http_auth_static_params_, &http_auth_dynamic_params_);
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
IOThread::~IOThread() {
|
|
|
|
BrowserThread::SetIOThreadDelegate(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IOThread::Init() {
|
2018-11-07 14:24:05 +00:00
|
|
|
std::unique_ptr<network::URLRequestContextBuilderMojo> builder =
|
|
|
|
std::make_unique<network::URLRequestContextBuilderMojo>();
|
2018-10-05 20:34:45 +00:00
|
|
|
|
2018-11-07 14:24:05 +00:00
|
|
|
auto cert_verifier = std::make_unique<net::CachingCertVerifier>(
|
|
|
|
std::make_unique<net::MultiThreadedCertVerifier>(
|
|
|
|
net::CertVerifyProc::CreateDefault()));
|
|
|
|
builder->SetCertVerifier(std::move(cert_verifier));
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2018-11-07 14:24:05 +00:00
|
|
|
// Create the network service, so that shared host resolver
|
|
|
|
// gets created which is required to set the auth preferences below.
|
|
|
|
network::NetworkService* network_service = content::GetNetworkServiceImpl();
|
|
|
|
network_service->SetUpHttpAuth(std::move(http_auth_static_params_));
|
|
|
|
network_service->ConfigureHttpAuthPrefs(std::move(http_auth_dynamic_params_));
|
|
|
|
|
|
|
|
system_network_context_ =
|
|
|
|
network_service
|
|
|
|
->CreateNetworkContextWithBuilder(std::move(network_context_request_),
|
|
|
|
std::move(network_context_params_),
|
|
|
|
std::move(builder),
|
|
|
|
&system_request_context_)
|
|
|
|
.release();
|
2018-10-04 18:08:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IOThread::CleanUp() {
|
2018-11-07 14:24:05 +00:00
|
|
|
system_request_context_->proxy_resolution_service()->OnShutdown();
|
2018-10-04 18:08:56 +00:00
|
|
|
|
|
|
|
if (net_log_)
|
|
|
|
net_log_->ShutDownBeforeTaskScheduler();
|
|
|
|
}
|