This source file includes following definitions.
- OnCertAdded
- OnCACertChanged
- CreateDatagramClientSocket
- CreateTransportClientSocket
- CreateSSLClientSocket
- ClearSSLSessionCache
- GetDefaultFactory
#include "net/socket/client_socket_factory.h"
#include "base/lazy_instance.h"
#include "base/thread_task_runner_handle.h"
#include "base/threading/sequenced_worker_pool.h"
#include "build/build_config.h"
#include "net/cert/cert_database.h"
#include "net/socket/client_socket_handle.h"
#if defined(USE_OPENSSL)
#include "net/socket/ssl_client_socket_openssl.h"
#elif defined(USE_NSS) || defined(OS_MACOSX) || defined(OS_WIN)
#include "net/socket/ssl_client_socket_nss.h"
#endif
#include "net/socket/tcp_client_socket.h"
#include "net/udp/udp_client_socket.h"
namespace net {
class X509Certificate;
namespace {
#if defined(OS_CHROMEOS) || defined(OS_LINUX)
bool g_use_dedicated_nss_thread = true;
#else
bool g_use_dedicated_nss_thread = false;
#endif
class DefaultClientSocketFactory : public ClientSocketFactory,
public CertDatabase::Observer {
public:
DefaultClientSocketFactory() {
if (g_use_dedicated_nss_thread) {
worker_pool_ = new base::SequencedWorkerPool(1, "NSS SSL Thread");
nss_thread_task_runner_ =
worker_pool_->GetSequencedTaskRunnerWithShutdownBehavior(
worker_pool_->GetSequenceToken(),
base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
}
CertDatabase::GetInstance()->AddObserver(this);
}
virtual ~DefaultClientSocketFactory() {
CertDatabase::GetInstance()->RemoveObserver(this);
}
virtual void OnCertAdded(const X509Certificate* cert) OVERRIDE {
ClearSSLSessionCache();
}
virtual void OnCACertChanged(const X509Certificate* cert) OVERRIDE {
ClearSSLSessionCache();
}
virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket(
DatagramSocket::BindType bind_type,
const RandIntCallback& rand_int_cb,
NetLog* net_log,
const NetLog::Source& source) OVERRIDE {
return scoped_ptr<DatagramClientSocket>(
new UDPClientSocket(bind_type, rand_int_cb, net_log, source));
}
virtual scoped_ptr<StreamSocket> CreateTransportClientSocket(
const AddressList& addresses,
NetLog* net_log,
const NetLog::Source& source) OVERRIDE {
return scoped_ptr<StreamSocket>(
new TCPClientSocket(addresses, net_log, source));
}
virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket(
scoped_ptr<ClientSocketHandle> transport_socket,
const HostPortPair& host_and_port,
const SSLConfig& ssl_config,
const SSLClientSocketContext& context) OVERRIDE {
scoped_refptr<base::SequencedTaskRunner> nss_task_runner(
nss_thread_task_runner_);
if (!nss_task_runner.get())
nss_task_runner = base::ThreadTaskRunnerHandle::Get();
#if defined(USE_OPENSSL)
return scoped_ptr<SSLClientSocket>(
new SSLClientSocketOpenSSL(transport_socket.Pass(), host_and_port,
ssl_config, context));
#elif defined(USE_NSS) || defined(OS_MACOSX) || defined(OS_WIN)
return scoped_ptr<SSLClientSocket>(
new SSLClientSocketNSS(nss_task_runner.get(),
transport_socket.Pass(),
host_and_port,
ssl_config,
context));
#else
NOTIMPLEMENTED();
return scoped_ptr<SSLClientSocket>();
#endif
}
virtual void ClearSSLSessionCache() OVERRIDE {
SSLClientSocket::ClearSessionCache();
}
private:
scoped_refptr<base::SequencedWorkerPool> worker_pool_;
scoped_refptr<base::SequencedTaskRunner> nss_thread_task_runner_;
};
static base::LazyInstance<DefaultClientSocketFactory>::Leaky
g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER;
}
ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() {
return g_default_client_socket_factory.Pointer();
}
}