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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
368 | 368 |
369 request_->Complete(was_npn_negotiated(), protocol_negotiated(), using_spdy()); | 369 request_->Complete(was_npn_negotiated(), protocol_negotiated(), using_spdy()); |
370 request_->OnWebSocketHandshakeStreamReady(this, | 370 request_->OnWebSocketHandshakeStreamReady(this, |
371 server_ssl_config_, | 371 server_ssl_config_, |
372 proxy_info_, | 372 proxy_info_, |
373 websocket_stream_.release()); | 373 websocket_stream_.release()); |
374 // |this| may be deleted after this call. | 374 // |this| may be deleted after this call. |
375 } | 375 } |
376 | 376 |
377 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamJobReadyCallback() { | 377 void HttpStreamFactoryImpl::Job::OnBidirectionalStreamJobReadyCallback() { |
378 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 378 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
379 DCHECK(bidirectional_stream_job_); | 379 DCHECK(bidirectional_stream_job_); |
380 | 380 |
381 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 381 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
382 | 382 |
383 if (IsOrphaned()) { | 383 if (IsOrphaned()) { |
384 stream_factory_->OnOrphanedJobComplete(this); | 384 stream_factory_->OnOrphanedJobComplete(this); |
385 } else { | 385 } else { |
386 request_->Complete(was_npn_negotiated(), protocol_negotiated(), | 386 request_->Complete(was_npn_negotiated(), protocol_negotiated(), |
387 using_spdy()); | 387 using_spdy()); |
388 request_->OnBidirectionalStreamJobReady( | 388 request_->OnBidirectionalStreamJobReady( |
389 this, server_ssl_config_, proxy_info_, | 389 this, server_ssl_config_, proxy_info_, |
390 bidirectional_stream_job_.release()); | 390 bidirectional_stream_job_.release()); |
391 } | 391 } |
392 // |this| may be deleted after this call. | 392 // |this| may be deleted after this call. |
393 #else | 393 #else |
394 DCHECK(false); | 394 DCHECK(false); |
395 #endif | 395 #endif |
396 } | 396 } |
397 | 397 |
398 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { | 398 void HttpStreamFactoryImpl::Job::OnNewSpdySessionReadyCallback() { |
399 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 399 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
400 DCHECK(stream_.get() || bidirectional_stream_job_.get()); | 400 DCHECK(stream_.get() || bidirectional_stream_job_.get()); |
401 #else | 401 #else |
402 DCHECK(stream_.get()); | 402 DCHECK(stream_.get()); |
403 #endif | 403 #endif |
404 DCHECK(!IsPreconnecting()); | 404 DCHECK(!IsPreconnecting()); |
405 DCHECK(using_spdy()); | 405 DCHECK(using_spdy()); |
406 // Note: an event loop iteration has passed, so |new_spdy_session_| may be | 406 // Note: an event loop iteration has passed, so |new_spdy_session_| may be |
407 // NULL at this point if the SpdySession closed immediately after creation. | 407 // NULL at this point if the SpdySession closed immediately after creation. |
408 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; | 408 base::WeakPtr<SpdySession> spdy_session = new_spdy_session_; |
409 new_spdy_session_.reset(); | 409 new_spdy_session_.reset(); |
410 | 410 |
411 MaybeCopyConnectionAttemptsFromSocketOrHandle(); | 411 MaybeCopyConnectionAttemptsFromSocketOrHandle(); |
412 | 412 |
413 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, | 413 // TODO(jgraettinger): Notify the factory, and let that notify |request_|, |
414 // rather than notifying |request_| directly. | 414 // rather than notifying |request_| directly. |
415 if (IsOrphaned()) { | 415 if (IsOrphaned()) { |
416 if (spdy_session) { | 416 if (spdy_session) { |
417 stream_factory_->OnNewSpdySessionReady( | 417 stream_factory_->OnNewSpdySessionReady( |
418 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, | 418 spdy_session, spdy_session_direct_, server_ssl_config_, proxy_info_, |
419 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); | 419 was_npn_negotiated(), protocol_negotiated(), using_spdy(), net_log_); |
420 } | 420 } |
421 stream_factory_->OnOrphanedJobComplete(this); | 421 stream_factory_->OnOrphanedJobComplete(this); |
422 } else { | 422 } else { |
423 if (for_bidirectional_) { | 423 if (for_bidirectional_) { |
424 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 424 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
425 DCHECK(bidirectional_stream_job_); | 425 DCHECK(bidirectional_stream_job_); |
426 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr, | 426 request_->OnNewSpdySessionReady(this, /*spdy_http_stream=*/nullptr, |
427 std::move(bidirectional_stream_job_), | 427 std::move(bidirectional_stream_job_), |
428 spdy_session, spdy_session_direct_); | 428 spdy_session, spdy_session_direct_); |
429 #else | 429 #else |
430 DCHECK(false); | 430 DCHECK(false); |
431 #endif | 431 #endif |
432 | 432 |
433 } else { | 433 } else { |
434 DCHECK(stream_); | 434 DCHECK(stream_); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 if (new_spdy_session_.get()) { | 616 if (new_spdy_session_.get()) { |
617 base::ThreadTaskRunnerHandle::Get()->PostTask( | 617 base::ThreadTaskRunnerHandle::Get()->PostTask( |
618 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, | 618 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, |
619 ptr_factory_.GetWeakPtr())); | 619 ptr_factory_.GetWeakPtr())); |
620 } else if (stream_factory_->for_websockets_) { | 620 } else if (stream_factory_->for_websockets_) { |
621 DCHECK(websocket_stream_); | 621 DCHECK(websocket_stream_); |
622 base::ThreadTaskRunnerHandle::Get()->PostTask( | 622 base::ThreadTaskRunnerHandle::Get()->PostTask( |
623 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, | 623 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, |
624 ptr_factory_.GetWeakPtr())); | 624 ptr_factory_.GetWeakPtr())); |
625 } else if (for_bidirectional_) { | 625 } else if (for_bidirectional_) { |
626 #if defined(ENABLE_BIDIRECTIONAL_STREAM) | 626 #if BUILDFLAG(ENABLE_BIDIRECTIONAL_STREAM) |
627 if (!bidirectional_stream_job_) { | 627 if (!bidirectional_stream_job_) { |
628 base::ThreadTaskRunnerHandle::Get()->PostTask( | 628 base::ThreadTaskRunnerHandle::Get()->PostTask( |
629 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, | 629 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, |
630 ptr_factory_.GetWeakPtr(), ERR_FAILED)); | 630 ptr_factory_.GetWeakPtr(), ERR_FAILED)); |
631 } else { | 631 } else { |
632 base::ThreadTaskRunnerHandle::Get()->PostTask( | 632 base::ThreadTaskRunnerHandle::Get()->PostTask( |
633 FROM_HERE, base::Bind(&Job::OnBidirectionalStreamJobReadyCallback, | 633 FROM_HERE, base::Bind(&Job::OnBidirectionalStreamJobReadyCallback, |
634 ptr_factory_.GetWeakPtr())); | 634 ptr_factory_.GetWeakPtr())); |
635 } | 635 } |
636 #else | 636 #else |
(...skipping 570 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 |