OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // ClientSocketPoolManager manages access to all ClientSocketPools. It's a | 5 // ClientSocketPoolManager manages access to all ClientSocketPools. It's a |
6 // simple container for all of them. Most importantly, it handles the lifetime | 6 // simple container for all of them. Most importantly, it handles the lifetime |
7 // and destruction order properly. | 7 // and destruction order properly. |
8 | 8 |
9 #include "net/socket/client_socket_pool_manager.h" | 9 #include "net/socket/client_socket_pool_manager.h" |
10 | 10 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 for (typename MapType::const_iterator it = socket_pools.begin(); | 51 for (typename MapType::const_iterator it = socket_pools.begin(); |
52 it != socket_pools.end(); it++) { | 52 it != socket_pools.end(); it++) { |
53 list->Append(it->second->GetInfoAsValue(it->first.ToString(), | 53 list->Append(it->second->GetInfoAsValue(it->first.ToString(), |
54 type, | 54 type, |
55 include_nested_pools)); | 55 include_nested_pools)); |
56 } | 56 } |
57 } | 57 } |
58 | 58 |
59 // The meat of the implementation for the InitSocketHandleForHttpRequest, | 59 // The meat of the implementation for the InitSocketHandleForHttpRequest, |
60 // InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods. | 60 // InitSocketHandleForRawConnect and PreconnectSocketsForHttpRequest methods. |
61 int InitSocketPoolHelper(const HttpRequestInfo& request_info, | 61 int InitSocketPoolHelper(const GURL& request_url, |
| 62 const GURL& request_referrer, |
| 63 const HttpRequestHeaders& request_extra_headers, |
| 64 int request_load_flags, |
| 65 RequestPriority request_priority, |
62 HttpNetworkSession* session, | 66 HttpNetworkSession* session, |
63 const ProxyInfo& proxy_info, | 67 const ProxyInfo& proxy_info, |
64 bool force_spdy_over_ssl, | 68 bool force_spdy_over_ssl, |
65 bool want_spdy_over_npn, | 69 bool want_spdy_over_npn, |
66 const SSLConfig& ssl_config_for_origin, | 70 const SSLConfig& ssl_config_for_origin, |
67 const SSLConfig& ssl_config_for_proxy, | 71 const SSLConfig& ssl_config_for_proxy, |
68 bool force_tunnel, | 72 bool force_tunnel, |
69 const BoundNetLog& net_log, | 73 const BoundNetLog& net_log, |
70 int num_preconnect_streams, | 74 int num_preconnect_streams, |
71 ClientSocketHandle* socket_handle, | 75 ClientSocketHandle* socket_handle, |
72 CompletionCallback* callback) { | 76 CompletionCallback* callback) { |
73 scoped_refptr<TransportSocketParams> tcp_params; | 77 scoped_refptr<TransportSocketParams> tcp_params; |
74 scoped_refptr<HttpProxySocketParams> http_proxy_params; | 78 scoped_refptr<HttpProxySocketParams> http_proxy_params; |
75 scoped_refptr<SOCKSSocketParams> socks_params; | 79 scoped_refptr<SOCKSSocketParams> socks_params; |
76 scoped_ptr<HostPortPair> proxy_host_port; | 80 scoped_ptr<HostPortPair> proxy_host_port; |
77 | 81 |
78 bool using_ssl = request_info.url.SchemeIs("https") || force_spdy_over_ssl; | 82 bool using_ssl = request_url.SchemeIs("https") || force_spdy_over_ssl; |
79 | 83 |
80 HostPortPair origin_host_port = | 84 HostPortPair origin_host_port = |
81 HostPortPair(request_info.url.HostNoBrackets(), | 85 HostPortPair(request_url.HostNoBrackets(), |
82 request_info.url.EffectiveIntPort()); | 86 request_url.EffectiveIntPort()); |
83 | 87 |
84 bool disable_resolver_cache = | 88 bool disable_resolver_cache = |
85 request_info.load_flags & LOAD_BYPASS_CACHE || | 89 request_load_flags & LOAD_BYPASS_CACHE || |
86 request_info.load_flags & LOAD_VALIDATE_CACHE || | 90 request_load_flags & LOAD_VALIDATE_CACHE || |
87 request_info.load_flags & LOAD_DISABLE_CACHE; | 91 request_load_flags & LOAD_DISABLE_CACHE; |
88 | 92 |
89 int load_flags = request_info.load_flags; | 93 int load_flags = request_load_flags; |
90 if (HttpStreamFactory::ignore_certificate_errors()) | 94 if (HttpStreamFactory::ignore_certificate_errors()) |
91 load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; | 95 load_flags |= LOAD_IGNORE_ALL_CERT_ERRORS; |
92 | 96 |
93 // Build the string used to uniquely identify connections of this type. | 97 // Build the string used to uniquely identify connections of this type. |
94 // Determine the host and port to connect to. | 98 // Determine the host and port to connect to. |
95 std::string connection_group = origin_host_port.ToString(); | 99 std::string connection_group = origin_host_port.ToString(); |
96 DCHECK(!connection_group.empty()); | 100 DCHECK(!connection_group.empty()); |
97 if (using_ssl) | 101 if (using_ssl) |
98 connection_group = base::StringPrintf("ssl/%s", connection_group.c_str()); | 102 connection_group = base::StringPrintf("ssl/%s", connection_group.c_str()); |
99 | 103 |
100 bool ignore_limits = (request_info.load_flags & LOAD_IGNORE_LIMITS) != 0; | 104 bool ignore_limits = (request_load_flags & LOAD_IGNORE_LIMITS) != 0; |
101 if (proxy_info.is_direct()) { | 105 if (proxy_info.is_direct()) { |
102 tcp_params = new TransportSocketParams(origin_host_port, | 106 tcp_params = new TransportSocketParams(origin_host_port, |
103 request_info.priority, | 107 request_priority, |
104 request_info.referrer, | 108 request_referrer, |
105 disable_resolver_cache, | 109 disable_resolver_cache, |
106 ignore_limits); | 110 ignore_limits); |
107 } else { | 111 } else { |
108 ProxyServer proxy_server = proxy_info.proxy_server(); | 112 ProxyServer proxy_server = proxy_info.proxy_server(); |
109 proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair())); | 113 proxy_host_port.reset(new HostPortPair(proxy_server.host_port_pair())); |
110 scoped_refptr<TransportSocketParams> proxy_tcp_params( | 114 scoped_refptr<TransportSocketParams> proxy_tcp_params( |
111 new TransportSocketParams(*proxy_host_port, | 115 new TransportSocketParams(*proxy_host_port, |
112 request_info.priority, | 116 request_priority, |
113 request_info.referrer, | 117 request_referrer, |
114 disable_resolver_cache, | 118 disable_resolver_cache, |
115 ignore_limits)); | 119 ignore_limits)); |
116 | 120 |
117 if (proxy_info.is_http() || proxy_info.is_https()) { | 121 if (proxy_info.is_http() || proxy_info.is_https()) { |
118 std::string user_agent; | 122 std::string user_agent; |
119 request_info.extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, | 123 request_extra_headers.GetHeader(HttpRequestHeaders::kUserAgent, |
120 &user_agent); | 124 &user_agent); |
121 scoped_refptr<SSLSocketParams> ssl_params; | 125 scoped_refptr<SSLSocketParams> ssl_params; |
122 if (proxy_info.is_https()) { | 126 if (proxy_info.is_https()) { |
123 // Set ssl_params, and unset proxy_tcp_params | 127 // Set ssl_params, and unset proxy_tcp_params |
124 ssl_params = new SSLSocketParams(proxy_tcp_params, | 128 ssl_params = new SSLSocketParams(proxy_tcp_params, |
125 NULL, | 129 NULL, |
126 NULL, | 130 NULL, |
127 ProxyServer::SCHEME_DIRECT, | 131 ProxyServer::SCHEME_DIRECT, |
128 *proxy_host_port.get(), | 132 *proxy_host_port.get(), |
129 ssl_config_for_proxy, | 133 ssl_config_for_proxy, |
130 load_flags, | 134 load_flags, |
131 force_spdy_over_ssl, | 135 force_spdy_over_ssl, |
132 want_spdy_over_npn); | 136 want_spdy_over_npn); |
133 proxy_tcp_params = NULL; | 137 proxy_tcp_params = NULL; |
134 } | 138 } |
135 | 139 |
136 http_proxy_params = | 140 http_proxy_params = |
137 new HttpProxySocketParams(proxy_tcp_params, | 141 new HttpProxySocketParams(proxy_tcp_params, |
138 ssl_params, | 142 ssl_params, |
139 request_info.url, | 143 request_url, |
140 user_agent, | 144 user_agent, |
141 origin_host_port, | 145 origin_host_port, |
142 session->http_auth_cache(), | 146 session->http_auth_cache(), |
143 session->http_auth_handler_factory(), | 147 session->http_auth_handler_factory(), |
144 session->spdy_session_pool(), | 148 session->spdy_session_pool(), |
145 force_tunnel || using_ssl); | 149 force_tunnel || using_ssl); |
146 } else { | 150 } else { |
147 DCHECK(proxy_info.is_socks()); | 151 DCHECK(proxy_info.is_socks()); |
148 char socks_version; | 152 char socks_version; |
149 if (proxy_server.scheme() == ProxyServer::SCHEME_SOCKS5) | 153 if (proxy_server.scheme() == ProxyServer::SCHEME_SOCKS5) |
150 socks_version = '5'; | 154 socks_version = '5'; |
151 else | 155 else |
152 socks_version = '4'; | 156 socks_version = '4'; |
153 connection_group = base::StringPrintf( | 157 connection_group = base::StringPrintf( |
154 "socks%c/%s", socks_version, connection_group.c_str()); | 158 "socks%c/%s", socks_version, connection_group.c_str()); |
155 | 159 |
156 socks_params = new SOCKSSocketParams(proxy_tcp_params, | 160 socks_params = new SOCKSSocketParams(proxy_tcp_params, |
157 socks_version == '5', | 161 socks_version == '5', |
158 origin_host_port, | 162 origin_host_port, |
159 request_info.priority, | 163 request_priority, |
160 request_info.referrer); | 164 request_referrer); |
161 } | 165 } |
162 } | 166 } |
163 | 167 |
164 // Deal with SSL - which layers on top of any given proxy. | 168 // Deal with SSL - which layers on top of any given proxy. |
165 if (using_ssl) { | 169 if (using_ssl) { |
166 scoped_refptr<SSLSocketParams> ssl_params = | 170 scoped_refptr<SSLSocketParams> ssl_params = |
167 new SSLSocketParams(tcp_params, | 171 new SSLSocketParams(tcp_params, |
168 socks_params, | 172 socks_params, |
169 http_proxy_params, | 173 http_proxy_params, |
170 proxy_info.proxy_server().scheme(), | 174 proxy_info.proxy_server().scheme(), |
171 origin_host_port, | 175 origin_host_port, |
172 ssl_config_for_origin, | 176 ssl_config_for_origin, |
173 load_flags, | 177 load_flags, |
174 force_spdy_over_ssl, | 178 force_spdy_over_ssl, |
175 want_spdy_over_npn); | 179 want_spdy_over_npn); |
176 SSLClientSocketPool* ssl_pool = NULL; | 180 SSLClientSocketPool* ssl_pool = NULL; |
177 if (proxy_info.is_direct()) | 181 if (proxy_info.is_direct()) |
178 ssl_pool = session->ssl_socket_pool(); | 182 ssl_pool = session->ssl_socket_pool(); |
179 else | 183 else |
180 ssl_pool = session->GetSocketPoolForSSLWithProxy(*proxy_host_port); | 184 ssl_pool = session->GetSocketPoolForSSLWithProxy(*proxy_host_port); |
181 | 185 |
182 if (num_preconnect_streams) { | 186 if (num_preconnect_streams) { |
183 RequestSocketsForPool(ssl_pool, connection_group, ssl_params, | 187 RequestSocketsForPool(ssl_pool, connection_group, ssl_params, |
184 num_preconnect_streams, net_log); | 188 num_preconnect_streams, net_log); |
185 return OK; | 189 return OK; |
186 } | 190 } |
187 | 191 |
188 return socket_handle->Init(connection_group, ssl_params, | 192 return socket_handle->Init(connection_group, ssl_params, |
189 request_info.priority, callback, ssl_pool, | 193 request_priority, callback, ssl_pool, |
190 net_log); | 194 net_log); |
191 } | 195 } |
192 | 196 |
193 // Finally, get the connection started. | 197 // Finally, get the connection started. |
194 if (proxy_info.is_http() || proxy_info.is_https()) { | 198 if (proxy_info.is_http() || proxy_info.is_https()) { |
195 HttpProxyClientSocketPool* pool = | 199 HttpProxyClientSocketPool* pool = |
196 session->GetSocketPoolForHTTPProxy(*proxy_host_port); | 200 session->GetSocketPoolForHTTPProxy(*proxy_host_port); |
197 if (num_preconnect_streams) { | 201 if (num_preconnect_streams) { |
198 RequestSocketsForPool(pool, connection_group, http_proxy_params, | 202 RequestSocketsForPool(pool, connection_group, http_proxy_params, |
199 num_preconnect_streams, net_log); | 203 num_preconnect_streams, net_log); |
200 return OK; | 204 return OK; |
201 } | 205 } |
202 | 206 |
203 return socket_handle->Init(connection_group, http_proxy_params, | 207 return socket_handle->Init(connection_group, http_proxy_params, |
204 request_info.priority, callback, | 208 request_priority, callback, |
205 pool, net_log); | 209 pool, net_log); |
206 } | 210 } |
207 | 211 |
208 if (proxy_info.is_socks()) { | 212 if (proxy_info.is_socks()) { |
209 SOCKSClientSocketPool* pool = | 213 SOCKSClientSocketPool* pool = |
210 session->GetSocketPoolForSOCKSProxy(*proxy_host_port); | 214 session->GetSocketPoolForSOCKSProxy(*proxy_host_port); |
211 if (num_preconnect_streams) { | 215 if (num_preconnect_streams) { |
212 RequestSocketsForPool(pool, connection_group, socks_params, | 216 RequestSocketsForPool(pool, connection_group, socks_params, |
213 num_preconnect_streams, net_log); | 217 num_preconnect_streams, net_log); |
214 return OK; | 218 return OK; |
215 } | 219 } |
216 | 220 |
217 return socket_handle->Init(connection_group, socks_params, | 221 return socket_handle->Init(connection_group, socks_params, |
218 request_info.priority, callback, pool, | 222 request_priority, callback, pool, |
219 net_log); | 223 net_log); |
220 } | 224 } |
221 | 225 |
222 DCHECK(proxy_info.is_direct()); | 226 DCHECK(proxy_info.is_direct()); |
223 | 227 |
224 TransportClientSocketPool* pool = session->transport_socket_pool(); | 228 TransportClientSocketPool* pool = session->transport_socket_pool(); |
225 if (num_preconnect_streams) { | 229 if (num_preconnect_streams) { |
226 RequestSocketsForPool(pool, connection_group, tcp_params, | 230 RequestSocketsForPool(pool, connection_group, tcp_params, |
227 num_preconnect_streams, net_log); | 231 num_preconnect_streams, net_log); |
228 return OK; | 232 return OK; |
229 } | 233 } |
230 | 234 |
231 return socket_handle->Init(connection_group, tcp_params, | 235 return socket_handle->Init(connection_group, tcp_params, |
232 request_info.priority, callback, | 236 request_priority, callback, |
233 pool, net_log); | 237 pool, net_log); |
234 } | 238 } |
235 | 239 |
236 } // namespace | 240 } // namespace |
237 | 241 |
238 ClientSocketPoolManager::ClientSocketPoolManager( | 242 ClientSocketPoolManager::ClientSocketPoolManager( |
239 NetLog* net_log, | 243 NetLog* net_log, |
240 ClientSocketFactory* socket_factory, | 244 ClientSocketFactory* socket_factory, |
241 HostResolver* host_resolver, | 245 HostResolver* host_resolver, |
242 CertVerifier* cert_verifier, | 246 CertVerifier* cert_verifier, |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
594 // cert. | 598 // cert. |
595 // | 599 // |
596 // Since the OnCertTrustChanged method doesn't tell us what | 600 // Since the OnCertTrustChanged method doesn't tell us what |
597 // kind of trust change it is, we have to flush the socket | 601 // kind of trust change it is, we have to flush the socket |
598 // pools to be safe. | 602 // pools to be safe. |
599 FlushSocketPools(); | 603 FlushSocketPools(); |
600 } | 604 } |
601 | 605 |
602 // static | 606 // static |
603 int ClientSocketPoolManager::InitSocketHandleForHttpRequest( | 607 int ClientSocketPoolManager::InitSocketHandleForHttpRequest( |
604 const HttpRequestInfo& request_info, | 608 const GURL& request_url, |
| 609 const GURL& request_referrer, |
| 610 const HttpRequestHeaders& request_extra_headers, |
| 611 int request_load_flags, |
| 612 RequestPriority request_priority, |
605 HttpNetworkSession* session, | 613 HttpNetworkSession* session, |
606 const ProxyInfo& proxy_info, | 614 const ProxyInfo& proxy_info, |
607 bool force_spdy_over_ssl, | 615 bool force_spdy_over_ssl, |
608 bool want_spdy_over_npn, | 616 bool want_spdy_over_npn, |
609 const SSLConfig& ssl_config_for_origin, | 617 const SSLConfig& ssl_config_for_origin, |
610 const SSLConfig& ssl_config_for_proxy, | 618 const SSLConfig& ssl_config_for_proxy, |
611 const BoundNetLog& net_log, | 619 const BoundNetLog& net_log, |
612 ClientSocketHandle* socket_handle, | 620 ClientSocketHandle* socket_handle, |
613 CompletionCallback* callback) { | 621 CompletionCallback* callback) { |
614 DCHECK(socket_handle); | 622 DCHECK(socket_handle); |
615 return InitSocketPoolHelper(request_info, | 623 return InitSocketPoolHelper(request_url, |
| 624 request_referrer, |
| 625 request_extra_headers, |
| 626 request_load_flags, |
| 627 request_priority, |
616 session, | 628 session, |
617 proxy_info, | 629 proxy_info, |
618 force_spdy_over_ssl, | 630 force_spdy_over_ssl, |
619 want_spdy_over_npn, | 631 want_spdy_over_npn, |
620 ssl_config_for_origin, | 632 ssl_config_for_origin, |
621 ssl_config_for_proxy, | 633 ssl_config_for_proxy, |
622 false, | 634 false, |
623 net_log, | 635 net_log, |
624 0, | 636 0, |
625 socket_handle, | 637 socket_handle, |
626 callback); | 638 callback); |
627 } | 639 } |
628 | 640 |
629 // static | 641 // static |
630 int ClientSocketPoolManager::InitSocketHandleForRawConnect( | 642 int ClientSocketPoolManager::InitSocketHandleForRawConnect( |
631 const HostPortPair& host_port_pair, | 643 const HostPortPair& host_port_pair, |
632 HttpNetworkSession* session, | 644 HttpNetworkSession* session, |
633 const ProxyInfo& proxy_info, | 645 const ProxyInfo& proxy_info, |
634 const SSLConfig& ssl_config_for_origin, | 646 const SSLConfig& ssl_config_for_origin, |
635 const SSLConfig& ssl_config_for_proxy, | 647 const SSLConfig& ssl_config_for_proxy, |
636 const BoundNetLog& net_log, | 648 const BoundNetLog& net_log, |
637 ClientSocketHandle* socket_handle, | 649 ClientSocketHandle* socket_handle, |
638 CompletionCallback* callback) { | 650 CompletionCallback* callback) { |
639 DCHECK(socket_handle); | 651 DCHECK(socket_handle); |
640 // Synthesize an HttpRequestInfo. | 652 // Synthesize an HttpRequestInfo. |
641 HttpRequestInfo request_info; | 653 GURL request_url = GURL("http://" + host_port_pair.ToString()); |
642 request_info.url = GURL("http://" + host_port_pair.ToString()); | 654 GURL request_referrer; |
643 return InitSocketPoolHelper(request_info, | 655 HttpRequestHeaders request_extra_headers; |
| 656 int request_load_flags = 0; |
| 657 RequestPriority request_priority = MEDIUM; |
| 658 |
| 659 return InitSocketPoolHelper(request_url, |
| 660 request_referrer, |
| 661 request_extra_headers, |
| 662 request_load_flags, |
| 663 request_priority, |
644 session, | 664 session, |
645 proxy_info, | 665 proxy_info, |
646 false, | 666 false, |
647 false, | 667 false, |
648 ssl_config_for_origin, | 668 ssl_config_for_origin, |
649 ssl_config_for_proxy, | 669 ssl_config_for_proxy, |
650 true, | 670 true, |
651 net_log, | 671 net_log, |
652 0, | 672 0, |
653 socket_handle, | 673 socket_handle, |
654 callback); | 674 callback); |
655 } | 675 } |
656 | 676 |
657 // static | 677 // static |
658 int ClientSocketPoolManager::PreconnectSocketsForHttpRequest( | 678 int ClientSocketPoolManager::PreconnectSocketsForHttpRequest( |
659 const HttpRequestInfo& request_info, | 679 const GURL& request_url, |
| 680 const GURL& request_referrer, |
| 681 const HttpRequestHeaders& request_extra_headers, |
| 682 int request_load_flags, |
| 683 RequestPriority request_priority, |
660 HttpNetworkSession* session, | 684 HttpNetworkSession* session, |
661 const ProxyInfo& proxy_info, | 685 const ProxyInfo& proxy_info, |
662 bool force_spdy_over_ssl, | 686 bool force_spdy_over_ssl, |
663 bool want_spdy_over_npn, | 687 bool want_spdy_over_npn, |
664 const SSLConfig& ssl_config_for_origin, | 688 const SSLConfig& ssl_config_for_origin, |
665 const SSLConfig& ssl_config_for_proxy, | 689 const SSLConfig& ssl_config_for_proxy, |
666 const BoundNetLog& net_log, | 690 const BoundNetLog& net_log, |
667 int num_preconnect_streams) { | 691 int num_preconnect_streams) { |
668 return InitSocketPoolHelper(request_info, | 692 return InitSocketPoolHelper(request_url, |
| 693 request_referrer, |
| 694 request_extra_headers, |
| 695 request_load_flags, |
| 696 request_priority, |
669 session, | 697 session, |
670 proxy_info, | 698 proxy_info, |
671 force_spdy_over_ssl, | 699 force_spdy_over_ssl, |
672 want_spdy_over_npn, | 700 want_spdy_over_npn, |
673 ssl_config_for_origin, | 701 ssl_config_for_origin, |
674 ssl_config_for_proxy, | 702 ssl_config_for_proxy, |
675 false, | 703 false, |
676 net_log, | 704 net_log, |
677 num_preconnect_streams, | 705 num_preconnect_streams, |
678 NULL, | 706 NULL, |
679 NULL); | 707 NULL); |
680 } | 708 } |
681 | 709 |
682 | 710 |
683 } // namespace net | 711 } // namespace net |
OLD | NEW |