REVIEW: setup request context for NSS OCSP only once
This commit is contained in:
parent
e3a56240c9
commit
abe1faea5c
6 changed files with 95 additions and 11 deletions
|
@ -279,6 +279,9 @@ int BrowserMainParts::PreCreateThreads() {
|
||||||
// Initialize the app locale.
|
// Initialize the app locale.
|
||||||
BrowserClient::SetApplicationLocale(l10n_util::GetApplicationLocale(""));
|
BrowserClient::SetApplicationLocale(l10n_util::GetApplicationLocale(""));
|
||||||
|
|
||||||
|
// Manage global state of net and other IO thread related.
|
||||||
|
io_thread_ = base::MakeUnique<IOThread>();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,6 +290,8 @@ void BrowserMainParts::PostDestroyThreads() {
|
||||||
device::BluetoothAdapterFactory::Shutdown();
|
device::BluetoothAdapterFactory::Shutdown();
|
||||||
bluez::DBusBluezManagerWrapperLinux::Shutdown();
|
bluez::DBusBluezManagerWrapperLinux::Shutdown();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
io_thread_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace brightray
|
} // namespace brightray
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "base/macros.h"
|
#include "base/macros.h"
|
||||||
#include "base/path_service.h"
|
#include "base/path_service.h"
|
||||||
#include "brightray/browser/brightray_paths.h"
|
#include "brightray/browser/brightray_paths.h"
|
||||||
|
#include "brightray/browser/io_thread.h"
|
||||||
#include "content/public/browser/browser_main_parts.h"
|
#include "content/public/browser/browser_main_parts.h"
|
||||||
#include "ui/views/layout/layout_provider.h"
|
#include "ui/views/layout/layout_provider.h"
|
||||||
|
|
||||||
|
@ -50,6 +51,8 @@ class BrowserMainParts : public content::BrowserMainParts {
|
||||||
void OverrideAppLogsPath();
|
void OverrideAppLogsPath();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
std::unique_ptr<IOThread> io_thread_;
|
||||||
|
|
||||||
#if defined(TOOLKIT_VIEWS)
|
#if defined(TOOLKIT_VIEWS)
|
||||||
std::unique_ptr<ViewsDelegate> views_delegate_;
|
std::unique_ptr<ViewsDelegate> views_delegate_;
|
||||||
#endif
|
#endif
|
||||||
|
|
48
brightray/browser/io_thread.cc
Normal file
48
brightray/browser/io_thread.cc
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
// 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"
|
||||||
|
#include "net/proxy/proxy_service.h"
|
||||||
|
#include "net/url_request/url_request_context.h"
|
||||||
|
#include "net/url_request/url_request_context_builder.h"
|
||||||
|
|
||||||
|
#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;
|
||||||
|
builder.set_proxy_service(net::ProxyService::CreateDirect());
|
||||||
|
builder.DisableHttpCache();
|
||||||
|
url_request_context_ = builder.Build();
|
||||||
|
|
||||||
|
#if defined(USE_NSS_CERTS)
|
||||||
|
net::SetMessageLoopForNSSHttpIO();
|
||||||
|
net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void IOThread::CleanUp() {
|
||||||
|
#if defined(USE_NSS_CERTS)
|
||||||
|
net::ShutdownNSSHttpIO();
|
||||||
|
net::SetURLRequestContextForNSSHttpIO(nullptr);
|
||||||
|
#endif
|
||||||
|
url_request_context_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace brightray
|
37
brightray/browser/io_thread.h
Normal file
37
brightray/browser/io_thread.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
// Copyright (c) 2017 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef BRIGHTRAY_BROWSER_IO_THREAD_H_
|
||||||
|
#define BRIGHTRAY_BROWSER_IO_THREAD_H_
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "base/macros.h"
|
||||||
|
#include "content/public/browser/browser_thread_delegate.h"
|
||||||
|
|
||||||
|
namespace net {
|
||||||
|
class URLRequestContext;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace brightray {
|
||||||
|
|
||||||
|
class IOThread : public content::BrowserThreadDelegate {
|
||||||
|
public:
|
||||||
|
IOThread();
|
||||||
|
~IOThread() override;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
// BrowserThreadDelegate Implementation, runs on the IO thread.
|
||||||
|
void Init() override;
|
||||||
|
void CleanUp() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::unique_ptr<net::URLRequestContext> url_request_context_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(IOThread);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace brightray
|
||||||
|
|
||||||
|
#endif // BRIGHTRAY_BROWSER_IO_THREAD_H_
|
|
@ -56,10 +56,6 @@
|
||||||
#include "storage/browser/quota/special_storage_policy.h"
|
#include "storage/browser/quota/special_storage_policy.h"
|
||||||
#include "url/url_constants.h"
|
#include "url/url_constants.h"
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
|
||||||
#include "net/cert_net/nss_ocsp.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using content::BrowserThread;
|
using content::BrowserThread;
|
||||||
|
|
||||||
namespace brightray {
|
namespace brightray {
|
||||||
|
@ -158,9 +154,6 @@ URLRequestContextGetter::URLRequestContextGetter(
|
||||||
}
|
}
|
||||||
|
|
||||||
URLRequestContextGetter::~URLRequestContextGetter() {
|
URLRequestContextGetter::~URLRequestContextGetter() {
|
||||||
#if defined(USE_NSS_CERTS)
|
|
||||||
net::SetURLRequestContextForNSSHttpIO(NULL);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
net::HostResolver* URLRequestContextGetter::host_resolver() {
|
net::HostResolver* URLRequestContextGetter::host_resolver() {
|
||||||
|
@ -175,10 +168,6 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() {
|
||||||
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
auto& command_line = *base::CommandLine::ForCurrentProcess();
|
||||||
url_request_context_.reset(new net::URLRequestContext);
|
url_request_context_.reset(new net::URLRequestContext);
|
||||||
|
|
||||||
#if defined(USE_NSS_CERTS)
|
|
||||||
net::SetURLRequestContextForNSSHttpIO(url_request_context_.get());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// --log-net-log
|
// --log-net-log
|
||||||
if (net_log_) {
|
if (net_log_) {
|
||||||
net_log_->StartLogging();
|
net_log_->StartLogging();
|
||||||
|
|
|
@ -29,6 +29,8 @@
|
||||||
'browser/inspectable_web_contents_view.h',
|
'browser/inspectable_web_contents_view.h',
|
||||||
'browser/inspectable_web_contents_view_mac.h',
|
'browser/inspectable_web_contents_view_mac.h',
|
||||||
'browser/inspectable_web_contents_view_mac.mm',
|
'browser/inspectable_web_contents_view_mac.mm',
|
||||||
|
'browser/io_thread.cc',
|
||||||
|
'browser/io_thread.h',
|
||||||
'browser/mac/bry_inspectable_web_contents_view.h',
|
'browser/mac/bry_inspectable_web_contents_view.h',
|
||||||
'browser/mac/bry_inspectable_web_contents_view.mm',
|
'browser/mac/bry_inspectable_web_contents_view.mm',
|
||||||
'browser/mac/cocoa_notification.h',
|
'browser/mac/cocoa_notification.h',
|
||||||
|
|
Loading…
Add table
Reference in a new issue