2017-12-18 11:57:20 +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 "brightray/browser/io_thread.h"
|
|
|
|
|
|
|
|
#include "content/public/browser/browser_thread.h"
|
2018-07-20 15:39:15 +00:00
|
|
|
#include "net/proxy_resolution/proxy_resolution_service.h"
|
2017-12-18 11:57:20 +00:00
|
|
|
#include "net/url_request/url_request_context.h"
|
|
|
|
#include "net/url_request/url_request_context_builder.h"
|
2018-03-15 06:29:16 +00:00
|
|
|
#include "net/url_request/url_request_context_getter.h"
|
2017-12-18 11:57:20 +00:00
|
|
|
|
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
#include "net/cert_net/nss_ocsp.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
using content::BrowserThread;
|
|
|
|
|
|
|
|
namespace brightray {
|
|
|
|
|
|
|
|
IOThread::IOThread() {
|
|
|
|
BrowserThread::SetIOThreadDelegate(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
IOThread::~IOThread() {
|
|
|
|
BrowserThread::SetIOThreadDelegate(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void IOThread::Init() {
|
|
|
|
net::URLRequestContextBuilder builder;
|
2018-04-05 21:28:05 +00:00
|
|
|
builder.set_proxy_resolution_service(
|
|
|
|
net::ProxyResolutionService::CreateDirect());
|
2017-12-18 11:57:20 +00:00
|
|
|
url_request_context_ = builder.Build();
|
2018-03-15 06:29:16 +00:00
|
|
|
url_request_context_getter_ = new net::TrivialURLRequestContextGetter(
|
|
|
|
url_request_context_.get(), base::ThreadTaskRunnerHandle::Get());
|
|
|
|
url_request_context_getter_->AddRef();
|
2017-12-18 11:57:20 +00:00
|
|
|
|
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void IOThread::CleanUp() {
|
|
|
|
#if defined(USE_NSS_CERTS)
|
|
|
|
net::SetURLRequestContextForNSSHttpIO(nullptr);
|
|
|
|
#endif
|
2018-03-15 06:29:16 +00:00
|
|
|
// Explicitly release before the IO thread gets destroyed.
|
|
|
|
url_request_context_getter_->Release();
|
2017-12-18 11:57:20 +00:00
|
|
|
url_request_context_.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace brightray
|