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 "net/base/net_util.h" | 11 #include "net/base/net_util.h" |
12 #include "net/http/http_network_session.h" | 12 #include "net/http/http_network_session.h" |
13 #include "net/http/http_server_properties.h" | 13 #include "net/http/http_server_properties.h" |
14 #include "net/http/http_stream_factory_impl_job.h" | 14 #include "net/http/http_stream_factory_impl_job.h" |
15 #include "net/http/http_stream_factory_impl_request.h" | 15 #include "net/http/http_stream_factory_impl_request.h" |
16 #include "net/log/net_log.h" | 16 #include "net/log/net_log.h" |
17 #include "net/quic/quic_server_id.h" | 17 #include "net/quic/quic_server_id.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 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | |
Ryan Hamilton
2016/01/08 21:36:33
drive-by comment: Instead of doing #ifdefs, would
| |
22 #include "net/spdy/bidirectional_stream_spdy_job.h" | |
23 #endif | |
24 | |
21 namespace net { | 25 namespace net { |
22 | 26 |
23 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, | 27 HttpStreamFactoryImpl::HttpStreamFactoryImpl(HttpNetworkSession* session, |
24 bool for_websockets) | 28 bool for_websockets) |
25 : session_(session), | 29 : session_(session), |
26 for_websockets_(for_websockets) {} | 30 for_websockets_(for_websockets) {} |
27 | 31 |
28 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { | 32 HttpStreamFactoryImpl::~HttpStreamFactoryImpl() { |
29 DCHECK(request_map_.empty()); | 33 DCHECK(request_map_.empty()); |
30 DCHECK(spdy_session_request_map_.empty()); | 34 DCHECK(spdy_session_request_map_.empty()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 DCHECK(create_helper); | 73 DCHECK(create_helper); |
70 return RequestStreamInternal(request_info, | 74 return RequestStreamInternal(request_info, |
71 priority, | 75 priority, |
72 server_ssl_config, | 76 server_ssl_config, |
73 proxy_ssl_config, | 77 proxy_ssl_config, |
74 delegate, | 78 delegate, |
75 create_helper, | 79 create_helper, |
76 net_log); | 80 net_log); |
77 } | 81 } |
78 | 82 |
83 HttpStreamRequest* HttpStreamFactoryImpl::RequestBidirectionalStreamJob( | |
84 const HttpRequestInfo& request_info, | |
85 RequestPriority priority, | |
86 const SSLConfig& server_ssl_config, | |
87 const SSLConfig& proxy_ssl_config, | |
88 HttpStreamRequest::Delegate* delegate, | |
89 const BoundNetLog& net_log) { | |
90 DCHECK(!for_websockets_); | |
91 DCHECK(request_info.url.SchemeIs(url::kHttpsScheme)); | |
92 | |
93 // TODO(xunjieli): Create QUIC's version of BidirectionalStreamJob. | |
94 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | |
95 Request* request = | |
96 new Request(request_info.url, this, delegate, nullptr, net_log, | |
97 Request::BIDIRECTIONAL_STREAM_SPDY_JOB); | |
98 Job* job = new Job(this, session_, request_info, priority, server_ssl_config, | |
99 proxy_ssl_config, net_log.net_log()); | |
100 request->AttachJob(job); | |
101 | |
102 job->Start(request); | |
103 return request; | |
104 | |
105 #else | |
106 DCHECK(false); | |
107 return nullptr; | |
108 #endif | |
109 } | |
110 | |
79 HttpStreamRequest* HttpStreamFactoryImpl::RequestStreamInternal( | 111 HttpStreamRequest* HttpStreamFactoryImpl::RequestStreamInternal( |
80 const HttpRequestInfo& request_info, | 112 const HttpRequestInfo& request_info, |
81 RequestPriority priority, | 113 RequestPriority priority, |
82 const SSLConfig& server_ssl_config, | 114 const SSLConfig& server_ssl_config, |
83 const SSLConfig& proxy_ssl_config, | 115 const SSLConfig& proxy_ssl_config, |
84 HttpStreamRequest::Delegate* delegate, | 116 HttpStreamRequest::Delegate* delegate, |
85 WebSocketHandshakeStreamBase::CreateHelper* | 117 WebSocketHandshakeStreamBase::CreateHelper* |
86 websocket_handshake_stream_create_helper, | 118 websocket_handshake_stream_create_helper, |
87 const BoundNetLog& net_log) { | 119 const BoundNetLog& net_log) { |
88 Request* request = new Request(request_info.url, | 120 Request* request = new Request(request_info.url, this, delegate, |
89 this, | |
90 delegate, | |
91 websocket_handshake_stream_create_helper, | 121 websocket_handshake_stream_create_helper, |
92 net_log); | 122 net_log, Request::HTTP_STREAM); |
93 Job* job = new Job(this, session_, request_info, priority, server_ssl_config, | 123 Job* job = new Job(this, session_, request_info, priority, server_ssl_config, |
94 proxy_ssl_config, net_log.net_log()); | 124 proxy_ssl_config, net_log.net_log()); |
95 request->AttachJob(job); | 125 request->AttachJob(job); |
96 | 126 |
97 const AlternativeServiceVector alternative_service_vector = | 127 const AlternativeServiceVector alternative_service_vector = |
98 GetAlternativeServicesFor(request_info.url, delegate); | 128 GetAlternativeServicesFor(request_info.url, delegate); |
99 | 129 |
100 if (!alternative_service_vector.empty()) { | 130 if (!alternative_service_vector.empty()) { |
101 // TODO(bnc): Pass on multiple alternative services to Job. | 131 // TODO(bnc): Pass on multiple alternative services to Job. |
102 const AlternativeService& alternative_service = | 132 const AlternativeService& alternative_service = |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
268 // queue (Order by priority first, then FIFO within same priority). Unclear | 298 // queue (Order by priority first, then FIFO within same priority). Unclear |
269 // that it matters here. | 299 // that it matters here. |
270 if (!ContainsKey(spdy_session_request_map_, spdy_session_key)) | 300 if (!ContainsKey(spdy_session_request_map_, spdy_session_key)) |
271 break; | 301 break; |
272 Request* request = *spdy_session_request_map_[spdy_session_key].begin(); | 302 Request* request = *spdy_session_request_map_[spdy_session_key].begin(); |
273 request->Complete(was_npn_negotiated, protocol_negotiated, using_spdy); | 303 request->Complete(was_npn_negotiated, protocol_negotiated, using_spdy); |
274 if (for_websockets_) { | 304 if (for_websockets_) { |
275 // TODO(ricea): Restore this code path when WebSocket over SPDY | 305 // TODO(ricea): Restore this code path when WebSocket over SPDY |
276 // implementation is ready. | 306 // implementation is ready. |
277 NOTREACHED(); | 307 NOTREACHED(); |
308 } else if (request->for_bidirectional()) { | |
309 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | |
310 request->OnBidirectionalStreamJobReady( | |
311 nullptr, used_ssl_config, used_proxy_info, | |
312 new BidirectionalStreamSpdyJob(spdy_session)); | |
313 #else | |
314 DCHECK(false); | |
315 #endif | |
278 } else { | 316 } else { |
279 bool use_relative_url = direct || request->url().SchemeIs("https"); | 317 bool use_relative_url = direct || request->url().SchemeIs("https"); |
280 request->OnStreamReady( | 318 request->OnStreamReady( |
281 NULL, | 319 nullptr, used_ssl_config, used_proxy_info, |
282 used_ssl_config, | |
283 used_proxy_info, | |
284 new SpdyHttpStream(spdy_session, use_relative_url)); | 320 new SpdyHttpStream(spdy_session, use_relative_url)); |
285 } | 321 } |
286 } | 322 } |
287 // TODO(mbelshe): Alert other valid requests. | 323 // TODO(mbelshe): Alert other valid requests. |
288 } | 324 } |
289 | 325 |
290 void HttpStreamFactoryImpl::OnOrphanedJobComplete(const Job* job) { | 326 void HttpStreamFactoryImpl::OnOrphanedJobComplete(const Job* job) { |
291 orphaned_job_set_.erase(job); | 327 orphaned_job_set_.erase(job); |
292 delete job; | 328 delete job; |
293 } | 329 } |
294 | 330 |
295 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { | 331 void HttpStreamFactoryImpl::OnPreconnectsComplete(const Job* job) { |
296 preconnect_job_set_.erase(job); | 332 preconnect_job_set_.erase(job); |
297 delete job; | 333 delete job; |
298 OnPreconnectsCompleteInternal(); | 334 OnPreconnectsCompleteInternal(); |
299 } | 335 } |
300 | 336 |
301 } // namespace net | 337 } // namespace net |
OLD | NEW |