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

Side by Side Diff: net/http/http_network_session.cc

Issue 1615005: Flush socket pools and SPDY session pool properly on explicit requests and network changes. (Closed)
Patch Set: Fix minor leak. Created 10 years, 8 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
« no previous file with comments | « net/http/http_network_session.h ('k') | net/http/http_network_session_unittest.cc » ('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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/http/http_network_session.h" 5 #include "net/http/http_network_session.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "net/http/http_auth_handler_factory.h" 8 #include "net/http/http_auth_handler_factory.h"
9 #include "net/http/url_security_manager.h" 9 #include "net/http/url_security_manager.h"
10 #include "net/spdy/spdy_session_pool.h" 10 #include "net/spdy/spdy_session_pool.h"
(...skipping 11 matching lines...) Expand all
22 uint16 HttpNetworkSession::g_fixed_https_port = 0; 22 uint16 HttpNetworkSession::g_fixed_https_port = 0;
23 23
24 // TODO(vandebo) when we've completely converted to pools, the base TCP 24 // TODO(vandebo) when we've completely converted to pools, the base TCP
25 // pool name should get changed to TCP instead of Transport. 25 // pool name should get changed to TCP instead of Transport.
26 HttpNetworkSession::HttpNetworkSession( 26 HttpNetworkSession::HttpNetworkSession(
27 NetworkChangeNotifier* network_change_notifier, 27 NetworkChangeNotifier* network_change_notifier,
28 HostResolver* host_resolver, 28 HostResolver* host_resolver,
29 ProxyService* proxy_service, 29 ProxyService* proxy_service,
30 ClientSocketFactory* client_socket_factory, 30 ClientSocketFactory* client_socket_factory,
31 SSLConfigService* ssl_config_service, 31 SSLConfigService* ssl_config_service,
32 SpdySessionPool* spdy_session_pool,
33 HttpAuthHandlerFactory* http_auth_handler_factory) 32 HttpAuthHandlerFactory* http_auth_handler_factory)
34 : network_change_notifier_(network_change_notifier), 33 : network_change_notifier_(network_change_notifier),
35 tcp_socket_pool_(new TCPClientSocketPool(
36 max_sockets_, max_sockets_per_group_, "Transport",
37 host_resolver, client_socket_factory, network_change_notifier_)),
38 socks_socket_pool_(new SOCKSClientSocketPool(
39 max_sockets_, max_sockets_per_group_, "SOCKS", host_resolver,
40 new TCPClientSocketPool(max_sockets_, max_sockets_per_group_,
41 "TCPForSOCKS", host_resolver,
42 client_socket_factory,
43 network_change_notifier_),
44 network_change_notifier_)),
45 socket_factory_(client_socket_factory), 34 socket_factory_(client_socket_factory),
46 host_resolver_(host_resolver), 35 host_resolver_(host_resolver),
36 tcp_socket_pool_(CreateNewTCPSocketPool()),
37 socks_socket_pool_(CreateNewSOCKSSocketPool()),
47 proxy_service_(proxy_service), 38 proxy_service_(proxy_service),
48 ssl_config_service_(ssl_config_service), 39 ssl_config_service_(ssl_config_service),
49 spdy_session_pool_(spdy_session_pool), 40 spdy_session_pool_(new SpdySessionPool()),
50 http_auth_handler_factory_(http_auth_handler_factory) { 41 http_auth_handler_factory_(http_auth_handler_factory) {
51 DCHECK(proxy_service); 42 DCHECK(proxy_service);
52 DCHECK(ssl_config_service); 43 DCHECK(ssl_config_service);
44
45 if (network_change_notifier)
46 network_change_notifier_->AddObserver(this);
53 } 47 }
54 48
55 HttpNetworkSession::~HttpNetworkSession() { 49 HttpNetworkSession::~HttpNetworkSession() {
50 if (network_change_notifier_)
51 network_change_notifier_->RemoveObserver(this);
56 } 52 }
57 53
58 URLSecurityManager* HttpNetworkSession::GetURLSecurityManager() { 54 URLSecurityManager* HttpNetworkSession::GetURLSecurityManager() {
59 // Create the URL security manager lazily in the first call. 55 // Create the URL security manager lazily in the first call.
60 // This is called on a single thread. 56 // This is called on a single thread.
61 if (!url_security_manager_.get()) { 57 if (!url_security_manager_.get()) {
62 url_security_manager_.reset( 58 url_security_manager_.reset(
63 URLSecurityManager::Create(http_auth_handler_factory_->filter())); 59 URLSecurityManager::Create(http_auth_handler_factory_->filter()));
64 } 60 }
65 return url_security_manager_.get(); 61 return url_security_manager_.get();
66 } 62 }
67 63
68 // static 64 // static
69 void HttpNetworkSession::set_max_sockets_per_group(int socket_count) { 65 void HttpNetworkSession::set_max_sockets_per_group(int socket_count) {
70 DCHECK(0 < socket_count); 66 DCHECK_LT(0, socket_count);
71 // The following is a sanity check... but we should NEVER be near this value. 67 // The following is a sanity check... but we should NEVER be near this value.
72 DCHECK(100 > socket_count); 68 DCHECK_GT(100, socket_count);
73 max_sockets_per_group_ = socket_count; 69 max_sockets_per_group_ = socket_count;
74 } 70 }
75 71
76 // TODO(vandebo) when we've completely converted to pools, the base TCP 72 void HttpNetworkSession::Flush() {
77 // pool name should get changed to TCP instead of Transport. 73 host_resolver()->Flush();
78 void HttpNetworkSession::ReplaceTCPSocketPool() { 74 tcp_socket_pool()->CloseIdleSockets();
79 tcp_socket_pool_ = new TCPClientSocketPool(max_sockets_, 75 tcp_socket_pool_ = CreateNewTCPSocketPool();
80 max_sockets_per_group_, 76 socks_socket_pool()->CloseIdleSockets();
81 "Transport", 77 socks_socket_pool_ = CreateNewSOCKSSocketPool();
82 host_resolver_, 78 spdy_session_pool_->CloseAllSessions();
83 socket_factory_, 79 spdy_session_pool_ = new SpdySessionPool;
84 network_change_notifier_); 80 }
81
82 void HttpNetworkSession::OnIPAddressChanged() {
83 Flush();
84 }
85
86 scoped_refptr<TCPClientSocketPool>
87 HttpNetworkSession::CreateNewTCPSocketPool() {
88 // TODO(vandebo) when we've completely converted to pools, the base TCP
89 // pool name should get changed to TCP instead of Transport.
90 return new TCPClientSocketPool(max_sockets_,
91 max_sockets_per_group_,
92 "Transport",
93 host_resolver_,
94 socket_factory_);
95 }
96
97 scoped_refptr<SOCKSClientSocketPool>
98 HttpNetworkSession::CreateNewSOCKSSocketPool() {
99 return new SOCKSClientSocketPool(
100 max_sockets_, max_sockets_per_group_, "SOCKS", host_resolver_,
101 new TCPClientSocketPool(max_sockets_, max_sockets_per_group_,
102 "TCPForSOCKS", host_resolver_,
103 socket_factory_));
85 } 104 }
86 105
87 } // namespace net 106 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_network_session.h ('k') | net/http/http_network_session_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698