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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 CertDatabase::AddObserver(this); | 58 CertDatabase::AddObserver(this); |
59 } | 59 } |
60 | 60 |
61 virtual ~DefaultClientSocketFactory() { | 61 virtual ~DefaultClientSocketFactory() { |
62 // Note: This code never runs, as the factory is defined as a Leaky | 62 // Note: This code never runs, as the factory is defined as a Leaky |
63 // singleton. | 63 // singleton. |
64 CertDatabase::RemoveObserver(this); | 64 CertDatabase::RemoveObserver(this); |
65 } | 65 } |
66 | 66 |
67 virtual void OnUserCertAdded(const X509Certificate* cert) { | 67 virtual void OnUserCertAdded(const X509Certificate* cert) OVERRIDE { |
68 ClearSSLSessionCache(); | 68 ClearSSLSessionCache(); |
69 } | 69 } |
70 | 70 |
71 virtual void OnCertTrustChanged(const X509Certificate* cert) { | 71 virtual void OnCertTrustChanged(const X509Certificate* cert) OVERRIDE { |
72 // Per wtc, we actually only need to flush when trust is reduced. | 72 // Per wtc, we actually only need to flush when trust is reduced. |
73 // Always flush now because OnCertTrustChanged does not tell us this. | 73 // Always flush now because OnCertTrustChanged does not tell us this. |
74 // See comments in ClientSocketPoolManager::OnCertTrustChanged. | 74 // See comments in ClientSocketPoolManager::OnCertTrustChanged. |
75 ClearSSLSessionCache(); | 75 ClearSSLSessionCache(); |
76 } | 76 } |
77 | 77 |
78 virtual DatagramClientSocket* CreateDatagramClientSocket( | 78 virtual DatagramClientSocket* CreateDatagramClientSocket( |
79 DatagramSocket::BindType bind_type, | 79 DatagramSocket::BindType bind_type, |
80 const RandIntCallback& rand_int_cb, | 80 const RandIntCallback& rand_int_cb, |
81 NetLog* net_log, | 81 NetLog* net_log, |
82 const NetLog::Source& source) { | 82 const NetLog::Source& source) OVERRIDE { |
83 return new UDPClientSocket(bind_type, rand_int_cb, net_log, source); | 83 return new UDPClientSocket(bind_type, rand_int_cb, net_log, source); |
84 } | 84 } |
85 | 85 |
86 virtual StreamSocket* CreateTransportClientSocket( | 86 virtual StreamSocket* CreateTransportClientSocket( |
87 const AddressList& addresses, | 87 const AddressList& addresses, |
88 NetLog* net_log, | 88 NetLog* net_log, |
89 const NetLog::Source& source) { | 89 const NetLog::Source& source) OVERRIDE { |
90 return new TCPClientSocket(addresses, net_log, source); | 90 return new TCPClientSocket(addresses, net_log, source); |
91 } | 91 } |
92 | 92 |
93 virtual SSLClientSocket* CreateSSLClientSocket( | 93 virtual SSLClientSocket* CreateSSLClientSocket( |
94 ClientSocketHandle* transport_socket, | 94 ClientSocketHandle* transport_socket, |
95 const HostPortPair& host_and_port, | 95 const HostPortPair& host_and_port, |
96 const SSLConfig& ssl_config, | 96 const SSLConfig& ssl_config, |
97 const SSLClientSocketContext& context) { | 97 const SSLClientSocketContext& context) OVERRIDE { |
98 // nss_thread_task_runner_ may be NULL if g_use_dedicated_nss_thread is | 98 // nss_thread_task_runner_ may be NULL if g_use_dedicated_nss_thread is |
99 // false or if the dedicated NSS thread failed to start. If so, cause NSS | 99 // false or if the dedicated NSS thread failed to start. If so, cause NSS |
100 // functions to execute on the current task runner. | 100 // functions to execute on the current task runner. |
101 // | 101 // |
102 // Note: The current task runner is obtained on each call due to unit | 102 // Note: The current task runner is obtained on each call due to unit |
103 // tests, which may create and tear down the current thread's TaskRunner | 103 // tests, which may create and tear down the current thread's TaskRunner |
104 // between each test. Because the DefaultClientSocketFactory is leaky, it | 104 // between each test. Because the DefaultClientSocketFactory is leaky, it |
105 // may span multiple tests, and thus the current task runner may change | 105 // may span multiple tests, and thus the current task runner may change |
106 // from call to call. | 106 // from call to call. |
107 scoped_refptr<base::SequencedTaskRunner> nss_task_runner( | 107 scoped_refptr<base::SequencedTaskRunner> nss_task_runner( |
(...skipping 22 matching lines...) Expand all Loading... |
130 } | 130 } |
131 return new SSLClientSocketNSS(nss_task_runner, transport_socket, | 131 return new SSLClientSocketNSS(nss_task_runner, transport_socket, |
132 host_and_port, ssl_config, | 132 host_and_port, ssl_config, |
133 context); | 133 context); |
134 #else | 134 #else |
135 NOTIMPLEMENTED(); | 135 NOTIMPLEMENTED(); |
136 return NULL; | 136 return NULL; |
137 #endif | 137 #endif |
138 } | 138 } |
139 | 139 |
140 void ClearSSLSessionCache() { | 140 virtual void ClearSSLSessionCache() OVERRIDE { |
141 SSLClientSocket::ClearSessionCache(); | 141 SSLClientSocket::ClearSessionCache(); |
142 } | 142 } |
143 | 143 |
144 private: | 144 private: |
145 scoped_refptr<base::SequencedWorkerPool> worker_pool_; | 145 scoped_refptr<base::SequencedWorkerPool> worker_pool_; |
146 scoped_refptr<base::SequencedTaskRunner> nss_thread_task_runner_; | 146 scoped_refptr<base::SequencedTaskRunner> nss_thread_task_runner_; |
147 }; | 147 }; |
148 | 148 |
149 static base::LazyInstance<DefaultClientSocketFactory>::Leaky | 149 static base::LazyInstance<DefaultClientSocketFactory>::Leaky |
150 g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER; | 150 g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER; |
(...skipping 24 matching lines...) Expand all Loading... |
175 #if defined(OS_WIN) | 175 #if defined(OS_WIN) |
176 // Reflect the capability of SSLClientSocketWin. | 176 // Reflect the capability of SSLClientSocketWin. |
177 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1); | 177 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1); |
178 #elif defined(OS_MACOSX) | 178 #elif defined(OS_MACOSX) |
179 // Reflect the capability of SSLClientSocketMac. | 179 // Reflect the capability of SSLClientSocketMac. |
180 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1); | 180 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1); |
181 #endif | 181 #endif |
182 } | 182 } |
183 | 183 |
184 } // namespace net | 184 } // namespace net |
OLD | NEW |