Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(721)

Side by Side Diff: net/http/http_stream_factory_impl_job.cc

Issue 2332193003: JobController3: Move MarkAlternativeServiceBroken to job controller (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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),
210 other_job_status_(STATUS_RUNNING),
211 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM), 209 stream_type_(HttpStreamRequest::BIDIRECTIONAL_STREAM),
212 ptr_factory_(this) { 210 ptr_factory_(this) {
213 DCHECK(session); 211 DCHECK(session);
214 // The job can't have alternative service and alternative proxy server set at 212 // 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 213 // the same time since alternative services are used for requests that are
216 // fetched directly, while the alternative proxy server is used for requests 214 // fetched directly, while the alternative proxy server is used for requests
217 // that should be fetched using proxy. 215 // that should be fetched using proxy.
218 DCHECK(alternative_service_.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL || 216 DCHECK(alternative_service_.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL ||
219 !alternative_proxy_server_.is_valid()); 217 !alternative_proxy_server_.is_valid());
220 DCHECK(!alternative_proxy_server_.is_valid() || 218 DCHECK(!alternative_proxy_server_.is_valid() ||
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 static_cast<ProxyClientSocket*>(connection_->socket()); 572 static_cast<ProxyClientSocket*>(connection_->socket());
575 base::ThreadTaskRunnerHandle::Get()->PostTask( 573 base::ThreadTaskRunnerHandle::Get()->PostTask(
576 FROM_HERE, base::Bind(&Job::OnHttpsProxyTunnelResponseCallback, 574 FROM_HERE, base::Bind(&Job::OnHttpsProxyTunnelResponseCallback,
577 ptr_factory_.GetWeakPtr(), 575 ptr_factory_.GetWeakPtr(),
578 *proxy_socket->GetConnectResponseInfo(), 576 *proxy_socket->GetConnectResponseInfo(),
579 proxy_socket->CreateConnectResponseStream())); 577 proxy_socket->CreateConnectResponseStream()));
580 return ERR_IO_PENDING; 578 return ERR_IO_PENDING;
581 } 579 }
582 580
583 case OK: 581 case OK:
584 job_status_ = STATUS_SUCCEEDED;
585 MaybeMarkAlternativeServiceBroken();
586 next_state_ = STATE_DONE; 582 next_state_ = STATE_DONE;
587 if (new_spdy_session_.get()) { 583 if (new_spdy_session_.get()) {
588 base::ThreadTaskRunnerHandle::Get()->PostTask( 584 base::ThreadTaskRunnerHandle::Get()->PostTask(
589 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback, 585 FROM_HERE, base::Bind(&Job::OnNewSpdySessionReadyCallback,
590 ptr_factory_.GetWeakPtr())); 586 ptr_factory_.GetWeakPtr()));
591 } else if (delegate_->for_websockets()) { 587 } else if (delegate_->for_websockets()) {
592 DCHECK(websocket_stream_); 588 DCHECK(websocket_stream_);
593 base::ThreadTaskRunnerHandle::Get()->PostTask( 589 base::ThreadTaskRunnerHandle::Get()->PostTask(
594 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback, 590 FROM_HERE, base::Bind(&Job::OnWebSocketHandshakeStreamReadyCallback,
595 ptr_factory_.GetWeakPtr())); 591 ptr_factory_.GetWeakPtr()));
(...skipping 10 matching lines...) Expand all
606 } 602 }
607 } else { 603 } else {
608 DCHECK(stream_.get()); 604 DCHECK(stream_.get());
609 base::ThreadTaskRunnerHandle::Get()->PostTask( 605 base::ThreadTaskRunnerHandle::Get()->PostTask(
610 FROM_HERE, 606 FROM_HERE,
611 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr())); 607 base::Bind(&Job::OnStreamReadyCallback, ptr_factory_.GetWeakPtr()));
612 } 608 }
613 return ERR_IO_PENDING; 609 return ERR_IO_PENDING;
614 610
615 default: 611 default:
616 if (job_status_ != STATUS_BROKEN) {
617 DCHECK_EQ(STATUS_RUNNING, job_status_);
618 job_status_ = STATUS_FAILED;
619 MaybeMarkAlternativeServiceBroken();
620 }
621 base::ThreadTaskRunnerHandle::Get()->PostTask( 612 base::ThreadTaskRunnerHandle::Get()->PostTask(
622 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback, 613 FROM_HERE, base::Bind(&Job::OnStreamFailedCallback,
623 ptr_factory_.GetWeakPtr(), result)); 614 ptr_factory_.GetWeakPtr(), result));
624 return ERR_IO_PENDING; 615 return ERR_IO_PENDING;
625 } 616 }
626 } 617 }
627 618
628 int HttpStreamFactoryImpl::Job::DoLoop(int result) { 619 int HttpStreamFactoryImpl::Job::DoLoop(int result) {
629 DCHECK_NE(next_state_, STATE_NONE); 620 DCHECK_NE(next_state_, STATE_NONE);
630 int rv = result; 621 int rv = result;
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
1056 // class. 1047 // class.
1057 connection_.reset(connection_->release_pending_http_proxy_connection()); 1048 connection_.reset(connection_->release_pending_http_proxy_connection());
1058 return result; 1049 return result;
1059 } 1050 }
1060 1051
1061 if (proxy_info_.is_quic() && using_quic_ && result < 0) { 1052 if (proxy_info_.is_quic() && using_quic_ && result < 0) {
1062 using_quic_ = false; 1053 using_quic_ = false;
1063 return ReconsiderProxyAfterError(result); 1054 return ReconsiderProxyAfterError(result);
1064 } 1055 }
1065 1056
1066 if (IsSpdyAlternative() && !using_spdy_) { 1057 if (IsSpdyAlternative() && !using_spdy_)
1067 job_status_ = STATUS_BROKEN;
1068 MaybeMarkAlternativeServiceBroken();
1069 return ERR_NPN_NEGOTIATION_FAILED; 1058 return ERR_NPN_NEGOTIATION_FAILED;
1070 }
1071 1059
1072 if (!ssl_started && result < 0 && 1060 if (!ssl_started && result < 0 &&
1073 (IsSpdyAlternative() || IsQuicAlternative())) { 1061 (IsSpdyAlternative() || IsQuicAlternative()))
1074 job_status_ = STATUS_BROKEN;
1075 MaybeMarkAlternativeServiceBroken();
1076 return result; 1062 return result;
1077 }
1078 1063
1079 if (using_quic_) { 1064 if (using_quic_) {
1080 if (result < 0) { 1065 if (result < 0)
1081 job_status_ = STATUS_BROKEN;
1082 MaybeMarkAlternativeServiceBroken();
1083 return result; 1066 return result;
1084 } 1067
1085 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) { 1068 if (stream_type_ == HttpStreamRequest::BIDIRECTIONAL_STREAM) {
1086 bidirectional_stream_impl_ = 1069 bidirectional_stream_impl_ =
1087 quic_request_.CreateBidirectionalStreamImpl(); 1070 quic_request_.CreateBidirectionalStreamImpl();
1088 if (!bidirectional_stream_impl_) { 1071 if (!bidirectional_stream_impl_) {
1089 // Quic session is closed before stream can be created. 1072 // Quic session is closed before stream can be created.
1090 return ERR_CONNECTION_CLOSED; 1073 return ERR_CONNECTION_CLOSED;
1091 } 1074 }
1092 } else { 1075 } else {
1093 stream_ = quic_request_.CreateStream(); 1076 stream_ = quic_request_.CreateStream();
1094 if (!stream_) { 1077 if (!stream_) {
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE); 1491 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE);
1509 } else if (IsSpdyAlternative() || IsQuicAlternative()) { 1492 } else if (IsSpdyAlternative() || IsQuicAlternative()) {
1510 // This Job was the alternative Job, and hence won the race. 1493 // This Job was the alternative Job, and hence won the race.
1511 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE); 1494 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE);
1512 } else { 1495 } else {
1513 // This Job was the normal Job, and hence the alternative Job lost the race. 1496 // This Job was the normal Job, and hence the alternative Job lost the race.
1514 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE); 1497 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE);
1515 } 1498 }
1516 } 1499 }
1517 1500
1518 void HttpStreamFactoryImpl::Job::MarkOtherJobComplete(const Job& job) {
1519 DCHECK_EQ(STATUS_RUNNING, other_job_status_);
1520 DCHECK(!other_job_alternative_proxy_server_.is_valid());
1521
1522 other_job_status_ = job.job_status_;
1523 other_job_alternative_service_ = job.alternative_service_;
1524 other_job_alternative_proxy_server_ = job.alternative_proxy_server_;
1525
1526 // At most one job can have a valid |alternative_proxy_server_|.
1527 DCHECK(!alternative_proxy_server_.is_valid() ||
1528 !other_job_alternative_proxy_server_.is_valid());
1529
1530 MaybeMarkAlternativeServiceBroken();
1531 }
1532
1533 void HttpStreamFactoryImpl::Job::MaybeMarkAlternativeServiceBroken() {
1534 // At least one job should not be an alternative job.
1535 DCHECK(alternative_service_.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL ||
1536 other_job_alternative_service_.protocol ==
1537 UNINITIALIZED_ALTERNATE_PROTOCOL);
1538
1539 if (job_status_ == STATUS_RUNNING || other_job_status_ == STATUS_RUNNING)
1540 return;
1541
1542 MaybeNotifyAlternativeProxyServerBroken();
1543
1544 if (IsSpdyAlternative() || IsQuicAlternative()) {
1545 if (job_status_ == STATUS_BROKEN && other_job_status_ == STATUS_SUCCEEDED) {
1546 HistogramBrokenAlternateProtocolLocation(
1547 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_ALT);
1548 session_->http_server_properties()->MarkAlternativeServiceBroken(
1549 alternative_service_);
1550 }
1551 return;
1552 }
1553
1554 session_->quic_stream_factory()->OnTcpJobCompleted(job_status_ ==
1555 STATUS_SUCCEEDED);
1556 if (job_status_ == STATUS_SUCCEEDED && other_job_status_ == STATUS_BROKEN) {
1557 HistogramBrokenAlternateProtocolLocation(
1558 BROKEN_ALTERNATE_PROTOCOL_LOCATION_HTTP_STREAM_FACTORY_IMPL_JOB_MAIN);
1559 session_->http_server_properties()->MarkAlternativeServiceBroken(
1560 other_job_alternative_service_);
1561 }
1562 }
1563
1564 void HttpStreamFactoryImpl::Job::MaybeNotifyAlternativeProxyServerBroken()
1565 const {
1566 if (!alternative_proxy_server_.is_valid() &&
1567 !other_job_alternative_proxy_server_.is_valid()) {
1568 // Neither of the two jobs used an alternative proxy server.
1569 return;
1570 }
1571
1572 // Neither this job, nor the other job should have used the alternative
1573 // service.
1574 DCHECK_EQ(UNINITIALIZED_ALTERNATE_PROTOCOL, alternative_service_.protocol);
1575 DCHECK_EQ(UNINITIALIZED_ALTERNATE_PROTOCOL,
1576 other_job_alternative_service_.protocol);
1577
1578 ProxyDelegate* proxy_delegate = session_->params().proxy_delegate;
1579 if (!proxy_delegate)
1580 return;
1581
1582 if (alternative_proxy_server_.is_valid()) {
1583 // |this| connected to the alternative proxy server.
1584 if ((job_status_ == STATUS_BROKEN || job_status_ == STATUS_FAILED) &&
1585 other_job_status_ == STATUS_SUCCEEDED) {
1586 // Notify ProxyDelegate.
1587 proxy_delegate->OnAlternativeProxyBroken(alternative_proxy_server_);
1588 }
1589 return;
1590 }
1591
1592 if (other_job_alternative_proxy_server_.is_valid()) {
1593 // Other job connected to the alternative proxy server.
1594 if (job_status_ == STATUS_SUCCEEDED &&
1595 (other_job_status_ == STATUS_BROKEN ||
1596 other_job_status_ == STATUS_FAILED)) {
1597 // Notify ProxyDelegate.
1598 proxy_delegate->OnAlternativeProxyBroken(
1599 other_job_alternative_proxy_server_);
1600 }
1601 return;
1602 }
1603 }
1604
1605 ClientSocketPoolManager::SocketGroupType 1501 ClientSocketPoolManager::SocketGroupType
1606 HttpStreamFactoryImpl::Job::GetSocketGroup() const { 1502 HttpStreamFactoryImpl::Job::GetSocketGroup() const {
1607 std::string scheme = origin_url_.scheme(); 1503 std::string scheme = origin_url_.scheme();
1608 if (scheme == "https" || scheme == "wss" || IsSpdyAlternative()) 1504 if (scheme == "https" || scheme == "wss" || IsSpdyAlternative())
1609 return ClientSocketPoolManager::SSL_GROUP; 1505 return ClientSocketPoolManager::SSL_GROUP;
1610 1506
1611 if (scheme == "ftp") 1507 if (scheme == "ftp")
1612 return ClientSocketPoolManager::FTP_GROUP; 1508 return ClientSocketPoolManager::FTP_GROUP;
1613 1509
1614 return ClientSocketPoolManager::NORMAL_GROUP; 1510 return ClientSocketPoolManager::NORMAL_GROUP;
(...skipping 11 matching lines...) Expand all
1626 1522
1627 ConnectionAttempts socket_attempts = connection_->connection_attempts(); 1523 ConnectionAttempts socket_attempts = connection_->connection_attempts();
1628 if (connection_->socket()) { 1524 if (connection_->socket()) {
1629 connection_->socket()->GetConnectionAttempts(&socket_attempts); 1525 connection_->socket()->GetConnectionAttempts(&socket_attempts);
1630 } 1526 }
1631 1527
1632 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts); 1528 delegate_->AddConnectionAttemptsToRequest(this, socket_attempts);
1633 } 1529 }
1634 1530
1635 } // namespace net 1531 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698