Chromium Code Reviews| 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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 using_spdy_(false), | 199 using_spdy_(false), |
| 200 using_quic_(false), | 200 using_quic_(false), |
| 201 quic_request_(session_->quic_stream_factory()), | 201 quic_request_(session_->quic_stream_factory()), |
| 202 using_existing_quic_session_(false), | 202 using_existing_quic_session_(false), |
| 203 spdy_certificate_error_(OK), | 203 spdy_certificate_error_(OK), |
| 204 establishing_tunnel_(false), | 204 establishing_tunnel_(false), |
| 205 was_npn_negotiated_(false), | 205 was_npn_negotiated_(false), |
| 206 negotiated_protocol_(kProtoUnknown), | 206 negotiated_protocol_(kProtoUnknown), |
| 207 num_streams_(0), | 207 num_streams_(0), |
| 208 spdy_session_direct_(false), | 208 spdy_session_direct_(false), |
| 209 job_status_(STATUS_RUNNING), | 209 job_status_(STATUS_RUNNING), |
|
tbansal1
2016/09/13 05:06:45
It seems that job_status_, other_job_status_ and o
Zhongyi Shi
2016/09/13 22:52:37
Done.
| |
| 210 other_job_status_(STATUS_RUNNING), | 210 other_job_status_(STATUS_RUNNING), |
| 211 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), | 211 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), |
| 212 ptr_factory_(this) { | 212 ptr_factory_(this) { |
| 213 DCHECK(session); | 213 DCHECK(session); |
| 214 // The job can't have alternative service and alternative proxy server set at | 214 // The job can't have alternative service and alternative proxy server set at |
| 215 // the same time since alternative services are used for requests that are | 215 // the same time since alternative services are used for requests that are |
| 216 // fetched directly, while the alternative proxy server is used for requests | 216 // fetched directly, while the alternative proxy server is used for requests |
| 217 // that should be fetched using proxy. | 217 // that should be fetched using proxy. |
| 218 DCHECK(alternative_service_.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL || | 218 DCHECK(alternative_service_.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL || |
| 219 !alternative_proxy_server_.is_valid()); | 219 !alternative_proxy_server_.is_valid()); |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 574 static_cast<ProxyClientSocket*>(connection_->socket()); | 574 static_cast<ProxyClientSocket*>(connection_->socket()); |
| 575 base::ThreadTaskRunnerHandle::Get()->PostTask( | 575 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 576 FROM_HERE, base::Bind(&Job::OnHttpsProxyTunnelResponseCallback, | 576 FROM_HERE, base::Bind(&Job::OnHttpsProxyTunnelResponseCallback, |
| 577 ptr_factory_.GetWeakPtr(), | 577 ptr_factory_.GetWeakPtr(), |
| 578 *proxy_socket->GetConnectResponseInfo(), | 578 *proxy_socket->GetConnectResponseInfo(), |
| 579 proxy_socket->CreateConnectResponseStream())); | 579 proxy_socket->CreateConnectResponseStream())); |
| 580 return ERR_IO_PENDING; | 580 return ERR_IO_PENDING; |
| 581 } | 581 } |
| 582 | 582 |
| 583 case OK: | 583 case OK: |
| 584 job_status_ = STATUS_SUCCEEDED; | |
| 585 MaybeMarkAlternativeServiceBroken(); | |
| 586 next_state_ = STATE_DONE; | 584 next_state_ = STATE_DONE; |
| 587 if (new_spdy_session_.get()) { | 585 if (new_spdy_session_.get()) { |
| 588 base::ThreadTaskRunnerHandle::Get()->PostTask( | 586 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 589 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, | 587 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, |
| 590 ptr_factory_.GetWeakPtr())); | 588 ptr_factory_.GetWeakPtr())); |
| 591 } else if (delegate_->for_websockets()) { | 589 } else if (delegate_->for_websockets()) { |
| 592 DCHECK(websocket_stream_); | 590 DCHECK(websocket_stream_); |
| 593 base::ThreadTaskRunnerHandle::Get()->PostTask( | 591 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 594 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, | 592 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, |
| 595 ptr_factory_.GetWeakPtr())); | 593 ptr_factory_.GetWeakPtr())); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 606 } | 604 } |
| 607 } else { | 605 } else { |
| 608 DCHECK(stream_.get()); | 606 DCHECK(stream_.get()); |
| 609 base::ThreadTaskRunnerHandle::Get()->PostTask( | 607 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 610 FROM_HERE, | 608 FROM_HERE, |
| 611 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr())); | 609 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr())); |
| 612 } | 610 } |
| 613 return ERR_IO_PENDING; | 611 return ERR_IO_PENDING; |
| 614 | 612 |
| 615 default: | 613 default: |
| 616 if (job_status_ != STATUS_BROKEN) { | 614 // Notify job controlelr that alternative proxy server is broken. |
| 617 DCHECK_EQ(STATUS_RUNNING, job_status_); | 615 if (alternative_proxy_server_.is_valid()) { |
| 618 job_status_ = STATUS_FAILED; | 616 delegate_->OnAlternativeProxyServerBroken(this); |
|
Ryan Hamilton
2016/09/13 04:17:04
Instead of requiring the job to explicitly notify
| |
| 619 MaybeMarkAlternativeServiceBroken(); | |
| 620 } | 617 } |
| 621 base::ThreadTaskRunnerHandle::Get()->PostTask( | 618 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 622 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, | 619 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, |
| 623 ptr_factory_.GetWeakPtr(), result)); | 620 ptr_factory_.GetWeakPtr(), result)); |
| 624 return ERR_IO_PENDING; | 621 return ERR_IO_PENDING; |
| 625 } | 622 } |
| 626 } | 623 } |
| 627 | 624 |
| 628 int HttpStreamFactoryImpl::Job::DoLoop(int result) { | 625 int HttpStreamFactoryImpl::Job::DoLoop(int result) { |
| 629 DCHECK_NE(next_state_, STATE_NONE); | 626 DCHECK_NE(next_state_, STATE_NONE); |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1058 connection_.reset(connection_->release_pending_http_proxy_connection()); | 1055 connection_.reset(connection_->release_pending_http_proxy_connection()); |
| 1059 return result; | 1056 return result; |
| 1060 } | 1057 } |
| 1061 | 1058 |
| 1062 if (proxy_info_.is_quic() && using_quic_ && result < 0) { | 1059 if (proxy_info_.is_quic() && using_quic_ && result < 0) { |
| 1063 using_quic_ = false; | 1060 using_quic_ = false; |
| 1064 return ReconsiderProxyAfterError(result); | 1061 return ReconsiderProxyAfterError(result); |
| 1065 } | 1062 } |
| 1066 | 1063 |
| 1067 if (IsSpdyAlternative() && !using_spdy_) { | 1064 if (IsSpdyAlternative() && !using_spdy_) { |
| 1068 job_status_ = STATUS_BROKEN; | 1065 if (alternative_proxy_server_.is_valid()) { |
| 1069 MaybeMarkAlternativeServiceBroken(); | 1066 // |this| connected to the alternative proxy server. |
| 1067 delegate_->OnAlternativeProxyServerBroken(this); | |
| 1068 } else { | |
| 1069 delegate_->OnAlternativeServiceBroken(this); | |
| 1070 } | |
| 1070 return ERR_NPN_NEGOTIATION_FAILED; | 1071 return ERR_NPN_NEGOTIATION_FAILED; |
| 1071 } | 1072 } |
| 1072 | 1073 |
| 1073 if (!ssl_started && result < 0 && | 1074 if (!ssl_started && result < 0 && |
| 1074 (IsSpdyAlternative() || IsQuicAlternative())) { | 1075 (IsSpdyAlternative() || IsQuicAlternative())) { |
| 1075 job_status_ = STATUS_BROKEN; | 1076 if (alternative_proxy_server_.is_valid()) { |
| 1076 MaybeMarkAlternativeServiceBroken(); | 1077 // |this| connected to the alternative proxy server. |
| 1078 delegate_->OnAlternativeProxyServerBroken(this); | |
| 1079 } else { | |
| 1080 delegate_->OnAlternativeServiceBroken(this); | |
| 1081 } | |
| 1077 return result; | 1082 return result; |
| 1078 } | 1083 } |
| 1079 | 1084 |
| 1080 if (using_quic_) { | 1085 if (using_quic_) { |
| 1081 if (result < 0) { | 1086 if (result < 0) { |
| 1082 job_status_ = STATUS_BROKEN; | 1087 if (alternative_proxy_server_.is_valid()) { |
| 1083 MaybeMarkAlternativeServiceBroken(); | 1088 // |this| connected to the alternative proxy server. |
| 1089 delegate_->OnAlternativeProxyServerBroken(this); | |
| 1090 } else { | |
| 1091 delegate_->OnAlternativeServiceBroken(this); | |
| 1092 } | |
| 1084 return result; | 1093 return result; |
| 1085 } | 1094 } |
| 1086 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { | 1095 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { |
| 1087 bidirectional_stream_impl_ = | 1096 bidirectional_stream_impl_ = |
| 1088 quic_request_.CreateBidirectionalStreamImpl(); | 1097 quic_request_.CreateBidirectionalStreamImpl(); |
| 1089 if (!bidirectional_stream_impl_) { | 1098 if (!bidirectional_stream_impl_) { |
| 1090 // Quic session is closed before stream can be created. | 1099 // Quic session is closed before stream can be created. |
| 1091 return ERR_CONNECTION_CLOSED; | 1100 return ERR_CONNECTION_CLOSED; |
| 1092 } | 1101 } |
| 1093 } else { | 1102 } else { |
| (...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1513 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); | 1522 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); |
| 1514 } else if (IsSpdyAlternative() || IsQuicAlternative()) { | 1523 } else if (IsSpdyAlternative() || IsQuicAlternative()) { |
| 1515 // This Job was the alternative Job, and hence won the race. | 1524 // This Job was the alternative Job, and hence won the race. |
| 1516 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); | 1525 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); |
| 1517 } else { | 1526 } else { |
| 1518 // This Job was the normal Job, and hence the alternative Job lost the race. | 1527 // This Job was the normal Job, and hence the alternative Job lost the race. |
| 1519 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE); | 1528 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE); |
| 1520 } | 1529 } |
| 1521 } | 1530 } |
| 1522 | 1531 |
| 1523 void HttpStreamFactoryImpl::Job::MarkOtherJobComplete(const Job& job) { | |
| 1524 DCHECK_EQ(STATUS_RUNNING, other_job_status_); | |
| 1525 DCHECK(!other_job_alternative_proxy_server_.is_valid()); | |
| 1526 | |
| 1527 other_job_status_ = job.job_status_; | |
| 1528 other_job_alternative_service_ = job.alternative_service_; | |
| 1529 other_job_alternative_proxy_server_ = job.alternative_proxy_server_; | |
| 1530 | |
| 1531 // At most one job can have a valid |alternative_proxy_server_|. | |
| 1532 DCHECK(!alternative_proxy_server_.is_valid() || | |
| 1533 !other_job_alternative_proxy_server_.is_valid()); | |
| 1534 | |
| 1535 MaybeMarkAlternativeServiceBroken(); | |
| 1536 } | |
| 1537 | |
| 1538 void HttpStreamFactoryImpl::Job::MaybeMarkAlternativeServiceBroken() { | |
| 1539 // At least one job should not be an alternative job. | |
| 1540 DCHECK(alternative_service_.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL || | |
| 1541 other_job_alternative_service_.protocol == | |
| 1542 UNINITIALIZED_ALTERNATE_PROTOCOL); | |
| 1543 | |
| 1544 if (job_status_ == STATUS_RUNNING || other_job_status_ == STATUS_RUNNING) | |
| 1545 return; | |
| 1546 | |
| 1547 MaybeNotifyAlternativeProxyServerBroken(); | |
| 1548 | |
| 1549 if (IsSpdyAlternative() || IsQuicAlternative()) { | |
| 1550 if (job_status_ == STATUS_BROKEN && other_job_status_ == STATUS_SUCCEEDED) { | |
| 1551 HistogramBrokenAlternateProtocolLocation( | |
| 1552 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT); | |
| 1553 session_->http_server_properties()->MarkAlternativeServiceBroken( | |
| 1554 alternative_service_); | |
| 1555 } | |
| 1556 return; | |
| 1557 } | |
| 1558 | |
| 1559 session_->quic_stream_factory()->OnTcpJobCompleted(job_status_ == | |
| 1560 STATUS_SUCCEEDED); | |
| 1561 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) { | |
| 1562 HistogramBrokenAlternateProtocolLocation( | |
| 1563 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN); | |
| 1564 session_->http_server_properties()->MarkAlternativeServiceBroken( | |
| 1565 other_job_alternative_service_); | |
| 1566 } | |
| 1567 } | |
| 1568 | |
| 1569 void HttpStreamFactoryImpl::Job::MaybeNotifyAlternativeProxyServerBroken() | |
| 1570 const { | |
| 1571 if (!alternative_proxy_server_.is_valid() && | |
| 1572 !other_job_alternative_proxy_server_.is_valid()) { | |
| 1573 // Neither of the two jobs used an alternative proxy server. | |
| 1574 return; | |
| 1575 } | |
| 1576 | |
| 1577 // Neither this job, nor the other job should have used the alternative | |
| 1578 // service. | |
| 1579 DCHECK_EQ(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service_.protocol); | |
| 1580 DCHECK_EQ(UNINITIALIZED_ALTERNATE_PROTOCOL, | |
| 1581 other_job_alternative_service_.protocol); | |
| 1582 | |
| 1583 ProxyDelegate* proxy_delegate = session_->params().proxy_delegate; | |
| 1584 if (!proxy_delegate) | |
| 1585 return; | |
| 1586 | |
| 1587 if (alternative_proxy_server_.is_valid()) { | |
| 1588 // |this| connected to the alternative proxy server. | |
| 1589 if ((job_status_ == STATUS_BROKEN || job_status_ == STATUS_FAILED) && | |
| 1590 other_job_status_ == STATUS_SUCCEEDED) { | |
| 1591 // Notify ProxyDelegate. | |
| 1592 proxy_delegate->OnAlternativeProxyBroken(alternative_proxy_server_); | |
| 1593 } | |
| 1594 return; | |
| 1595 } | |
| 1596 | |
| 1597 if (other_job_alternative_proxy_server_.is_valid()) { | |
| 1598 // Other job connected to the alternative proxy server. | |
| 1599 if (job_status_ == STATUS_SUCCEEDED && | |
| 1600 (other_job_status_ == STATUS_BROKEN || | |
| 1601 other_job_status_ == STATUS_FAILED)) { | |
| 1602 // Notify ProxyDelegate. | |
| 1603 proxy_delegate->OnAlternativeProxyBroken( | |
| 1604 other_job_alternative_proxy_server_); | |
| 1605 } | |
| 1606 return; | |
| 1607 } | |
| 1608 } | |
| 1609 | |
| 1610 ClientSocketPoolManager::SocketGroupType | 1532 ClientSocketPoolManager::SocketGroupType |
| 1611 HttpStreamFactoryImpl::Job::GetSocketGroup() const { | 1533 HttpStreamFactoryImpl::Job::GetSocketGroup() const { |
| 1612 std::string scheme = origin_url_.scheme(); | 1534 std::string scheme = origin_url_.scheme(); |
| 1613 if (scheme == "https" || scheme == "wss" || IsSpdyAlternative()) | 1535 if (scheme == "https" || scheme == "wss" || IsSpdyAlternative()) |
| 1614 return ClientSocketPoolManager::SSL_GROUP; | 1536 return ClientSocketPoolManager::SSL_GROUP; |
| 1615 | 1537 |
| 1616 if (scheme == "ftp") | 1538 if (scheme == "ftp") |
| 1617 return ClientSocketPoolManager::FTP_GROUP; | 1539 return ClientSocketPoolManager::FTP_GROUP; |
| 1618 | 1540 |
| 1619 return ClientSocketPoolManager::NORMAL_GROUP; | 1541 return ClientSocketPoolManager::NORMAL_GROUP; |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1631 | 1553 |
| 1632 ConnectionAttempts socket_attempts = connection_->connection_attempts(); | 1554 ConnectionAttempts socket_attempts = connection_->connection_attempts(); |
| 1633 if (connection_->socket()) { | 1555 if (connection_->socket()) { |
| 1634 connection_->socket()->GetConnectionAttempts(&socket_attempts); | 1556 connection_->socket()->GetConnectionAttempts(&socket_attempts); |
| 1635 } | 1557 } |
| 1636 | 1558 |
| 1637 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); | 1559 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); |
| 1638 } | 1560 } |
| 1639 | 1561 |
| 1640 } // namespace net | 1562 } // namespace net |
| OLD | NEW |