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/spdy/spdy_session.h" | 5 #include "net/spdy/spdy_session.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 // requires re-working CreateFakeSpdySession(), though. | 525 // requires re-working CreateFakeSpdySession(), though. |
526 DCHECK(connection_->socket()); | 526 DCHECK(connection_->socket()); |
527 // With SPDY we can't recycle sockets. | 527 // With SPDY we can't recycle sockets. |
528 connection_->socket()->Disconnect(); | 528 connection_->socket()->Disconnect(); |
529 | 529 |
530 RecordHistograms(); | 530 RecordHistograms(); |
531 | 531 |
532 net_log_.EndEvent(NetLog::TYPE_SPDY_SESSION); | 532 net_log_.EndEvent(NetLog::TYPE_SPDY_SESSION); |
533 } | 533 } |
534 | 534 |
535 Error SpdySession::InitializeWithSocket( | 535 void SpdySession::InitializeWithSocket( |
536 scoped_ptr<ClientSocketHandle> connection, | 536 scoped_ptr<ClientSocketHandle> connection, |
537 SpdySessionPool* pool, | 537 SpdySessionPool* pool, |
538 bool is_secure, | 538 bool is_secure, |
539 int certificate_error_code) { | 539 int certificate_error_code) { |
540 CHECK(!in_io_loop_); | 540 CHECK(!in_io_loop_); |
541 DCHECK_EQ(availability_state_, STATE_AVAILABLE); | 541 DCHECK_EQ(availability_state_, STATE_AVAILABLE); |
542 DCHECK_EQ(read_state_, READ_STATE_DO_READ); | 542 DCHECK_EQ(read_state_, READ_STATE_DO_READ); |
543 DCHECK_EQ(write_state_, WRITE_STATE_IDLE); | 543 DCHECK_EQ(write_state_, WRITE_STATE_IDLE); |
544 DCHECK(!connection_); | 544 DCHECK(!connection_); |
545 | 545 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 #if defined(SPDY_PROXY_AUTH_ORIGIN) | 586 #if defined(SPDY_PROXY_AUTH_ORIGIN) |
587 UMA_HISTOGRAM_BOOLEAN("Net.SpdySessions_DataReductionProxy", | 587 UMA_HISTOGRAM_BOOLEAN("Net.SpdySessions_DataReductionProxy", |
588 host_port_pair().Equals(HostPortPair::FromURL( | 588 host_port_pair().Equals(HostPortPair::FromURL( |
589 GURL(SPDY_PROXY_AUTH_ORIGIN)))); | 589 GURL(SPDY_PROXY_AUTH_ORIGIN)))); |
590 #endif | 590 #endif |
591 | 591 |
592 net_log_.AddEvent( | 592 net_log_.AddEvent( |
593 NetLog::TYPE_SPDY_SESSION_INITIALIZED, | 593 NetLog::TYPE_SPDY_SESSION_INITIALIZED, |
594 connection_->socket()->NetLog().source().ToEventParametersCallback()); | 594 connection_->socket()->NetLog().source().ToEventParametersCallback()); |
595 | 595 |
596 int error = DoReadLoop(READ_STATE_DO_READ, OK); | 596 DCHECK_NE(availability_state_, STATE_CLOSED); |
597 if (error == ERR_IO_PENDING) | 597 connection_->AddHigherLayeredPool(this); |
598 error = OK; | 598 if (enable_sending_initial_data_) |
599 if (error == OK) { | 599 SendInitialData(); |
600 DCHECK_NE(availability_state_, STATE_CLOSED); | 600 pool_ = pool; |
601 connection_->AddHigherLayeredPool(this); | 601 |
602 if (enable_sending_initial_data_) | 602 // Bootstrap the read loop. |
603 SendInitialData(); | 603 base::MessageLoop::current()->PostTask( |
604 pool_ = pool; | 604 FROM_HERE, |
605 } else { | 605 base::Bind(&SpdySession::PumpReadLoop, |
606 DcheckClosed(); | 606 weak_factory_.GetWeakPtr(), READ_STATE_DO_READ, OK)); |
607 } | |
608 return static_cast<Error>(error); | |
609 } | 607 } |
610 | 608 |
611 bool SpdySession::VerifyDomainAuthentication(const std::string& domain) { | 609 bool SpdySession::VerifyDomainAuthentication(const std::string& domain) { |
612 if (!verify_domain_authentication_) | 610 if (!verify_domain_authentication_) |
613 return true; | 611 return true; |
614 | 612 |
615 if (availability_state_ == STATE_CLOSED) | 613 if (availability_state_ == STATE_CLOSED) |
616 return false; | 614 return false; |
617 | 615 |
618 SSLInfo ssl_info; | 616 SSLInfo ssl_info; |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1547 return SESSION_ALREADY_CLOSED; | 1545 return SESSION_ALREADY_CLOSED; |
1548 | 1546 |
1549 net_log_.AddEvent( | 1547 net_log_.AddEvent( |
1550 NetLog::TYPE_SPDY_SESSION_CLOSE, | 1548 NetLog::TYPE_SPDY_SESSION_CLOSE, |
1551 base::Bind(&NetLogSpdySessionCloseCallback, err, &description)); | 1549 base::Bind(&NetLogSpdySessionCloseCallback, err, &description)); |
1552 | 1550 |
1553 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SpdySession.ClosedOnError", -err); | 1551 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SpdySession.ClosedOnError", -err); |
1554 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySession.BytesRead.OtherErrors", | 1552 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySession.BytesRead.OtherErrors", |
1555 total_bytes_received_, 1, 100000000, 50); | 1553 total_bytes_received_, 1, 100000000, 50); |
1556 | 1554 |
1557 // |pool_| will be NULL when |InitializeWithSocket()| is in the | 1555 DCHECK(pool_); |
1558 // call stack. | 1556 if (availability_state_ != STATE_GOING_AWAY) |
1559 if (pool_ && availability_state_ != STATE_GOING_AWAY) | |
1560 pool_->MakeSessionUnavailable(GetWeakPtr()); | 1557 pool_->MakeSessionUnavailable(GetWeakPtr()); |
1561 | 1558 |
1562 availability_state_ = STATE_CLOSED; | 1559 availability_state_ = STATE_CLOSED; |
1563 error_on_close_ = err; | 1560 error_on_close_ = err; |
1564 | 1561 |
1565 StartGoingAway(0, err); | 1562 StartGoingAway(0, err); |
1566 write_queue_.Clear(); | 1563 write_queue_.Clear(); |
1567 | 1564 |
1568 DcheckClosed(); | 1565 DcheckClosed(); |
1569 | 1566 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1621 void SpdySession::CloseSessionOnError(Error err, | 1618 void SpdySession::CloseSessionOnError(Error err, |
1622 const std::string& description) { | 1619 const std::string& description) { |
1623 // We may be called from anywhere, so we can't expect a particular | 1620 // We may be called from anywhere, so we can't expect a particular |
1624 // return value. | 1621 // return value. |
1625 ignore_result(DoCloseSession(err, description)); | 1622 ignore_result(DoCloseSession(err, description)); |
1626 } | 1623 } |
1627 | 1624 |
1628 void SpdySession::MakeUnavailable() { | 1625 void SpdySession::MakeUnavailable() { |
1629 if (availability_state_ < STATE_GOING_AWAY) { | 1626 if (availability_state_ < STATE_GOING_AWAY) { |
1630 availability_state_ = STATE_GOING_AWAY; | 1627 availability_state_ = STATE_GOING_AWAY; |
1631 // |pool_| will be NULL when |InitializeWithSocket()| is in the | 1628 DCHECK(pool_); |
1632 // call stack. | 1629 pool_->MakeSessionUnavailable(GetWeakPtr()); |
1633 if (pool_) | |
1634 pool_->MakeSessionUnavailable(GetWeakPtr()); | |
1635 } | 1630 } |
1636 } | 1631 } |
1637 | 1632 |
1638 base::Value* SpdySession::GetInfoAsValue() const { | 1633 base::Value* SpdySession::GetInfoAsValue() const { |
1639 base::DictionaryValue* dict = new base::DictionaryValue(); | 1634 base::DictionaryValue* dict = new base::DictionaryValue(); |
1640 | 1635 |
1641 dict->SetInteger("source_id", net_log_.source().id); | 1636 dict->SetInteger("source_id", net_log_.source().id); |
1642 | 1637 |
1643 dict->SetString("host_port_pair", host_port_pair().ToString()); | 1638 dict->SetString("host_port_pair", host_port_pair().ToString()); |
1644 if (!pooled_aliases_.empty()) { | 1639 if (!pooled_aliases_.empty()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1679 dict->SetBoolean("received_settings", received_settings_); | 1674 dict->SetBoolean("received_settings", received_settings_); |
1680 | 1675 |
1681 dict->SetInteger("send_window_size", session_send_window_size_); | 1676 dict->SetInteger("send_window_size", session_send_window_size_); |
1682 dict->SetInteger("recv_window_size", session_recv_window_size_); | 1677 dict->SetInteger("recv_window_size", session_recv_window_size_); |
1683 dict->SetInteger("unacked_recv_window_bytes", | 1678 dict->SetInteger("unacked_recv_window_bytes", |
1684 session_unacked_recv_window_bytes_); | 1679 session_unacked_recv_window_bytes_); |
1685 return dict; | 1680 return dict; |
1686 } | 1681 } |
1687 | 1682 |
1688 bool SpdySession::IsReused() const { | 1683 bool SpdySession::IsReused() const { |
1689 return buffered_spdy_framer_->frames_received() > 0; | 1684 return buffered_spdy_framer_->frames_received() > 0 || |
| 1685 connection_->reuse_type() == ClientSocketHandle::UNUSED_IDLE; |
1690 } | 1686 } |
1691 | 1687 |
1692 bool SpdySession::GetLoadTimingInfo(SpdyStreamId stream_id, | 1688 bool SpdySession::GetLoadTimingInfo(SpdyStreamId stream_id, |
1693 LoadTimingInfo* load_timing_info) const { | 1689 LoadTimingInfo* load_timing_info) const { |
1694 return connection_->GetLoadTimingInfo(stream_id != kFirstStreamId, | 1690 return connection_->GetLoadTimingInfo(stream_id != kFirstStreamId, |
1695 load_timing_info); | 1691 load_timing_info); |
1696 } | 1692 } |
1697 | 1693 |
1698 int SpdySession::GetPeerAddress(IPEndPoint* address) const { | 1694 int SpdySession::GetPeerAddress(IPEndPoint* address) const { |
1699 int rv = ERR_SOCKET_NOT_CONNECTED; | 1695 int rv = ERR_SOCKET_NOT_CONNECTED; |
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3047 if (!queue->empty()) { | 3043 if (!queue->empty()) { |
3048 SpdyStreamId stream_id = queue->front(); | 3044 SpdyStreamId stream_id = queue->front(); |
3049 queue->pop_front(); | 3045 queue->pop_front(); |
3050 return stream_id; | 3046 return stream_id; |
3051 } | 3047 } |
3052 } | 3048 } |
3053 return 0; | 3049 return 0; |
3054 } | 3050 } |
3055 | 3051 |
3056 } // namespace net | 3052 } // namespace net |
OLD | NEW |