electron/atom/browser/io_thread.cc
Electron Bot d008d217f9 chore: bump chromium to 2a7aff41ce73adc0eeee67d364989 (master) (#18505)
* chore: bump chromium in DEPS to 07463d3cd628b037c11f36022cb4c788db4628e3

* chore: update patches

* fix: Don't leak system network context when nw service is disabled

https://chromium-review.googlesource.com/c/chromium/src/+/1632494
NetworkService is now deleted by using SequnceLocalStorageSlot
on the IO thread when the service is disabled, which expects
all associated NetworkContexts on that sequence to be destroyed.

* chore: bump chromium in DEPS to 7c16850e7e40990e141f47101b737ec1092175a1

* fix: Destroy all network contexts before primary network context

* Simplify out-of-process service registration

https://chromium-review.googlesource.com/c/chromium/src/+/1615882

* [ThreadPool] Rename base::ThreadPool to base::ThreadPoolInstance

https://chromium-review.googlesource.com/c/chromium/src/+/1634851

* chore: update patches

* fix: -Winconsistent-missing-override warnings

* chore: bump chromium in DEPS to 93ebfaccc12715df1d5426797998eed0932f7ae1

* Change CreateBrowserMainParts to return unique_ptrs

https://chromium-review.googlesource.com/c/chromium/src/+/1632532

* chore: update patches

* chore: bump chromium in DEPS to e656555ffb87bdd05e248d0a3ef9dd9d3433e17b

* chore: bump chromium in DEPS to 111e7a8d2e3ae9d70e535009d6afb066ac906063

* chore: bump chromium in DEPS to 9b6b84670d32a7aff41ce73adc0eeee67d364989

* chore: update patches

* chore: remove ShouldInterceptResourceAsStream as it is removed upstream

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639597

* chore: remove ResourceDispatcherHostCreated as it is removed upstream

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1610892

* chore: CreateWithStrongBinding --> CreateWithSelfOwnedReceiver

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1636722

* chore: rename all blink media enums

Refs: https://chromium-review.googlesource.com/c/chromium/src/+/1639237

* chore: add accidentally removed patch content back
2019-06-03 20:44:12 -07:00

97 lines
3.4 KiB
C++

// 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"
#include <utility>
#include "atom/browser/net/url_request_context_getter.h"
#include "components/net_log/chrome_net_log.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/network_service_instance.h"
#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"
#include "net/proxy_resolution/proxy_resolution_service.h"
#include "net/url_request/url_request_context.h"
#include "services/network/network_service.h"
#include "services/network/public/cpp/features.h"
#include "services/network/url_request_context_builder_mojo.h"
using content::BrowserThread;
IOThread::IOThread(net_log::ChromeNetLog* net_log,
SystemNetworkContextManager* system_network_context_manager)
: net_log_(net_log) {
BrowserThread::SetIOThreadDelegate(this);
system_network_context_manager->SetUp(
&network_context_request_, &network_context_params_,
&http_auth_static_params_, &http_auth_dynamic_params_);
}
IOThread::~IOThread() {
BrowserThread::SetIOThreadDelegate(nullptr);
}
void IOThread::RegisterURLRequestContextGetter(
atom::URLRequestContextGetter* getter) {
base::AutoLock lock(lock_);
DCHECK(!base::FeatureList::IsEnabled(network::features::kNetworkService));
DCHECK_EQ(0u, request_context_getters_.count(getter));
request_context_getters_.insert(getter);
}
void IOThread::DeregisterURLRequestContextGetter(
atom::URLRequestContextGetter* getter) {
base::AutoLock lock(lock_);
DCHECK(!base::FeatureList::IsEnabled(network::features::kNetworkService));
DCHECK_EQ(1u, request_context_getters_.count(getter));
request_context_getters_.erase(getter);
}
void IOThread::Init() {
if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
std::unique_ptr<network::URLRequestContextBuilderMojo> builder =
std::make_unique<network::URLRequestContextBuilderMojo>();
// Enable file:// support.
builder->set_file_enabled(true);
auto cert_verifier = std::make_unique<net::CachingCertVerifier>(
std::make_unique<net::MultiThreadedCertVerifier>(
net::CertVerifyProc::CreateDefault(nullptr)));
builder->SetCertVerifier(std::move(cert_verifier));
// 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_);
}
}
void IOThread::CleanUp() {
if (!base::FeatureList::IsEnabled(network::features::kNetworkService)) {
system_request_context_->proxy_resolution_service()->OnShutdown();
base::AutoLock lock(lock_);
for (auto* getter : request_context_getters_) {
getter->NotifyContextShuttingDown();
}
system_network_context_.reset();
}
if (net_log_)
net_log_->ShutDownBeforeThreadPool();
}