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/http/http_stream_factory_impl.h" | 5 #include "net/http/http_stream_factory_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/metrics/field_trial.h" | |
12 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
13 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
14 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
15 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
16 #include "net/http/http_server_properties.h" | 15 #include "net/http/http_server_properties.h" |
17 #include "net/http/http_stream_factory_impl_job.h" | 16 #include "net/http/http_stream_factory_impl_job.h" |
18 #include "net/http/http_stream_factory_impl_job_controller.h" | 17 #include "net/http/http_stream_factory_impl_job_controller.h" |
19 #include "net/http/http_stream_factory_impl_request.h" | 18 #include "net/http/http_stream_factory_impl_request.h" |
20 #include "net/http/transport_security_state.h" | 19 #include "net/http/transport_security_state.h" |
21 #include "net/proxy/proxy_info.h" | 20 #include "net/proxy/proxy_info.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 GURL origin_url, | 81 GURL origin_url, |
83 const ProxyServer& alternative_proxy_server, | 82 const ProxyServer& alternative_proxy_server, |
84 NetLog* net_log) override { | 83 NetLog* net_log) override { |
85 return new HttpStreamFactoryImpl::Job( | 84 return new HttpStreamFactoryImpl::Job( |
86 delegate, job_type, session, request_info, priority, server_ssl_config, | 85 delegate, job_type, session, request_info, priority, server_ssl_config, |
87 proxy_ssl_config, destination, origin_url, AlternativeService(), | 86 proxy_ssl_config, destination, origin_url, AlternativeService(), |
88 alternative_proxy_server, net_log); | 87 alternative_proxy_server, net_log); |
89 } | 88 } |
90 }; | 89 }; |
91 | 90 |
92 // Returns true if only one preconnect to proxy servers is allowed via field | |
93 // trial. | |
94 bool AllowOnlyOnePreconnectToProxyServers() { | |
95 return base::StartsWith(base::FieldTrialList::FindFullName( | |
96 "NetAllowOnlyOnePreconnectToProxyServers"), | |
97 "Enabled", base::CompareCase::INSENSITIVE_ASCII); | |
98 } | |
99 | |
100 } // anonymous namespace | 91 } // anonymous namespace |
101 | 92 |
102 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, | 93 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, |
103 bool for_websockets) | 94 bool for_websockets) |
104 : session_(session), | 95 : session_(session), |
105 job_factory_(new DefaultJobFactory()), | 96 job_factory_(new DefaultJobFactory()), |
106 for_websockets_(for_websockets), | 97 for_websockets_(for_websockets) {} |
107 allow_only_one_preconnect_to_proxy_servers_( | |
108 AllowOnlyOnePreconnectToProxyServers()) {} | |
109 | 98 |
110 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { | 99 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { |
111 DCHECK(request_map_.empty()); | 100 DCHECK(request_map_.empty()); |
112 DCHECK(spdy_session_request_map_.empty()); | 101 DCHECK(spdy_session_request_map_.empty()); |
113 } | 102 } |
114 | 103 |
115 HttpStreamRequest* HttpStreamFactoryImpl::RequestStream( | 104 HttpStreamRequest* HttpStreamFactoryImpl::RequestStream( |
116 const HttpRequestInfo& request_info, | 105 const HttpRequestInfo& request_info, |
117 RequestPriority priority, | 106 RequestPriority priority, |
118 const SSLConfig& server_ssl_config, | 107 const SSLConfig& server_ssl_config, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 NOTREACHED(); | 243 NOTREACHED(); |
255 } | 244 } |
256 | 245 |
257 bool HttpStreamFactoryImpl::OnInitConnection(const JobController& controller, | 246 bool HttpStreamFactoryImpl::OnInitConnection(const JobController& controller, |
258 const ProxyInfo& proxy_info) { | 247 const ProxyInfo& proxy_info) { |
259 if (!controller.is_preconnect()) { | 248 if (!controller.is_preconnect()) { |
260 // Connection initialization can be skipped only for the preconnect jobs. | 249 // Connection initialization can be skipped only for the preconnect jobs. |
261 return false; | 250 return false; |
262 } | 251 } |
263 | 252 |
264 if (!allow_only_one_preconnect_to_proxy_servers_ || | 253 if (!session_->params().restrict_to_one_preconnect_for_proxies || |
265 !ProxyServerSupportsPriorities(proxy_info)) { | 254 !ProxyServerSupportsPriorities(proxy_info)) { |
266 return false; | 255 return false; |
267 } | 256 } |
268 | 257 |
269 if (base::ContainsKey(preconnecting_proxy_servers_, | 258 if (base::ContainsKey(preconnecting_proxy_servers_, |
270 proxy_info.proxy_server())) { | 259 proxy_info.proxy_server())) { |
271 UMA_HISTOGRAM_EXACT_LINEAR("Net.PreconnectSkippedToProxyServers", 1, 2); | 260 UMA_HISTOGRAM_EXACT_LINEAR("Net.PreconnectSkippedToProxyServers", 1, 2); |
272 // Skip preconnect to the proxy server since we are already preconnecting | 261 // Skip preconnect to the proxy server since we are already preconnecting |
273 // (probably via some other job). | 262 // (probably via some other job). |
274 return true; | 263 return true; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 DCHECK(!host_port_pair.IsEmpty()); | 296 DCHECK(!host_port_pair.IsEmpty()); |
308 | 297 |
309 url::SchemeHostPort scheme_host_port("https", host_port_pair.host(), | 298 url::SchemeHostPort scheme_host_port("https", host_port_pair.host(), |
310 host_port_pair.port()); | 299 host_port_pair.port()); |
311 | 300 |
312 return session_->http_server_properties()->SupportsRequestPriority( | 301 return session_->http_server_properties()->SupportsRequestPriority( |
313 scheme_host_port); | 302 scheme_host_port); |
314 } | 303 } |
315 | 304 |
316 } // namespace net | 305 } // namespace net |
OLD | NEW |