| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/socket/client_socket_factory.h" | 5 #include "net/socket/client_socket_factory.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
| 9 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 worker_pool_ = new base::SequencedWorkerPool(1, "NSS SSL Thread"); | 43 worker_pool_ = new base::SequencedWorkerPool(1, "NSS SSL Thread"); |
| 44 nss_thread_task_runner_ = | 44 nss_thread_task_runner_ = |
| 45 worker_pool_->GetSequencedTaskRunnerWithShutdownBehavior( | 45 worker_pool_->GetSequencedTaskRunnerWithShutdownBehavior( |
| 46 worker_pool_->GetSequenceToken(), | 46 worker_pool_->GetSequenceToken(), |
| 47 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); | 47 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN); |
| 48 } | 48 } |
| 49 | 49 |
| 50 CertDatabase::GetInstance()->AddObserver(this); | 50 CertDatabase::GetInstance()->AddObserver(this); |
| 51 } | 51 } |
| 52 | 52 |
| 53 virtual ~DefaultClientSocketFactory() { | 53 ~DefaultClientSocketFactory() override { |
| 54 // Note: This code never runs, as the factory is defined as a Leaky | 54 // Note: This code never runs, as the factory is defined as a Leaky |
| 55 // singleton. | 55 // singleton. |
| 56 CertDatabase::GetInstance()->RemoveObserver(this); | 56 CertDatabase::GetInstance()->RemoveObserver(this); |
| 57 } | 57 } |
| 58 | 58 |
| 59 virtual void OnCertAdded(const X509Certificate* cert) override { | 59 void OnCertAdded(const X509Certificate* cert) override { |
| 60 ClearSSLSessionCache(); | 60 ClearSSLSessionCache(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 virtual void OnCACertChanged(const X509Certificate* cert) override { | 63 void OnCACertChanged(const X509Certificate* cert) override { |
| 64 // Per wtc, we actually only need to flush when trust is reduced. | 64 // Per wtc, we actually only need to flush when trust is reduced. |
| 65 // Always flush now because OnCACertChanged does not tell us this. | 65 // Always flush now because OnCACertChanged does not tell us this. |
| 66 // See comments in ClientSocketPoolManager::OnCACertChanged. | 66 // See comments in ClientSocketPoolManager::OnCACertChanged. |
| 67 ClearSSLSessionCache(); | 67 ClearSSLSessionCache(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 virtual scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( | 70 scoped_ptr<DatagramClientSocket> CreateDatagramClientSocket( |
| 71 DatagramSocket::BindType bind_type, | 71 DatagramSocket::BindType bind_type, |
| 72 const RandIntCallback& rand_int_cb, | 72 const RandIntCallback& rand_int_cb, |
| 73 NetLog* net_log, | 73 NetLog* net_log, |
| 74 const NetLog::Source& source) override { | 74 const NetLog::Source& source) override { |
| 75 return scoped_ptr<DatagramClientSocket>( | 75 return scoped_ptr<DatagramClientSocket>( |
| 76 new UDPClientSocket(bind_type, rand_int_cb, net_log, source)); | 76 new UDPClientSocket(bind_type, rand_int_cb, net_log, source)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 virtual scoped_ptr<StreamSocket> CreateTransportClientSocket( | 79 scoped_ptr<StreamSocket> CreateTransportClientSocket( |
| 80 const AddressList& addresses, | 80 const AddressList& addresses, |
| 81 NetLog* net_log, | 81 NetLog* net_log, |
| 82 const NetLog::Source& source) override { | 82 const NetLog::Source& source) override { |
| 83 return scoped_ptr<StreamSocket>( | 83 return scoped_ptr<StreamSocket>( |
| 84 new TCPClientSocket(addresses, net_log, source)); | 84 new TCPClientSocket(addresses, net_log, source)); |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual scoped_ptr<SSLClientSocket> CreateSSLClientSocket( | 87 scoped_ptr<SSLClientSocket> CreateSSLClientSocket( |
| 88 scoped_ptr<ClientSocketHandle> transport_socket, | 88 scoped_ptr<ClientSocketHandle> transport_socket, |
| 89 const HostPortPair& host_and_port, | 89 const HostPortPair& host_and_port, |
| 90 const SSLConfig& ssl_config, | 90 const SSLConfig& ssl_config, |
| 91 const SSLClientSocketContext& context) override { | 91 const SSLClientSocketContext& context) override { |
| 92 // nss_thread_task_runner_ may be NULL if g_use_dedicated_nss_thread is | 92 // nss_thread_task_runner_ may be NULL if g_use_dedicated_nss_thread is |
| 93 // false or if the dedicated NSS thread failed to start. If so, cause NSS | 93 // false or if the dedicated NSS thread failed to start. If so, cause NSS |
| 94 // functions to execute on the current task runner. | 94 // functions to execute on the current task runner. |
| 95 // | 95 // |
| 96 // Note: The current task runner is obtained on each call due to unit | 96 // Note: The current task runner is obtained on each call due to unit |
| 97 // tests, which may create and tear down the current thread's TaskRunner | 97 // tests, which may create and tear down the current thread's TaskRunner |
| (...skipping 15 matching lines...) Expand all Loading... |
| 113 transport_socket.Pass(), | 113 transport_socket.Pass(), |
| 114 host_and_port, | 114 host_and_port, |
| 115 ssl_config, | 115 ssl_config, |
| 116 context)); | 116 context)); |
| 117 #else | 117 #else |
| 118 NOTIMPLEMENTED(); | 118 NOTIMPLEMENTED(); |
| 119 return scoped_ptr<SSLClientSocket>(); | 119 return scoped_ptr<SSLClientSocket>(); |
| 120 #endif | 120 #endif |
| 121 } | 121 } |
| 122 | 122 |
| 123 virtual void ClearSSLSessionCache() override { | 123 void ClearSSLSessionCache() override { SSLClientSocket::ClearSessionCache(); } |
| 124 SSLClientSocket::ClearSessionCache(); | |
| 125 } | |
| 126 | 124 |
| 127 private: | 125 private: |
| 128 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 126 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
| 129 scoped_refptr<base::SequencedTaskRunner> nss_thread_task_runner_; | 127 scoped_refptr<base::SequencedTaskRunner> nss_thread_task_runner_; |
| 130 }; | 128 }; |
| 131 | 129 |
| 132 static base::LazyInstance<DefaultClientSocketFactory>::Leaky | 130 static base::LazyInstance<DefaultClientSocketFactory>::Leaky |
| 133 g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER; | 131 g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER; |
| 134 | 132 |
| 135 } // namespace | 133 } // namespace |
| 136 | 134 |
| 137 // static | 135 // static |
| 138 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { | 136 ClientSocketFactory* ClientSocketFactory::GetDefaultFactory() { |
| 139 return g_default_client_socket_factory.Pointer(); | 137 return g_default_client_socket_factory.Pointer(); |
| 140 } | 138 } |
| 141 | 139 |
| 142 } // namespace net | 140 } // namespace net |
| OLD | NEW |