Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(615)

Side by Side Diff: net/socket/client_socket_factory.cc

Issue 10749009: Switch the NSS thread from being a base::Thread to a base::SequencedWorkerPool of 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove suppression Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | net/socket/ssl_client_socket_nss.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/thread.h" 9 #include "base/threading/sequenced_worker_pool.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "net/base/cert_database.h" 11 #include "net/base/cert_database.h"
12 #include "net/socket/client_socket_handle.h" 12 #include "net/socket/client_socket_handle.h"
13 #if defined(OS_WIN) 13 #if defined(OS_WIN)
14 #include "net/socket/ssl_client_socket_nss.h" 14 #include "net/socket/ssl_client_socket_nss.h"
15 #include "net/socket/ssl_client_socket_win.h" 15 #include "net/socket/ssl_client_socket_win.h"
16 #elif defined(USE_OPENSSL) 16 #elif defined(USE_OPENSSL)
17 #include "net/socket/ssl_client_socket_openssl.h" 17 #include "net/socket/ssl_client_socket_openssl.h"
18 #elif defined(USE_NSS) 18 #elif defined(USE_NSS)
19 #include "net/socket/ssl_client_socket_nss.h" 19 #include "net/socket/ssl_client_socket_nss.h"
(...skipping 20 matching lines...) Expand all
40 bool g_use_dedicated_nss_thread = true; 40 bool g_use_dedicated_nss_thread = true;
41 #else 41 #else
42 bool g_use_dedicated_nss_thread = false; 42 bool g_use_dedicated_nss_thread = false;
43 #endif 43 #endif
44 44
45 class DefaultClientSocketFactory : public ClientSocketFactory, 45 class DefaultClientSocketFactory : public ClientSocketFactory,
46 public CertDatabase::Observer { 46 public CertDatabase::Observer {
47 public: 47 public:
48 DefaultClientSocketFactory() { 48 DefaultClientSocketFactory() {
49 if (g_use_dedicated_nss_thread) { 49 if (g_use_dedicated_nss_thread) {
50 nss_thread_.reset(new base::Thread("NSS SSL Thread")); 50 // Use a single thread for the worker pool.
51 if (nss_thread_->Start()) 51 worker_pool_ = new base::SequencedWorkerPool(1, "NSS SSL Thread");
52 nss_thread_task_runner_ = nss_thread_->message_loop_proxy(); 52 nss_thread_task_runner_ =
53 worker_pool_->GetSequencedTaskRunnerWithShutdownBehavior(
54 worker_pool_->GetSequenceToken(),
55 base::SequencedWorkerPool::CONTINUE_ON_SHUTDOWN);
53 } 56 }
54 57
55 CertDatabase::AddObserver(this); 58 CertDatabase::AddObserver(this);
56 } 59 }
57 60
58 virtual ~DefaultClientSocketFactory() { 61 virtual ~DefaultClientSocketFactory() {
59 // 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
60 // singleton. 63 // singleton.
61 CertDatabase::RemoveObserver(this); 64 CertDatabase::RemoveObserver(this);
62 } 65 }
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const SSLClientSocketContext& context) { 97 const SSLClientSocketContext& context) {
95 // 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
96 // 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
97 // functions to execute on the current task runner. 100 // functions to execute on the current task runner.
98 // 101 //
99 // 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
100 // 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
101 // between each test. Because the DefaultClientSocketFactory is leaky, it 104 // between each test. Because the DefaultClientSocketFactory is leaky, it
102 // 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
103 // from call to call. 106 // from call to call.
104 scoped_refptr<base::SingleThreadTaskRunner> nss_task_runner( 107 scoped_refptr<base::SequencedTaskRunner> nss_task_runner(
105 nss_thread_task_runner_); 108 nss_thread_task_runner_);
106 if (!nss_task_runner) 109 if (!nss_task_runner)
107 nss_task_runner = base::ThreadTaskRunnerHandle::Get(); 110 nss_task_runner = base::ThreadTaskRunnerHandle::Get();
108 111
109 #if defined(USE_OPENSSL) 112 #if defined(USE_OPENSSL)
110 return new SSLClientSocketOpenSSL(transport_socket, host_and_port, 113 return new SSLClientSocketOpenSSL(transport_socket, host_and_port,
111 ssl_config, context); 114 ssl_config, context);
112 #elif defined(USE_NSS) 115 #elif defined(USE_NSS)
113 return new SSLClientSocketNSS(nss_task_runner, transport_socket, 116 return new SSLClientSocketNSS(nss_task_runner, transport_socket,
114 host_and_port, ssl_config, context); 117 host_and_port, ssl_config, context);
(...skipping 17 matching lines...) Expand all
132 NOTIMPLEMENTED(); 135 NOTIMPLEMENTED();
133 return NULL; 136 return NULL;
134 #endif 137 #endif
135 } 138 }
136 139
137 void ClearSSLSessionCache() { 140 void ClearSSLSessionCache() {
138 SSLClientSocket::ClearSessionCache(); 141 SSLClientSocket::ClearSessionCache();
139 } 142 }
140 143
141 private: 144 private:
142 scoped_ptr<base::Thread> nss_thread_; 145 scoped_refptr<base::SequencedWorkerPool> worker_pool_;
143 scoped_refptr<base::SingleThreadTaskRunner> nss_thread_task_runner_; 146 scoped_refptr<base::SequencedTaskRunner> nss_thread_task_runner_;
144 }; 147 };
145 148
146 static base::LazyInstance<DefaultClientSocketFactory>::Leaky 149 static base::LazyInstance<DefaultClientSocketFactory>::Leaky
147 g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER; 150 g_default_client_socket_factory = LAZY_INSTANCE_INITIALIZER;
148 151
149 } // namespace 152 } // namespace
150 153
151 // Deprecated function (http://crbug.com/37810) that takes a StreamSocket. 154 // Deprecated function (http://crbug.com/37810) that takes a StreamSocket.
152 SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket( 155 SSLClientSocket* ClientSocketFactory::CreateSSLClientSocket(
153 StreamSocket* transport_socket, 156 StreamSocket* transport_socket,
(...skipping 18 matching lines...) Expand all
172 #if defined(OS_WIN) 175 #if defined(OS_WIN)
173 // Reflect the capability of SSLClientSocketWin. 176 // Reflect the capability of SSLClientSocketWin.
174 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1); 177 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1);
175 #elif defined(OS_MACOSX) 178 #elif defined(OS_MACOSX)
176 // Reflect the capability of SSLClientSocketMac. 179 // Reflect the capability of SSLClientSocketMac.
177 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1); 180 SSLConfigService::SetDefaultVersionMax(SSL_PROTOCOL_VERSION_TLS1);
178 #endif 181 #endif
179 } 182 }
180 183
181 } // namespace net 184 } // namespace net
OLDNEW
« no previous file with comments | « no previous file | net/socket/ssl_client_socket_nss.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698