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_job.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 StreamType stream_type) |
23 : url_(url), | 25 : url_(url), |
24 factory_(factory), | 26 factory_(factory), |
25 websocket_handshake_stream_create_helper_( | 27 websocket_handshake_stream_create_helper_( |
26 websocket_handshake_stream_create_helper), | 28 websocket_handshake_stream_create_helper), |
27 delegate_(delegate), | 29 delegate_(delegate), |
28 net_log_(net_log), | 30 net_log_(net_log), |
29 completed_(false), | 31 completed_(false), |
30 was_npn_negotiated_(false), | 32 was_npn_negotiated_(false), |
31 protocol_negotiated_(kProtoUnknown), | 33 protocol_negotiated_(kProtoUnknown), |
32 using_spdy_(false) { | 34 using_spdy_(false), |
| 35 for_bidirectional_(stream_type == BIDIRECTIONAL_STREAM_SPDY_JOB) { |
33 DCHECK(factory_); | 36 DCHECK(factory_); |
34 DCHECK(delegate_); | 37 DCHECK(delegate_); |
35 | 38 |
36 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); | 39 net_log_.BeginEvent(NetLog::TYPE_HTTP_STREAM_REQUEST); |
37 } | 40 } |
38 | 41 |
39 HttpStreamFactoryImpl::Request::~Request() { | 42 HttpStreamFactoryImpl::Request::~Request() { |
40 if (bound_job_.get()) | 43 if (bound_job_.get()) |
41 DCHECK(jobs_.empty()); | 44 DCHECK(jobs_.empty()); |
42 | 45 |
(...skipping 27 matching lines...) Expand all Loading... |
70 protocol_negotiated_ = protocol_negotiated; | 73 protocol_negotiated_ = protocol_negotiated; |
71 using_spdy_ = using_spdy; | 74 using_spdy_ = using_spdy; |
72 } | 75 } |
73 | 76 |
74 void HttpStreamFactoryImpl::Request::OnStreamReady( | 77 void HttpStreamFactoryImpl::Request::OnStreamReady( |
75 Job* job, | 78 Job* job, |
76 const SSLConfig& used_ssl_config, | 79 const SSLConfig& used_ssl_config, |
77 const ProxyInfo& used_proxy_info, | 80 const ProxyInfo& used_proxy_info, |
78 HttpStream* stream) { | 81 HttpStream* stream) { |
79 DCHECK(!factory_->for_websockets_); | 82 DCHECK(!factory_->for_websockets_); |
| 83 DCHECK(!for_bidirectional_); |
80 DCHECK(stream); | 84 DCHECK(stream); |
81 DCHECK(completed_); | 85 DCHECK(completed_); |
82 | 86 |
83 OnJobSucceeded(job); | 87 OnJobSucceeded(job); |
84 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); | 88 delegate_->OnStreamReady(used_ssl_config, used_proxy_info, stream); |
85 } | 89 } |
86 | 90 |
| 91 void HttpStreamFactoryImpl::Request::OnBidirectionalStreamJobReady( |
| 92 Job* job, |
| 93 const SSLConfig& used_ssl_config, |
| 94 const ProxyInfo& used_proxy_info, |
| 95 BidirectionalStreamJob* stream_job) { |
| 96 DCHECK(!factory_->for_websockets_); |
| 97 DCHECK(for_bidirectional_); |
| 98 DCHECK(stream_job); |
| 99 DCHECK(completed_); |
| 100 |
| 101 OnJobSucceeded(job); |
| 102 delegate_->OnBidirectionalStreamJobReady(used_ssl_config, used_proxy_info, |
| 103 stream_job); |
| 104 } |
| 105 |
87 void HttpStreamFactoryImpl::Request::OnWebSocketHandshakeStreamReady( | 106 void HttpStreamFactoryImpl::Request::OnWebSocketHandshakeStreamReady( |
88 Job* job, | 107 Job* job, |
89 const SSLConfig& used_ssl_config, | 108 const SSLConfig& used_ssl_config, |
90 const ProxyInfo& used_proxy_info, | 109 const ProxyInfo& used_proxy_info, |
91 WebSocketHandshakeStreamBase* stream) { | 110 WebSocketHandshakeStreamBase* stream) { |
92 DCHECK(factory_->for_websockets_); | 111 DCHECK(factory_->for_websockets_); |
| 112 DCHECK(!for_bidirectional_); |
93 DCHECK(stream); | 113 DCHECK(stream); |
94 DCHECK(completed_); | 114 DCHECK(completed_); |
95 | 115 |
96 OnJobSucceeded(job); | 116 OnJobSucceeded(job); |
97 delegate_->OnWebSocketHandshakeStreamReady( | 117 delegate_->OnWebSocketHandshakeStreamReady( |
98 used_ssl_config, used_proxy_info, stream); | 118 used_ssl_config, used_proxy_info, stream); |
99 } | 119 } |
100 | 120 |
101 void HttpStreamFactoryImpl::Request::OnStreamFailed( | 121 void HttpStreamFactoryImpl::Request::OnStreamFailed( |
102 Job* job, | 122 Job* job, |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 // TODO(jgraettinger): Currently, HttpStreamFactoryImpl::Job notifies a | 265 // TODO(jgraettinger): Currently, HttpStreamFactoryImpl::Job notifies a |
246 // Request that the session is ready, which in turn notifies it's delegate, | 266 // Request that the session is ready, which in turn notifies it's delegate, |
247 // and then it notifies HttpStreamFactoryImpl so that /other/ requests may | 267 // 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. | 268 // 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 | 269 // Instead, see if Job can notify HttpStreamFactoryImpl only, and have one |
250 // path for notifying any requests waiting for the session (including the | 270 // path for notifying any requests waiting for the session (including the |
251 // request which spawned it). | 271 // request which spawned it). |
252 void HttpStreamFactoryImpl::Request::OnNewSpdySessionReady( | 272 void HttpStreamFactoryImpl::Request::OnNewSpdySessionReady( |
253 Job* job, | 273 Job* job, |
254 scoped_ptr<HttpStream> stream, | 274 scoped_ptr<HttpStream> stream, |
| 275 scoped_ptr<BidirectionalStreamJob> bidirectional_stream_job, |
255 const base::WeakPtr<SpdySession>& spdy_session, | 276 const base::WeakPtr<SpdySession>& spdy_session, |
256 bool direct) { | 277 bool direct) { |
257 DCHECK(job); | 278 DCHECK(job); |
258 DCHECK(job->using_spdy()); | 279 DCHECK(job->using_spdy()); |
259 | 280 |
260 // Note: |spdy_session| may be NULL. In that case, |delegate_| should still | 281 // Note: |spdy_session| may be NULL. In that case, |delegate_| should still |
261 // receive |stream| so the error propagates up correctly, however there is no | 282 // receive |stream| so the error propagates up correctly, however there is no |
262 // point in broadcasting |spdy_session| to other requests. | 283 // point in broadcasting |spdy_session| to other requests. |
263 | 284 |
264 // The first case is the usual case. | 285 // The first case is the usual case. |
(...skipping 14 matching lines...) Expand all Loading... |
279 const BoundNetLog net_log = job->net_log(); | 300 const BoundNetLog net_log = job->net_log(); |
280 | 301 |
281 Complete(was_npn_negotiated, protocol_negotiated, using_spdy); | 302 Complete(was_npn_negotiated, protocol_negotiated, using_spdy); |
282 | 303 |
283 // Cache this so we can still use it if the request is deleted. | 304 // Cache this so we can still use it if the request is deleted. |
284 HttpStreamFactoryImpl* factory = factory_; | 305 HttpStreamFactoryImpl* factory = factory_; |
285 if (factory->for_websockets_) { | 306 if (factory->for_websockets_) { |
286 // TODO(ricea): Re-instate this code when WebSockets over SPDY is | 307 // TODO(ricea): Re-instate this code when WebSockets over SPDY is |
287 // implemented. | 308 // implemented. |
288 NOTREACHED(); | 309 NOTREACHED(); |
| 310 } else if (for_bidirectional_) { |
| 311 DCHECK(bidirectional_stream_job); |
| 312 DCHECK(!stream); |
| 313 delegate_->OnBidirectionalStreamJobReady( |
| 314 job->server_ssl_config(), job->proxy_info(), |
| 315 bidirectional_stream_job.release()); |
289 } else { | 316 } else { |
| 317 DCHECK(!bidirectional_stream_job); |
| 318 DCHECK(stream); |
290 delegate_->OnStreamReady(job->server_ssl_config(), job->proxy_info(), | 319 delegate_->OnStreamReady(job->server_ssl_config(), job->proxy_info(), |
291 stream.release()); | 320 stream.release()); |
292 } | 321 } |
293 // |this| may be deleted after this point. | 322 // |this| may be deleted after this point. |
294 if (spdy_session && spdy_session->IsAvailable()) { | 323 if (spdy_session && spdy_session->IsAvailable()) { |
295 factory->OnNewSpdySessionReady(spdy_session, | 324 factory->OnNewSpdySessionReady(spdy_session, |
296 direct, | 325 direct, |
297 used_ssl_config, | 326 used_ssl_config, |
298 used_proxy_info, | 327 used_proxy_info, |
299 was_npn_negotiated, | 328 was_npn_negotiated, |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 404 } |
376 // We may have other jobs in |jobs_|. For example, if we start multiple jobs | 405 // We may have other jobs in |jobs_|. For example, if we start multiple jobs |
377 // for Alternate-Protocol. | 406 // for Alternate-Protocol. |
378 BindJob(job); | 407 BindJob(job); |
379 return; | 408 return; |
380 } | 409 } |
381 DCHECK(jobs_.empty()); | 410 DCHECK(jobs_.empty()); |
382 } | 411 } |
383 | 412 |
384 } // namespace net | 413 } // namespace net |
OLD | NEW |