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 void SpdySession::InitializeWithSocket( | 535 Error 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 DCHECK_NE(availability_state_, STATE_CLOSED); | 596 int error = DoReadLoop(READ_STATE_DO_READ, OK); |
597 connection_->AddHigherLayeredPool(this); | 597 if (error == ERR_IO_PENDING) |
598 if (enable_sending_initial_data_) | 598 error = OK; |
599 SendInitialData(); | 599 if (error == OK) { |
600 pool_ = pool; | 600 DCHECK_NE(availability_state_, STATE_CLOSED); |
601 | 601 connection_->AddHigherLayeredPool(this); |
602 // Bootstrap the read loop. | 602 if (enable_sending_initial_data_) |
603 base::MessageLoop::current()->PostTask( | 603 SendInitialData(); |
604 FROM_HERE, | 604 pool_ = pool; |
605 base::Bind(&SpdySession::PumpReadLoop, | 605 } else { |
606 weak_factory_.GetWeakPtr(), READ_STATE_DO_READ, OK)); | 606 DcheckClosed(); |
| 607 } |
| 608 return static_cast<Error>(error); |
607 } | 609 } |
608 | 610 |
609 bool SpdySession::VerifyDomainAuthentication(const std::string& domain) { | 611 bool SpdySession::VerifyDomainAuthentication(const std::string& domain) { |
610 if (!verify_domain_authentication_) | 612 if (!verify_domain_authentication_) |
611 return true; | 613 return true; |
612 | 614 |
613 if (availability_state_ == STATE_CLOSED) | 615 if (availability_state_ == STATE_CLOSED) |
614 return false; | 616 return false; |
615 | 617 |
616 SSLInfo ssl_info; | 618 SSLInfo ssl_info; |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1545 return SESSION_ALREADY_CLOSED; | 1547 return SESSION_ALREADY_CLOSED; |
1546 | 1548 |
1547 net_log_.AddEvent( | 1549 net_log_.AddEvent( |
1548 NetLog::TYPE_SPDY_SESSION_CLOSE, | 1550 NetLog::TYPE_SPDY_SESSION_CLOSE, |
1549 base::Bind(&NetLogSpdySessionCloseCallback, err, &description)); | 1551 base::Bind(&NetLogSpdySessionCloseCallback, err, &description)); |
1550 | 1552 |
1551 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SpdySession.ClosedOnError", -err); | 1553 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.SpdySession.ClosedOnError", -err); |
1552 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySession.BytesRead.OtherErrors", | 1554 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.SpdySession.BytesRead.OtherErrors", |
1553 total_bytes_received_, 1, 100000000, 50); | 1555 total_bytes_received_, 1, 100000000, 50); |
1554 | 1556 |
1555 DCHECK(pool_); | 1557 // |pool_| will be NULL when |InitializeWithSocket()| is in the |
1556 if (availability_state_ != STATE_GOING_AWAY) | 1558 // call stack. |
| 1559 if (pool_ && availability_state_ != STATE_GOING_AWAY) |
1557 pool_->MakeSessionUnavailable(GetWeakPtr()); | 1560 pool_->MakeSessionUnavailable(GetWeakPtr()); |
1558 | 1561 |
1559 availability_state_ = STATE_CLOSED; | 1562 availability_state_ = STATE_CLOSED; |
1560 error_on_close_ = err; | 1563 error_on_close_ = err; |
1561 | 1564 |
1562 StartGoingAway(0, err); | 1565 StartGoingAway(0, err); |
1563 write_queue_.Clear(); | 1566 write_queue_.Clear(); |
1564 | 1567 |
1565 DcheckClosed(); | 1568 DcheckClosed(); |
1566 | 1569 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1618 void SpdySession::CloseSessionOnError(Error err, | 1621 void SpdySession::CloseSessionOnError(Error err, |
1619 const std::string& description) { | 1622 const std::string& description) { |
1620 // We may be called from anywhere, so we can't expect a particular | 1623 // We may be called from anywhere, so we can't expect a particular |
1621 // return value. | 1624 // return value. |
1622 ignore_result(DoCloseSession(err, description)); | 1625 ignore_result(DoCloseSession(err, description)); |
1623 } | 1626 } |
1624 | 1627 |
1625 void SpdySession::MakeUnavailable() { | 1628 void SpdySession::MakeUnavailable() { |
1626 if (availability_state_ < STATE_GOING_AWAY) { | 1629 if (availability_state_ < STATE_GOING_AWAY) { |
1627 availability_state_ = STATE_GOING_AWAY; | 1630 availability_state_ = STATE_GOING_AWAY; |
1628 DCHECK(pool_); | 1631 // |pool_| will be NULL when |InitializeWithSocket()| is in the |
1629 pool_->MakeSessionUnavailable(GetWeakPtr()); | 1632 // call stack. |
| 1633 if (pool_) |
| 1634 pool_->MakeSessionUnavailable(GetWeakPtr()); |
1630 } | 1635 } |
1631 } | 1636 } |
1632 | 1637 |
1633 base::Value* SpdySession::GetInfoAsValue() const { | 1638 base::Value* SpdySession::GetInfoAsValue() const { |
1634 base::DictionaryValue* dict = new base::DictionaryValue(); | 1639 base::DictionaryValue* dict = new base::DictionaryValue(); |
1635 | 1640 |
1636 dict->SetInteger("source_id", net_log_.source().id); | 1641 dict->SetInteger("source_id", net_log_.source().id); |
1637 | 1642 |
1638 dict->SetString("host_port_pair", host_port_pair().ToString()); | 1643 dict->SetString("host_port_pair", host_port_pair().ToString()); |
1639 if (!pooled_aliases_.empty()) { | 1644 if (!pooled_aliases_.empty()) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 dict->SetBoolean("received_settings", received_settings_); | 1679 dict->SetBoolean("received_settings", received_settings_); |
1675 | 1680 |
1676 dict->SetInteger("send_window_size", session_send_window_size_); | 1681 dict->SetInteger("send_window_size", session_send_window_size_); |
1677 dict->SetInteger("recv_window_size", session_recv_window_size_); | 1682 dict->SetInteger("recv_window_size", session_recv_window_size_); |
1678 dict->SetInteger("unacked_recv_window_bytes", | 1683 dict->SetInteger("unacked_recv_window_bytes", |
1679 session_unacked_recv_window_bytes_); | 1684 session_unacked_recv_window_bytes_); |
1680 return dict; | 1685 return dict; |
1681 } | 1686 } |
1682 | 1687 |
1683 bool SpdySession::IsReused() const { | 1688 bool SpdySession::IsReused() const { |
1684 return buffered_spdy_framer_->frames_received() > 0 || | 1689 return buffered_spdy_framer_->frames_received() > 0; |
1685 connection_->reuse_type() == ClientSocketHandle::UNUSED_IDLE; | |
1686 } | 1690 } |
1687 | 1691 |
1688 bool SpdySession::GetLoadTimingInfo(SpdyStreamId stream_id, | 1692 bool SpdySession::GetLoadTimingInfo(SpdyStreamId stream_id, |
1689 LoadTimingInfo* load_timing_info) const { | 1693 LoadTimingInfo* load_timing_info) const { |
1690 return connection_->GetLoadTimingInfo(stream_id != kFirstStreamId, | 1694 return connection_->GetLoadTimingInfo(stream_id != kFirstStreamId, |
1691 load_timing_info); | 1695 load_timing_info); |
1692 } | 1696 } |
1693 | 1697 |
1694 int SpdySession::GetPeerAddress(IPEndPoint* address) const { | 1698 int SpdySession::GetPeerAddress(IPEndPoint* address) const { |
1695 int rv = ERR_SOCKET_NOT_CONNECTED; | 1699 int rv = ERR_SOCKET_NOT_CONNECTED; |
(...skipping 1347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3043 if (!queue->empty()) { | 3047 if (!queue->empty()) { |
3044 SpdyStreamId stream_id = queue->front(); | 3048 SpdyStreamId stream_id = queue->front(); |
3045 queue->pop_front(); | 3049 queue->pop_front(); |
3046 return stream_id; | 3050 return stream_id; |
3047 } | 3051 } |
3048 } | 3052 } |
3049 return 0; | 3053 return 0; |
3050 } | 3054 } |
3051 | 3055 |
3052 } // namespace net | 3056 } // namespace net |
OLD | NEW |