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_request.h" | 5 #include "net/http/http_stream_factory_impl_request.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "net/http/bidirectional_stream.h" | |
10 #include "net/http/http_stream_factory_impl_job.h" | 11 #include "net/http/http_stream_factory_impl_job.h" |
11 #include "net/spdy/spdy_http_stream.h" | 12 #include "net/spdy/spdy_http_stream.h" |
12 #include "net/spdy/spdy_session.h" | 13 #include "net/spdy/spdy_session.h" |
13 | 14 |
14 namespace net { | 15 namespace net { |
15 | 16 |
16 HttpStreamFactoryImpl::Request::Request( | 17 HttpStreamFactoryImpl::Request::Request( |
17 const GURL& url, | 18 const GURL& url, |
18 HttpStreamFactoryImpl* factory, | 19 HttpStreamFactoryImpl* factory, |
19 HttpStreamRequest::Delegate* delegate, | 20 HttpStreamRequest::Delegate* delegate, |
20 WebSocketHandshakeStreamBase::CreateHelper* | 21 WebSocketHandshakeStreamBase::CreateHelper* |
21 websocket_handshake_stream_create_helper, | 22 websocket_handshake_stream_create_helper, |
22 const BoundNetLog& net_log) | 23 const BoundNetLog& net_log) |
24 : Request(url, | |
25 factory, | |
26 delegate, | |
27 websocket_handshake_stream_create_helper, | |
28 net_log, | |
29 false) {} | |
30 | |
31 HttpStreamFactoryImpl::Request::Request( | |
mef
2015/09/30 16:18:16
why do we need to duplicate constructors? Can we a
xunjieli
2015/10/01 18:41:16
Done.
| |
32 const GURL& url, | |
33 HttpStreamFactoryImpl* factory, | |
34 HttpStreamRequest::Delegate* delegate, | |
35 WebSocketHandshakeStreamBase::CreateHelper* | |
36 websocket_handshake_stream_create_helper, | |
37 const BoundNetLog& net_log, | |
38 bool for_bidirectional) | |
23 : url_(url), | 39 : url_(url), |
24 factory_(factory), | 40 factory_(factory), |
25 websocket_handshake_stream_create_helper_( | 41 websocket_handshake_stream_create_helper_( |
26 websocket_handshake_stream_create_helper), | 42 websocket_handshake_stream_create_helper), |
27 delegate_(delegate), | 43 delegate_(delegate), |
28 net_log_(net_log), | 44 net_log_(net_log), |
29 completed_(false), | 45 completed_(false), |
30 was_npn_negotiated_(false), | 46 was_npn_negotiated_(false), |
31 protocol_negotiated_(kProtoUnknown), | 47 protocol_negotiated_(kProtoUnknown), |
32 using_spdy_(false) { | 48 using_spdy_(false), |
49 for_bidirectional_(for_bidirectional) { | |
33 DCHECK(factory_); | 50 DCHECK(factory_); |
34 DCHECK(delegate_); | 51 DCHECK(delegate_); |
35 | 52 |
36 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); | 53 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); |
37 } | 54 } |
38 | 55 |
39 HttpStreamFactoryImpl::Request::~Request() { | 56 HttpStreamFactoryImpl::Request::~Request() { |
40 if (bound_job_.get()) | 57 if (bound_job_.get()) |
41 DCHECK(jobs_.empty()); | 58 DCHECK(jobs_.empty()); |
42 | 59 |
(...skipping 27 matching lines...) Expand all Loading... | |
70 protocol_negotiated_ = protocol_negotiated; | 87 protocol_negotiated_ = protocol_negotiated; |
71 using_spdy_ = using_spdy; | 88 using_spdy_ = using_spdy; |
72 } | 89 } |
73 | 90 |
74 void HttpStreamFactoryImpl::Request::OnStreamReady( | 91 void HttpStreamFactoryImpl::Request::OnStreamReady( |
75 Job* job, | 92 Job* job, |
76 const SSLConfig& used_ssl_config, | 93 const SSLConfig& used_ssl_config, |
77 const ProxyInfo& used_proxy_info, | 94 const ProxyInfo& used_proxy_info, |
78 HttpStream* stream) { | 95 HttpStream* stream) { |
79 DCHECK(!factory_->for_websockets_); | 96 DCHECK(!factory_->for_websockets_); |
97 DCHECK(!for_bidirectional_); | |
80 DCHECK(stream); | 98 DCHECK(stream); |
81 DCHECK(completed_); | 99 DCHECK(completed_); |
82 | 100 |
83 OnJobSucceeded(job); | 101 OnJobSucceeded(job); |
84 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); | 102 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); |
85 } | 103 } |
86 | 104 |
105 void HttpStreamFactoryImpl::Request::OnBidirectionalStreamReady( | |
106 Job* job, | |
107 const SSLConfig& used_ssl_config, | |
108 const ProxyInfo& used_proxy_info, | |
109 BidirectionalStream* stream) { | |
110 DCHECK(!factory_->for_websockets_); | |
111 DCHECK(for_bidirectional_); | |
112 DCHECK(stream); | |
113 DCHECK(completed_); | |
114 | |
115 OnJobSucceeded(job); | |
116 delegate_->OnBidirectionalStreamReady(used_ssl_config, used_proxy_info, | |
117 stream); | |
118 } | |
119 | |
87 void HttpStreamFactoryImpl::Request::OnWebSocketHandshakeStreamReady( | 120 void HttpStreamFactoryImpl::Request::OnWebSocketHandshakeStreamReady( |
88 Job* job, | 121 Job* job, |
89 const SSLConfig& used_ssl_config, | 122 const SSLConfig& used_ssl_config, |
90 const ProxyInfo& used_proxy_info, | 123 const ProxyInfo& used_proxy_info, |
91 WebSocketHandshakeStreamBase* stream) { | 124 WebSocketHandshakeStreamBase* stream) { |
92 DCHECK(factory_->for_websockets_); | 125 DCHECK(factory_->for_websockets_); |
126 DCHECK(!for_bidirectional_); | |
93 DCHECK(stream); | 127 DCHECK(stream); |
94 DCHECK(completed_); | 128 DCHECK(completed_); |
95 | 129 |
96 OnJobSucceeded(job); | 130 OnJobSucceeded(job); |
97 delegate_->OnWebSocketHandshakeStreamReady( | 131 delegate_->OnWebSocketHandshakeStreamReady( |
98 used_ssl_config, used_proxy_info, stream); | 132 used_ssl_config, used_proxy_info, stream); |
99 } | 133 } |
100 | 134 |
101 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 135 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
102 Job* job, | 136 Job* job, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 // TODO(jgraettinger): Currently, HttpStreamFactoryImpl::Job notifies a | 279 // TODO(jgraettinger): Currently, HttpStreamFactoryImpl::Job notifies a |
246 // Request that the session is ready, which in turn notifies it's delegate, | 280 // Request that the session is ready, which in turn notifies it's delegate, |
247 // and then it notifies HttpStreamFactoryImpl so that /other/ requests may | 281 // and then it notifies HttpStreamFactoryImpl so that /other/ requests may |
248 // be woken, but only if the spdy_session is still okay. This is tough to grok. | 282 // be woken, but only if the spdy_session is still okay. This is tough to grok. |
249 // Instead, see if Job can notify HttpStreamFactoryImpl only, and have one | 283 // Instead, see if Job can notify HttpStreamFactoryImpl only, and have one |
250 // path for notifying any requests waiting for the session (including the | 284 // path for notifying any requests waiting for the session (including the |
251 // request which spawned it). | 285 // request which spawned it). |
252 void HttpStreamFactoryImpl::Request::OnNewSpdySessionReady( | 286 void HttpStreamFactoryImpl::Request::OnNewSpdySessionReady( |
253 Job* job, | 287 Job* job, |
254 scoped_ptr<HttpStream> stream, | 288 scoped_ptr<HttpStream> stream, |
289 scoped_ptr<BidirectionalStream> bidirectional_stream, | |
255 const base::WeakPtr<SpdySession>& spdy_session, | 290 const base::WeakPtr<SpdySession>& spdy_session, |
256 bool direct) { | 291 bool direct) { |
257 DCHECK(job); | 292 DCHECK(job); |
258 DCHECK(job->using_spdy()); | 293 DCHECK(job->using_spdy()); |
259 | 294 |
260 // Note: |spdy_session| may be NULL. In that case, |delegate_| should still | 295 // Note: |spdy_session| may be NULL. In that case, |delegate_| should still |
261 // receive |stream| so the error propogates up correctly, however there is no | 296 // receive |stream| so the error propogates up correctly, however there is no |
262 // point in broadcasting |spdy_session| to other requests. | 297 // point in broadcasting |spdy_session| to other requests. |
263 | 298 |
264 // The first case is the usual case. | 299 // The first case is the usual case. |
(...skipping 14 matching lines...) Expand all Loading... | |
279 const BoundNetLog net_log = job->net_log(); | 314 const BoundNetLog net_log = job->net_log(); |
280 | 315 |
281 Complete(was_npn_negotiated, protocol_negotiated, using_spdy); | 316 Complete(was_npn_negotiated, protocol_negotiated, using_spdy); |
282 | 317 |
283 // Cache this so we can still use it if the request is deleted. | 318 // Cache this so we can still use it if the request is deleted. |
284 HttpStreamFactoryImpl* factory = factory_; | 319 HttpStreamFactoryImpl* factory = factory_; |
285 if (factory->for_websockets_) { | 320 if (factory->for_websockets_) { |
286 // TODO(ricea): Re-instate this code when WebSockets over SPDY is | 321 // TODO(ricea): Re-instate this code when WebSockets over SPDY is |
287 // implemented. | 322 // implemented. |
288 NOTREACHED(); | 323 NOTREACHED(); |
324 } else if (for_bidirectional_) { | |
mef
2015/09/30 16:18:16
Does this only work for new spdy session?
xunjieli
2015/10/01 18:41:16
It also works for existing spdy session if HttpStr
| |
325 delegate_->OnBidirectionalStreamReady(job->server_ssl_config(), | |
326 job->proxy_info(), | |
327 bidirectional_stream.release()); | |
289 } else { | 328 } else { |
290 delegate_->OnStreamReady(job->server_ssl_config(), job->proxy_info(), | 329 delegate_->OnStreamReady(job->server_ssl_config(), job->proxy_info(), |
291 stream.release()); | 330 stream.release()); |
292 } | 331 } |
293 // |this| may be deleted after this point. | 332 // |this| may be deleted after this point. |
294 if (spdy_session && spdy_session->IsAvailable()) { | 333 if (spdy_session && spdy_session->IsAvailable()) { |
295 factory->OnNewSpdySessionReady(spdy_session, | 334 factory->OnNewSpdySessionReady(spdy_session, |
296 direct, | 335 direct, |
297 used_ssl_config, | 336 used_ssl_config, |
298 used_proxy_info, | 337 used_proxy_info, |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 } | 414 } |
376 // We may have other jobs in |jobs_|. For example, if we start multiple jobs | 415 // We may have other jobs in |jobs_|. For example, if we start multiple jobs |
377 // for Alternate-Protocol. | 416 // for Alternate-Protocol. |
378 BindJob(job); | 417 BindJob(job); |
379 return; | 418 return; |
380 } | 419 } |
381 DCHECK(jobs_.empty()); | 420 DCHECK(jobs_.empty()); |
382 } | 421 } |
383 | 422 |
384 } // namespace net | 423 } // namespace net |
OLD | NEW |