Merge pull request #6466 from electron/cert-verifier-io-thread

Create AtomCertVerifier on IO thread
This commit is contained in:
Cheng Zhao 2016-07-13 12:22:17 +09:00 committed by GitHub
commit e96d7a5fd9
5 changed files with 16 additions and 18 deletions

View file

@ -285,6 +285,14 @@ void SetProxyInIO(net::URLRequestContextGetter* getter,
RunCallbackInUI(callback);
}
void SetCertVerifyProcInIO(
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
const AtomCertVerifier::VerifyProc& proc) {
auto request_context = context_getter->GetURLRequestContext();
static_cast<AtomCertVerifier*>(request_context->cert_verifier())->
SetVerifyProc(proc);
}
void ClearHostResolverCacheInIO(
const scoped_refptr<net::URLRequestContextGetter>& context_getter,
const base::Closure& callback) {
@ -434,7 +442,10 @@ void Session::SetCertVerifyProc(v8::Local<v8::Value> val,
return;
}
browser_context_->cert_verifier()->SetVerifyProc(proc);
BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
base::Bind(&SetCertVerifyProcInIO,
make_scoped_refptr(browser_context_->GetRequestContext()),
proc));
}
void Session::SetPermissionRequestHandler(v8::Local<v8::Value> val,

View file

@ -66,7 +66,6 @@ std::string RemoveWhitespace(const std::string& str) {
AtomBrowserContext::AtomBrowserContext(const std::string& partition,
bool in_memory)
: brightray::BrowserContext(partition, in_memory),
cert_verifier_(new AtomCertVerifier),
network_delegate_(new AtomNetworkDelegate) {
// Construct user agent string.
Browser* browser = Browser::Get();
@ -174,7 +173,7 @@ content::PermissionManager* AtomBrowserContext::GetPermissionManager() {
}
std::unique_ptr<net::CertVerifier> AtomBrowserContext::CreateCertVerifier() {
return make_scoped_ptr(cert_verifier_);
return std::unique_ptr<net::CertVerifier>(new AtomCertVerifier);
}
net::SSLConfigService* AtomBrowserContext::CreateSSLConfigService() {

View file

@ -12,7 +12,6 @@
namespace atom {
class AtomDownloadManagerDelegate;
class AtomCertVerifier;
class AtomNetworkDelegate;
class AtomPermissionManager;
class WebViewManager;
@ -42,7 +41,6 @@ class AtomBrowserContext : public brightray::BrowserContext {
// brightray::BrowserContext:
void RegisterPrefs(PrefRegistrySimple* pref_registry) override;
AtomCertVerifier* cert_verifier() const { return cert_verifier_; }
AtomNetworkDelegate* network_delegate() const { return network_delegate_; }
private:
@ -52,7 +50,6 @@ class AtomBrowserContext : public brightray::BrowserContext {
std::string user_agent_;
// Managed by brightray::BrowserContext.
AtomCertVerifier* cert_verifier_;
AtomNetworkDelegate* network_delegate_;
DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);

View file

@ -36,7 +36,6 @@ AtomCertVerifier::~AtomCertVerifier() {
}
void AtomCertVerifier::SetVerifyProc(const VerifyProc& proc) {
base::AutoLock auto_lock(lock_);
verify_proc_ = proc;
}
@ -52,20 +51,14 @@ int AtomCertVerifier::Verify(
const net::BoundNetLog& net_log) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
VerifyProc proc;
{
base::AutoLock auto_lock(lock_);
proc = verify_proc_;
}
if (proc.is_null())
if (verify_proc_.is_null())
return default_cert_verifier_->Verify(
cert, hostname, ocsp_response, flags, crl_set, verify_result, callback,
out_req, net_log);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(proc, hostname, make_scoped_refptr(cert),
base::Bind(verify_proc_, hostname, make_scoped_refptr(cert),
base::Bind(OnResult, verify_result, callback)));
return net::ERR_IO_PENDING;
}

View file

@ -5,10 +5,9 @@
#ifndef ATOM_BROWSER_NET_ATOM_CERT_VERIFIER_H_
#define ATOM_BROWSER_NET_ATOM_CERT_VERIFIER_H_
#include <memory>
#include <string>
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "net/cert/cert_verifier.h"
namespace atom {
@ -39,7 +38,6 @@ class AtomCertVerifier : public net::CertVerifier {
bool SupportsOCSPStapling() override;
private:
base::Lock lock_;
VerifyProc verify_proc_;
std::unique_ptr<net::CertVerifier> default_cert_verifier_;