OLD | NEW |
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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 // The max number of sockets to allow per proxy server. This applies both to | 28 // The max number of sockets to allow per proxy server. This applies both to |
29 // http and SOCKS proxies. See http://crbug.com/12066 for details about proxy | 29 // http and SOCKS proxies. See http://crbug.com/12066 for details about proxy |
30 // server connection limits. | 30 // server connection limits. |
31 int g_max_sockets_per_proxy_server = 15; | 31 int g_max_sockets_per_proxy_server = 15; |
32 | 32 |
33 uint16 g_fixed_http_port = 0; | 33 uint16 g_fixed_http_port = 0; |
34 uint16 g_fixed_https_port = 0; | 34 uint16 g_fixed_https_port = 0; |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
| 38 // TODO(vandebo) when we've completely converted to pools, the base TCP |
| 39 // pool name should get changed to TCP instead of Transport. |
38 HttpNetworkSession::HttpNetworkSession( | 40 HttpNetworkSession::HttpNetworkSession( |
39 NetworkChangeNotifier* network_change_notifier, | 41 NetworkChangeNotifier* network_change_notifier, |
40 HostResolver* host_resolver, | 42 HostResolver* host_resolver, |
41 ProxyService* proxy_service, | 43 ProxyService* proxy_service, |
42 ClientSocketFactory* client_socket_factory, | 44 ClientSocketFactory* client_socket_factory, |
43 SSLConfigService* ssl_config_service, | 45 SSLConfigService* ssl_config_service, |
| 46 SpdySessionPool* spdy_session_pool, |
44 HttpAuthHandlerFactory* http_auth_handler_factory) | 47 HttpAuthHandlerFactory* http_auth_handler_factory) |
45 : network_change_notifier_(network_change_notifier), | 48 : network_change_notifier_(network_change_notifier), |
| 49 tcp_socket_pool_(new TCPClientSocketPool( |
| 50 g_max_sockets, g_max_sockets_per_group, "Transport", |
| 51 host_resolver, client_socket_factory, network_change_notifier_)), |
46 socket_factory_(client_socket_factory), | 52 socket_factory_(client_socket_factory), |
47 host_resolver_(host_resolver), | 53 host_resolver_(host_resolver), |
48 tcp_socket_pool_(CreateNewTCPSocketPool()), | |
49 proxy_service_(proxy_service), | 54 proxy_service_(proxy_service), |
50 ssl_config_service_(ssl_config_service), | 55 ssl_config_service_(ssl_config_service), |
51 spdy_session_pool_(new SpdySessionPool), | 56 spdy_session_pool_(spdy_session_pool), |
52 http_auth_handler_factory_(http_auth_handler_factory) { | 57 http_auth_handler_factory_(http_auth_handler_factory) { |
53 DCHECK(proxy_service); | 58 DCHECK(proxy_service); |
54 DCHECK(ssl_config_service); | 59 DCHECK(ssl_config_service); |
55 | |
56 if (network_change_notifier_) | |
57 network_change_notifier_->AddObserver(this); | |
58 } | 60 } |
59 | 61 |
60 HttpNetworkSession::~HttpNetworkSession() { | 62 HttpNetworkSession::~HttpNetworkSession() { |
61 if (network_change_notifier_) | |
62 network_change_notifier_->RemoveObserver(this); | |
63 } | |
64 | |
65 void HttpNetworkSession::OnIPAddressChanged() { | |
66 Flush(); | |
67 } | |
68 | |
69 void HttpNetworkSession::Flush() { | |
70 // TODO(willchan): Flush |host_resolver_|. | |
71 tcp_socket_pool()->CloseIdleSockets(); | |
72 tcp_socket_pool_ = CreateNewTCPSocketPool(); | |
73 for (HTTPProxySocketPoolMap::iterator it = http_proxy_socket_pool_.begin(); | |
74 it != http_proxy_socket_pool_.end(); ++it) | |
75 it->second->CloseIdleSockets(); | |
76 http_proxy_socket_pool_.clear(); | |
77 for (SOCKSSocketPoolMap::iterator it = socks_socket_pool_.begin(); | |
78 it != socks_socket_pool_.end(); ++it) | |
79 it->second->CloseIdleSockets(); | |
80 socks_socket_pool_.clear(); | |
81 spdy_session_pool_ = new SpdySessionPool; | |
82 } | |
83 | |
84 scoped_refptr<TCPClientSocketPool> | |
85 HttpNetworkSession::CreateNewTCPSocketPool() { | |
86 // TODO(vandebo) when we've completely converted to pools, the base TCP | |
87 // pool name should get changed to TCP instead of Transport. | |
88 return new TCPClientSocketPool(g_max_sockets, | |
89 g_max_sockets_per_group, | |
90 "Transport", | |
91 host_resolver_, | |
92 socket_factory_); | |
93 } | 63 } |
94 | 64 |
95 const scoped_refptr<TCPClientSocketPool>& | 65 const scoped_refptr<TCPClientSocketPool>& |
96 HttpNetworkSession::GetSocketPoolForHTTPProxy(const HostPortPair& http_proxy) { | 66 HttpNetworkSession::GetSocketPoolForHTTPProxy(const HostPortPair& http_proxy) { |
97 HTTPProxySocketPoolMap::const_iterator it = | 67 HTTPProxySocketPoolMap::const_iterator it = |
98 http_proxy_socket_pool_.find(http_proxy); | 68 http_proxy_socket_pool_.find(http_proxy); |
99 if (it != http_proxy_socket_pool_.end()) | 69 if (it != http_proxy_socket_pool_.end()) |
100 return it->second; | 70 return it->second; |
101 | 71 |
102 std::pair<HTTPProxySocketPoolMap::iterator, bool> ret = | 72 std::pair<HTTPProxySocketPoolMap::iterator, bool> ret = |
103 http_proxy_socket_pool_.insert( | 73 http_proxy_socket_pool_.insert( |
104 std::make_pair( | 74 std::make_pair( |
105 http_proxy, | 75 http_proxy, |
106 new TCPClientSocketPool( | 76 new TCPClientSocketPool( |
107 g_max_sockets_per_proxy_server, g_max_sockets_per_group, | 77 g_max_sockets_per_proxy_server, g_max_sockets_per_group, |
108 "HTTPProxy", host_resolver_, socket_factory_))); | 78 "HTTPProxy", host_resolver_, socket_factory_, |
| 79 network_change_notifier_))); |
109 | 80 |
110 return ret.first->second; | 81 return ret.first->second; |
111 } | 82 } |
112 | 83 |
113 const scoped_refptr<SOCKSClientSocketPool>& | 84 const scoped_refptr<SOCKSClientSocketPool>& |
114 HttpNetworkSession::GetSocketPoolForSOCKSProxy( | 85 HttpNetworkSession::GetSocketPoolForSOCKSProxy( |
115 const HostPortPair& socks_proxy) { | 86 const HostPortPair& socks_proxy) { |
116 SOCKSSocketPoolMap::const_iterator it = socks_socket_pool_.find(socks_proxy); | 87 SOCKSSocketPoolMap::const_iterator it = socks_socket_pool_.find(socks_proxy); |
117 if (it != socks_socket_pool_.end()) | 88 if (it != socks_socket_pool_.end()) |
118 return it->second; | 89 return it->second; |
119 | 90 |
120 std::pair<SOCKSSocketPoolMap::iterator, bool> ret = | 91 std::pair<SOCKSSocketPoolMap::iterator, bool> ret = |
121 socks_socket_pool_.insert( | 92 socks_socket_pool_.insert( |
122 std::make_pair( | 93 std::make_pair( |
123 socks_proxy, | 94 socks_proxy, |
124 new SOCKSClientSocketPool( | 95 new SOCKSClientSocketPool( |
125 g_max_sockets_per_proxy_server, g_max_sockets_per_group, | 96 g_max_sockets_per_proxy_server, g_max_sockets_per_group, |
126 "SOCKS", host_resolver_, | 97 "SOCKS", host_resolver_, |
127 new TCPClientSocketPool(g_max_sockets_per_proxy_server, | 98 new TCPClientSocketPool(g_max_sockets_per_proxy_server, |
128 g_max_sockets_per_group, | 99 g_max_sockets_per_group, |
129 "TCPForSOCKS", host_resolver_, | 100 "TCPForSOCKS", host_resolver_, |
130 socket_factory_)))); | 101 socket_factory_, |
| 102 network_change_notifier_), |
| 103 network_change_notifier_))); |
131 | 104 |
132 return ret.first->second; | 105 return ret.first->second; |
133 } | 106 } |
134 | 107 |
135 // static | 108 // static |
136 void HttpNetworkSession::set_max_sockets_per_group(int socket_count) { | 109 void HttpNetworkSession::set_max_sockets_per_group(int socket_count) { |
137 DCHECK_LT(0, socket_count); | 110 DCHECK_LT(0, socket_count); |
138 // The following is a sanity check... but we should NEVER be near this value. | 111 // The following is a sanity check... but we should NEVER be near this value. |
139 DCHECK_GT(100, socket_count); | 112 DCHECK_GT(100, socket_count); |
140 g_max_sockets_per_group = socket_count; | 113 g_max_sockets_per_group = socket_count; |
(...skipping 12 matching lines...) Expand all Loading... |
153 // static | 126 // static |
154 uint16 HttpNetworkSession::fixed_https_port() { | 127 uint16 HttpNetworkSession::fixed_https_port() { |
155 return g_fixed_https_port; | 128 return g_fixed_https_port; |
156 } | 129 } |
157 | 130 |
158 // static | 131 // static |
159 void HttpNetworkSession::set_fixed_https_port(uint16 port) { | 132 void HttpNetworkSession::set_fixed_https_port(uint16 port) { |
160 g_fixed_https_port = port; | 133 g_fixed_https_port = port; |
161 } | 134 } |
162 | 135 |
| 136 // TODO(vandebo) when we've completely converted to pools, the base TCP |
| 137 // pool name should get changed to TCP instead of Transport. |
| 138 void HttpNetworkSession::ReplaceTCPSocketPool() { |
| 139 tcp_socket_pool_ = new TCPClientSocketPool(g_max_sockets, |
| 140 g_max_sockets_per_group, |
| 141 "Transport", |
| 142 host_resolver_, |
| 143 socket_factory_, |
| 144 network_change_notifier_); |
| 145 } |
| 146 |
163 } // namespace net | 147 } // namespace net |
OLD | NEW |