Chromium Code Reviews| 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/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "net/base/net_log.h" | 12 #include "net/base/net_log.h" |
| 13 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
| 14 #include "net/http/http_network_session.h" | 14 #include "net/http/http_network_session.h" |
| 15 #include "net/http/http_server_properties.h" | 15 #include "net/http/http_server_properties.h" |
| 16 #include "net/http/http_stream_factory_impl_job.h" | 16 #include "net/http/http_stream_factory_impl_job.h" |
| 17 #include "net/http/http_stream_factory_impl_request.h" | 17 #include "net/http/http_stream_factory_impl_request.h" |
| 18 #include "net/spdy/spdy_http_stream.h" | 18 #include "net/spdy/spdy_http_stream.h" |
| 19 #include "url/gurl.h" | 19 #include "url/gurl.h" |
| 20 | 20 |
| 21 namespace net { | 21 namespace net { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 const PortAlternateProtocolPair kNoAlternateProtocol = { | 25 const AlternateProtocolInfo kNoAlternateProtocol = |
| 26 0, UNINITIALIZED_ALTERNATE_PROTOCOL | 26 AlternateProtocolInfo(0, UNINITIALIZED_ALTERNATE_PROTOCOL, 0); |
|
jamesr
2014/07/08 19:36:38
this creates a static initializer
Ryan Hamilton
2014/07/08 19:59:51
Ugh! Yes, it does :< Sorry about that.
Fixed.
| |
| 27 }; | |
| 28 | 27 |
| 29 GURL UpgradeUrlToHttps(const GURL& original_url, int port) { | 28 GURL UpgradeUrlToHttps(const GURL& original_url, int port) { |
| 30 GURL::Replacements replacements; | 29 GURL::Replacements replacements; |
| 31 // new_sheme and new_port need to be in scope here because GURL::Replacements | 30 // new_sheme and new_port need to be in scope here because GURL::Replacements |
| 32 // references the memory contained by them directly. | 31 // references the memory contained by them directly. |
| 33 const std::string new_scheme = "https"; | 32 const std::string new_scheme = "https"; |
| 34 const std::string new_port = base::IntToString(port); | 33 const std::string new_port = base::IntToString(port); |
| 35 replacements.SetSchemeStr(new_scheme); | 34 replacements.SetSchemeStr(new_scheme); |
| 36 replacements.SetPortStr(new_port); | 35 replacements.SetPortStr(new_port); |
| 37 return original_url.ReplaceComponents(replacements); | 36 return original_url.ReplaceComponents(replacements); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 WebSocketHandshakeStreamBase::CreateHelper* | 103 WebSocketHandshakeStreamBase::CreateHelper* |
| 105 websocket_handshake_stream_create_helper, | 104 websocket_handshake_stream_create_helper, |
| 106 const BoundNetLog& net_log) { | 105 const BoundNetLog& net_log) { |
| 107 Request* request = new Request(request_info.url, | 106 Request* request = new Request(request_info.url, |
| 108 this, | 107 this, |
| 109 delegate, | 108 delegate, |
| 110 websocket_handshake_stream_create_helper, | 109 websocket_handshake_stream_create_helper, |
| 111 net_log); | 110 net_log); |
| 112 | 111 |
| 113 GURL alternate_url; | 112 GURL alternate_url; |
| 114 PortAlternateProtocolPair alternate = | 113 AlternateProtocolInfo alternate = |
| 115 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); | 114 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); |
| 116 Job* alternate_job = NULL; | 115 Job* alternate_job = NULL; |
| 117 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 116 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 118 // Never share connection with other jobs for FTP requests. | 117 // Never share connection with other jobs for FTP requests. |
| 119 DCHECK(!request_info.url.SchemeIs("ftp")); | 118 DCHECK(!request_info.url.SchemeIs("ftp")); |
| 120 | 119 |
| 121 HttpRequestInfo alternate_request_info = request_info; | 120 HttpRequestInfo alternate_request_info = request_info; |
| 122 alternate_request_info.url = alternate_url; | 121 alternate_request_info.url = alternate_url; |
| 123 alternate_job = | 122 alternate_job = |
| 124 new Job(this, session_, alternate_request_info, priority, | 123 new Job(this, session_, alternate_request_info, priority, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 148 } | 147 } |
| 149 | 148 |
| 150 void HttpStreamFactoryImpl::PreconnectStreams( | 149 void HttpStreamFactoryImpl::PreconnectStreams( |
| 151 int num_streams, | 150 int num_streams, |
| 152 const HttpRequestInfo& request_info, | 151 const HttpRequestInfo& request_info, |
| 153 RequestPriority priority, | 152 RequestPriority priority, |
| 154 const SSLConfig& server_ssl_config, | 153 const SSLConfig& server_ssl_config, |
| 155 const SSLConfig& proxy_ssl_config) { | 154 const SSLConfig& proxy_ssl_config) { |
| 156 DCHECK(!for_websockets_); | 155 DCHECK(!for_websockets_); |
| 157 GURL alternate_url; | 156 GURL alternate_url; |
| 158 PortAlternateProtocolPair alternate = | 157 AlternateProtocolInfo alternate = |
| 159 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); | 158 GetAlternateProtocolRequestFor(request_info.url, &alternate_url); |
| 160 Job* job = NULL; | 159 Job* job = NULL; |
| 161 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { | 160 if (alternate.protocol != UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 162 HttpRequestInfo alternate_request_info = request_info; | 161 HttpRequestInfo alternate_request_info = request_info; |
| 163 alternate_request_info.url = alternate_url; | 162 alternate_request_info.url = alternate_url; |
| 164 job = new Job(this, session_, alternate_request_info, priority, | 163 job = new Job(this, session_, alternate_request_info, priority, |
| 165 server_ssl_config, proxy_ssl_config, session_->net_log()); | 164 server_ssl_config, proxy_ssl_config, session_->net_log()); |
| 166 job->MarkAsAlternate(request_info.url, alternate); | 165 job->MarkAsAlternate(request_info.url, alternate); |
| 167 } else { | 166 } else { |
| 168 job = new Job(this, session_, request_info, priority, | 167 job = new Job(this, session_, request_info, priority, |
| 169 server_ssl_config, proxy_ssl_config, session_->net_log()); | 168 server_ssl_config, proxy_ssl_config, session_->net_log()); |
| 170 } | 169 } |
| 171 preconnect_job_set_.insert(job); | 170 preconnect_job_set_.insert(job); |
| 172 job->Preconnect(num_streams); | 171 job->Preconnect(num_streams); |
| 173 } | 172 } |
| 174 | 173 |
| 175 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { | 174 const HostMappingRules* HttpStreamFactoryImpl::GetHostMappingRules() const { |
| 176 return session_->params().host_mapping_rules; | 175 return session_->params().host_mapping_rules; |
| 177 } | 176 } |
| 178 | 177 |
| 179 PortAlternateProtocolPair HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( | 178 AlternateProtocolInfo HttpStreamFactoryImpl::GetAlternateProtocolRequestFor( |
| 180 const GURL& original_url, | 179 const GURL& original_url, |
| 181 GURL* alternate_url) { | 180 GURL* alternate_url) { |
| 182 if (!session_->params().use_alternate_protocols) | 181 if (!session_->params().use_alternate_protocols) |
| 183 return kNoAlternateProtocol; | 182 return kNoAlternateProtocol; |
| 184 | 183 |
| 185 if (original_url.SchemeIs("ftp")) | 184 if (original_url.SchemeIs("ftp")) |
| 186 return kNoAlternateProtocol; | 185 return kNoAlternateProtocol; |
| 187 | 186 |
| 188 HostPortPair origin = HostPortPair(original_url.HostNoBrackets(), | 187 HostPortPair origin = HostPortPair(original_url.HostNoBrackets(), |
| 189 original_url.EffectiveIntPort()); | 188 original_url.EffectiveIntPort()); |
| 190 | 189 |
| 191 HttpServerProperties& http_server_properties = | 190 HttpServerProperties& http_server_properties = |
| 192 *session_->http_server_properties(); | 191 *session_->http_server_properties(); |
| 193 if (!http_server_properties.HasAlternateProtocol(origin)) | 192 if (!http_server_properties.HasAlternateProtocol(origin)) |
| 194 return kNoAlternateProtocol; | 193 return kNoAlternateProtocol; |
| 195 | 194 |
| 196 PortAlternateProtocolPair alternate = | 195 AlternateProtocolInfo alternate = |
| 197 http_server_properties.GetAlternateProtocol(origin); | 196 http_server_properties.GetAlternateProtocol(origin); |
| 198 if (alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) { | 197 if (alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) { |
| 199 HistogramAlternateProtocolUsage( | 198 HistogramAlternateProtocolUsage( |
| 200 ALTERNATE_PROTOCOL_USAGE_BROKEN, | 199 ALTERNATE_PROTOCOL_USAGE_BROKEN, |
| 201 http_server_properties.GetAlternateProtocolExperiment()); | 200 http_server_properties.GetAlternateProtocolExperiment()); |
| 202 return kNoAlternateProtocol; | 201 return kNoAlternateProtocol; |
| 203 } | 202 } |
| 204 | 203 |
| 205 if (!IsAlternateProtocolValid(alternate.protocol)) { | 204 if (!IsAlternateProtocolValid(alternate.protocol)) { |
| 206 NOTREACHED(); | 205 NOTREACHED(); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 302 delete job; | 301 delete job; |
| 303 } | 302 } |
| 304 | 303 |
| 305 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 304 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
| 306 preconnect_job_set_.erase(job); | 305 preconnect_job_set_.erase(job); |
| 307 delete job; | 306 delete job; |
| 308 OnPreconnectsCompleteInternal(); | 307 OnPreconnectsCompleteInternal(); |
| 309 } | 308 } |
| 310 | 309 |
| 311 } // namespace net | 310 } // namespace net |
| OLD | NEW |