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_job.h" | 5 #include "net/http/http_stream_factory_impl_job.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 #include "net/socket/ssl_client_socket.h" | 44 #include "net/socket/ssl_client_socket.h" |
45 #include "net/socket/ssl_client_socket_pool.h" | 45 #include "net/socket/ssl_client_socket_pool.h" |
46 #include "net/spdy/spdy_http_stream.h" | 46 #include "net/spdy/spdy_http_stream.h" |
47 #include "net/spdy/spdy_protocol.h" | 47 #include "net/spdy/spdy_protocol.h" |
48 #include "net/spdy/spdy_session.h" | 48 #include "net/spdy/spdy_session.h" |
49 #include "net/spdy/spdy_session_pool.h" | 49 #include "net/spdy/spdy_session_pool.h" |
50 #include "net/ssl/ssl_cert_request_info.h" | 50 #include "net/ssl/ssl_cert_request_info.h" |
51 #include "net/ssl/ssl_connection_status_flags.h" | 51 #include "net/ssl/ssl_connection_status_flags.h" |
52 #include "net/ssl/ssl_failure_state.h" | 52 #include "net/ssl/ssl_failure_state.h" |
53 | 53 |
54 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 54 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
55 #include "net/http/bidirectional_stream_job.h" | 55 #include "net/http/bidirectional_stream_job.h" |
56 #include "net/spdy/bidirectional_stream_spdy_job.h" | 56 #include "net/spdy/bidirectional_stream_spdy_job.h" |
57 #endif | 57 #endif |
58 | 58 |
59 namespace net { | 59 namespace net { |
60 | 60 |
61 // Returns parameters associated with the start of a HTTP stream job. | 61 // Returns parameters associated with the start of a HTTP stream job. |
62 scoped_ptr<base::Value> NetLogHttpStreamJobCallback( | 62 scoped_ptr<base::Value> NetLogHttpStreamJobCallback( |
63 const NetLog::Source& source, | 63 const NetLog::Source& source, |
64 const GURL* original_url, | 64 const GURL* original_url, |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 | 361 |
362 request_->Complete(was_npn_negotiated(), protocol_negotiated(), using_spdy()); | 362 request_->Complete(was_npn_negotiated(), protocol_negotiated(), using_spdy()); |
363 request_->OnWebSocketHandshakeStreamReady(this, | 363 request_->OnWebSocketHandshakeStreamReady(this, |
364 server_ssl_config_, | 364 server_ssl_config_, |
365 proxy_info_, | 365 proxy_info_, |
366 websocket_stream_.release()); | 366 websocket_stream_.release()); |
367 // |this| may be deleted after this call. | 367 // |this| may be deleted after this call. |
368 } | 368 } |
369 | 369 |
370 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamJobReadyCallback() { | 370 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamJobReadyCallback() { |
371 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 371 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
372 DCHECK(bidirectional_stream_job_); | 372 DCHECK(bidirectional_stream_job_); |
373 | 373 |
374 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 374 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
375 | 375 |
376 if (IsOrphaned()) { | 376 if (IsOrphaned()) { |
377 stream_factory_->OnOrphanedJobComplete(this); | 377 stream_factory_->OnOrphanedJobComplete(this); |
378 } else { | 378 } else { |
379 request_->Complete(was_npn_negotiated(), protocol_negotiated(), | 379 request_->Complete(was_npn_negotiated(), protocol_negotiated(), |
380 using_spdy()); | 380 using_spdy()); |
381 request_->OnBidirectionalStreamJobReady( | 381 request_->OnBidirectionalStreamJobReady( |
382 this, server_ssl_config_, proxy_info_, | 382 this, server_ssl_config_, proxy_info_, |
383 bidirectional_stream_job_.release()); | 383 bidirectional_stream_job_.release()); |
384 } | 384 } |
385 // |this| may be deleted after this call. | 385 // |this| may be deleted after this call. |
386 #else | 386 #else |
387 DCHECK(false); | 387 DCHECK(false); |
388 #endif | 388 #endif |
389 } | 389 } |
390 | 390 |
391 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { | 391 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { |
392 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 392 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
393 DCHECK(stream_.get() || bidirectional_stream_job_.get()); | 393 DCHECK(stream_.get() || bidirectional_stream_job_.get()); |
394 #else | 394 #else |
395 DCHECK(stream_.get()); | 395 DCHECK(stream_.get()); |
396 #endif | 396 #endif |
397 DCHECK(!IsPreconnecting()); | 397 DCHECK(!IsPreconnecting()); |
398 DCHECK(using_spdy()); | 398 DCHECK(using_spdy()); |
399 // Note: an event loop iteration has passed, so |new_spdy_session_| may be | 399 // Note: an event loop iteration has passed, so |new_spdy_session_| may be |
400 // NULL at this point if the SpdySession closed immediately after creation. | 400 // NULL at this point if the SpdySession closed immediately after creation. |
401 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; | 401 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; |
402 new_spdy_session_.reset(); | 402 new_spdy_session_.reset(); |
403 | 403 |
404 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 404 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
405 | 405 |
406 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, | 406 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, |
407 // rather than notifying |request_| directly. | 407 // rather than notifying |request_| directly. |
408 if (IsOrphaned()) { | 408 if (IsOrphaned()) { |
409 if (spdy_session) { | 409 if (spdy_session) { |
410 stream_factory_->OnNewSpdySessionReady( | 410 stream_factory_->OnNewSpdySessionReady( |
411 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, | 411 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, |
412 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); | 412 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); |
413 } | 413 } |
414 stream_factory_->OnOrphanedJobComplete(this); | 414 stream_factory_->OnOrphanedJobComplete(this); |
415 } else { | 415 } else { |
416 if (for_bidirectional_) { | 416 if (for_bidirectional_) { |
417 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 417 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
418 DCHECK(bidirectional_stream_job_); | 418 DCHECK(bidirectional_stream_job_); |
419 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr, | 419 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr, |
420 std::move(bidirectional_stream_job_), | 420 std::move(bidirectional_stream_job_), |
421 spdy_session, spdy_session_direct_); | 421 spdy_session, spdy_session_direct_); |
422 #else | 422 #else |
423 DCHECK(false); | 423 DCHECK(false); |
424 #endif | 424 #endif |
425 | 425 |
426 } else { | 426 } else { |
427 DCHECK(stream_); | 427 DCHECK(stream_); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 if (new_spdy_session_.get()) { | 609 if (new_spdy_session_.get()) { |
610 base::ThreadTaskRunnerHandle::Get()->PostTask( | 610 base::ThreadTaskRunnerHandle::Get()->PostTask( |
611 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, | 611 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, |
612 ptr_factory_.GetWeakPtr())); | 612 ptr_factory_.GetWeakPtr())); |
613 } else if (stream_factory_->for_websockets_) { | 613 } else if (stream_factory_->for_websockets_) { |
614 DCHECK(websocket_stream_); | 614 DCHECK(websocket_stream_); |
615 base::ThreadTaskRunnerHandle::Get()->PostTask( | 615 base::ThreadTaskRunnerHandle::Get()->PostTask( |
616 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, | 616 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, |
617 ptr_factory_.GetWeakPtr())); | 617 ptr_factory_.GetWeakPtr())); |
618 } else if (for_bidirectional_) { | 618 } else if (for_bidirectional_) { |
619 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 619 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
620 if (!bidirectional_stream_job_) { | 620 if (!bidirectional_stream_job_) { |
621 base::ThreadTaskRunnerHandle::Get()->PostTask( | 621 base::ThreadTaskRunnerHandle::Get()->PostTask( |
622 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, | 622 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, |
623 ptr_factory_.GetWeakPtr(), ERR_FAILED)); | 623 ptr_factory_.GetWeakPtr(), ERR_FAILED)); |
624 } else { | 624 } else { |
625 base::ThreadTaskRunnerHandle::Get()->PostTask( | 625 base::ThreadTaskRunnerHandle::Get()->PostTask( |
626 FROM_HERE, base::Bind(&Job::OnBidirectionalStreamJobReadyCallback, | 626 FROM_HERE, base::Bind(&Job::OnBidirectionalStreamJobReadyCallback, |
627 ptr_factory_.GetWeakPtr())); | 627 ptr_factory_.GetWeakPtr())); |
628 } | 628 } |
629 #else | 629 #else |
(...skipping 577 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1207 } | 1207 } |
1208 | 1208 |
1209 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamJob( | 1209 int HttpStreamFactoryImpl::Job::SetSpdyHttpStreamOrBidirectionalStreamJob( |
1210 base::WeakPtr<SpdySession> session, | 1210 base::WeakPtr<SpdySession> session, |
1211 bool direct) { | 1211 bool direct) { |
1212 // TODO(ricea): Restore the code for WebSockets over SPDY once it's | 1212 // TODO(ricea): Restore the code for WebSockets over SPDY once it's |
1213 // implemented. | 1213 // implemented. |
1214 if (stream_factory_->for_websockets_) | 1214 if (stream_factory_->for_websockets_) |
1215 return ERR_NOT_IMPLEMENTED; | 1215 return ERR_NOT_IMPLEMENTED; |
1216 if (for_bidirectional_) { | 1216 if (for_bidirectional_) { |
1217 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 1217 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
1218 // TODO(xunjieli): Create QUIC's version of BidirectionalStreamJob. | 1218 // TODO(xunjieli): Create QUIC's version of BidirectionalStreamJob. |
1219 bidirectional_stream_job_.reset(new BidirectionalStreamSpdyJob(session)); | 1219 bidirectional_stream_job_.reset(new BidirectionalStreamSpdyJob(session)); |
1220 return OK; | 1220 return OK; |
1221 #else | 1221 #else |
1222 DCHECK(false); | 1222 DCHECK(false); |
1223 return ERR_FAILED; | 1223 return ERR_FAILED; |
1224 #endif | 1224 #endif |
1225 } | 1225 } |
1226 | 1226 |
1227 // TODO(willchan): Delete this code, because eventually, the | 1227 // TODO(willchan): Delete this code, because eventually, the |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 if (connection_->socket()) { | 1690 if (connection_->socket()) { |
1691 ConnectionAttempts socket_attempts; | 1691 ConnectionAttempts socket_attempts; |
1692 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1692 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
1693 request_->AddConnectionAttempts(socket_attempts); | 1693 request_->AddConnectionAttempts(socket_attempts); |
1694 } else { | 1694 } else { |
1695 request_->AddConnectionAttempts(connection_->connection_attempts()); | 1695 request_->AddConnectionAttempts(connection_->connection_attempts()); |
1696 } | 1696 } |
1697 } | 1697 } |
1698 | 1698 |
1699 } // namespace net | 1699 } // namespace net |
OLD | NEW |