| 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/quic/quic_chromium_client_session.h" | 5 #include "net/quic/quic_chromium_client_session.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 server_info_(std::move(server_info)), | 198 server_info_(std::move(server_info)), |
| 199 num_total_streams_(0), | 199 num_total_streams_(0), |
| 200 task_runner_(task_runner), | 200 task_runner_(task_runner), |
| 201 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), | 201 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), |
| 202 dns_resolution_end_time_(dns_resolution_end_time), | 202 dns_resolution_end_time_(dns_resolution_end_time), |
| 203 logger_(new QuicConnectionLogger(this, | 203 logger_(new QuicConnectionLogger(this, |
| 204 connection_description, | 204 connection_description, |
| 205 std::move(socket_performance_watcher), | 205 std::move(socket_performance_watcher), |
| 206 net_log_)), | 206 net_log_)), |
| 207 going_away_(false), | 207 going_away_(false), |
| 208 port_migration_detected_(false), |
| 208 disabled_reason_(QUIC_DISABLED_NOT), | 209 disabled_reason_(QUIC_DISABLED_NOT), |
| 209 token_binding_signatures_(kTokenBindingSignatureMapSize), | 210 token_binding_signatures_(kTokenBindingSignatureMapSize), |
| 210 weak_factory_(this) { | 211 weak_factory_(this) { |
| 211 sockets_.push_back(std::move(socket)); | 212 sockets_.push_back(std::move(socket)); |
| 212 packet_readers_.push_back(make_scoped_ptr(new QuicChromiumPacketReader( | 213 packet_readers_.push_back(make_scoped_ptr(new QuicChromiumPacketReader( |
| 213 sockets_.back().get(), clock, this, yield_after_packets, | 214 sockets_.back().get(), clock, this, yield_after_packets, |
| 214 yield_after_duration, net_log_))); | 215 yield_after_duration, net_log_))); |
| 215 crypto_stream_.reset( | 216 crypto_stream_.reset( |
| 216 crypto_client_stream_factory->CreateQuicCryptoClientStream( | 217 crypto_client_stream_factory->CreateQuicCryptoClientStream( |
| 217 server_id, this, make_scoped_ptr(new ProofVerifyContextChromium( | 218 server_id, this, make_scoped_ptr(new ProofVerifyContextChromium( |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 364 |
| 364 // Record number of frames per stream in packet. | 365 // Record number of frames per stream in packet. |
| 365 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesPerStreamInPacket", 1); | 366 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesPerStreamInPacket", 1); |
| 366 | 367 |
| 367 return QuicSpdySession::OnStreamFrame(frame); | 368 return QuicSpdySession::OnStreamFrame(frame); |
| 368 } | 369 } |
| 369 | 370 |
| 370 void QuicChromiumClientSession::AddObserver(Observer* observer) { | 371 void QuicChromiumClientSession::AddObserver(Observer* observer) { |
| 371 if (going_away_) { | 372 if (going_away_) { |
| 372 RecordUnexpectedObservers(ADD_OBSERVER); | 373 RecordUnexpectedObservers(ADD_OBSERVER); |
| 373 observer->OnSessionClosed(ERR_UNEXPECTED); | 374 observer->OnSessionClosed(ERR_UNEXPECTED, port_migration_detected_); |
| 374 return; | 375 return; |
| 375 } | 376 } |
| 376 | 377 |
| 377 DCHECK(!ContainsKey(observers_, observer)); | 378 DCHECK(!ContainsKey(observers_, observer)); |
| 378 observers_.insert(observer); | 379 observers_.insert(observer); |
| 379 } | 380 } |
| 380 | 381 |
| 381 void QuicChromiumClientSession::RemoveObserver(Observer* observer) { | 382 void QuicChromiumClientSession::RemoveObserver(Observer* observer) { |
| 382 DCHECK(ContainsKey(observers_, observer)); | 383 DCHECK(ContainsKey(observers_, observer)); |
| 383 observers_.erase(observer); | 384 observers_.erase(observer); |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 753 } | 754 } |
| 754 | 755 |
| 755 void QuicChromiumClientSession::OnCryptoHandshakeMessageReceived( | 756 void QuicChromiumClientSession::OnCryptoHandshakeMessageReceived( |
| 756 const CryptoHandshakeMessage& message) { | 757 const CryptoHandshakeMessage& message) { |
| 757 logger_->OnCryptoHandshakeMessageReceived(message); | 758 logger_->OnCryptoHandshakeMessageReceived(message); |
| 758 } | 759 } |
| 759 | 760 |
| 760 void QuicChromiumClientSession::OnGoAway(const QuicGoAwayFrame& frame) { | 761 void QuicChromiumClientSession::OnGoAway(const QuicGoAwayFrame& frame) { |
| 761 QuicSession::OnGoAway(frame); | 762 QuicSession::OnGoAway(frame); |
| 762 NotifyFactoryOfSessionGoingAway(); | 763 NotifyFactoryOfSessionGoingAway(); |
| 764 port_migration_detected_ = frame.error_code == QUIC_ERROR_MIGRATING_PORT; |
| 763 } | 765 } |
| 764 | 766 |
| 765 void QuicChromiumClientSession::OnRstStream(const QuicRstStreamFrame& frame) { | 767 void QuicChromiumClientSession::OnRstStream(const QuicRstStreamFrame& frame) { |
| 766 QuicSession::OnRstStream(frame); | 768 QuicSession::OnRstStream(frame); |
| 767 OnClosedStream(); | 769 OnClosedStream(); |
| 768 } | 770 } |
| 769 | 771 |
| 770 void QuicChromiumClientSession::OnConnectionClosed( | 772 void QuicChromiumClientSession::OnConnectionClosed( |
| 771 QuicErrorCode error, | 773 QuicErrorCode error, |
| 772 ConnectionCloseSource source) { | 774 ConnectionCloseSource source) { |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 QuicStreamId id = stream->id(); | 956 QuicStreamId id = stream->id(); |
| 955 static_cast<QuicChromiumClientStream*>(stream)->OnError(net_error); | 957 static_cast<QuicChromiumClientStream*>(stream)->OnError(net_error); |
| 956 CloseStream(id); | 958 CloseStream(id); |
| 957 } | 959 } |
| 958 } | 960 } |
| 959 | 961 |
| 960 void QuicChromiumClientSession::CloseAllObservers(int net_error) { | 962 void QuicChromiumClientSession::CloseAllObservers(int net_error) { |
| 961 while (!observers_.empty()) { | 963 while (!observers_.empty()) { |
| 962 Observer* observer = *observers_.begin(); | 964 Observer* observer = *observers_.begin(); |
| 963 observers_.erase(observer); | 965 observers_.erase(observer); |
| 964 observer->OnSessionClosed(net_error); | 966 observer->OnSessionClosed(net_error, port_migration_detected_); |
| 965 } | 967 } |
| 966 } | 968 } |
| 967 | 969 |
| 968 scoped_ptr<base::Value> QuicChromiumClientSession::GetInfoAsValue( | 970 scoped_ptr<base::Value> QuicChromiumClientSession::GetInfoAsValue( |
| 969 const std::set<HostPortPair>& aliases) { | 971 const std::set<HostPortPair>& aliases) { |
| 970 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 972 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 971 dict->SetString("version", QuicVersionToString(connection()->version())); | 973 dict->SetString("version", QuicVersionToString(connection()->version())); |
| 972 dict->SetInteger("open_streams", GetNumOpenOutgoingStreams()); | 974 dict->SetInteger("open_streams", GetNumOpenOutgoingStreams()); |
| 973 scoped_ptr<base::ListValue> stream_list(new base::ListValue()); | 975 scoped_ptr<base::ListValue> stream_list(new base::ListValue()); |
| 974 for (StreamMap::const_iterator it = dynamic_streams().begin(); | 976 for (StreamMap::const_iterator it = dynamic_streams().begin(); |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 } | 1093 } |
| 1092 // TODO(jri): Make SetQuicPacketWriter take a scoped_ptr. | 1094 // TODO(jri): Make SetQuicPacketWriter take a scoped_ptr. |
| 1093 connection()->SetQuicPacketWriter(writer.release(), /*owns_writer=*/true); | 1095 connection()->SetQuicPacketWriter(writer.release(), /*owns_writer=*/true); |
| 1094 packet_readers_.push_back(std::move(reader)); | 1096 packet_readers_.push_back(std::move(reader)); |
| 1095 sockets_.push_back(std::move(socket)); | 1097 sockets_.push_back(std::move(socket)); |
| 1096 StartReading(); | 1098 StartReading(); |
| 1097 connection()->SendPing(); | 1099 connection()->SendPing(); |
| 1098 return true; | 1100 return true; |
| 1099 } | 1101 } |
| 1100 | 1102 |
| 1103 void QuicChromiumClientSession::PopulateNetErrorDetails( |
| 1104 NetErrorDetails* details) { |
| 1105 details->quic_port_migration_detected = port_migration_detected_; |
| 1106 } |
| 1107 |
| 1101 const DatagramClientSocket* QuicChromiumClientSession::GetDefaultSocket() | 1108 const DatagramClientSocket* QuicChromiumClientSession::GetDefaultSocket() |
| 1102 const { | 1109 const { |
| 1103 DCHECK(sockets_.back().get() != nullptr); | 1110 DCHECK(sockets_.back().get() != nullptr); |
| 1104 // The most recently added socket is the currently active one. | 1111 // The most recently added socket is the currently active one. |
| 1105 return sockets_.back().get(); | 1112 return sockets_.back().get(); |
| 1106 } | 1113 } |
| 1107 | 1114 |
| 1108 bool QuicChromiumClientSession::IsAuthorized(const std::string& hostname) { | 1115 bool QuicChromiumClientSession::IsAuthorized(const std::string& hostname) { |
| 1109 return CanPool(hostname, server_id_.privacy_mode()); | 1116 return CanPool(hostname, server_id_.privacy_mode()); |
| 1110 } | 1117 } |
| 1111 | 1118 |
| 1112 bool QuicChromiumClientSession::HasNonMigratableStreams() const { | 1119 bool QuicChromiumClientSession::HasNonMigratableStreams() const { |
| 1113 for (const auto& stream : dynamic_streams()) { | 1120 for (const auto& stream : dynamic_streams()) { |
| 1114 if (!static_cast<QuicChromiumClientStream*>(stream.second)->can_migrate()) | 1121 if (!static_cast<QuicChromiumClientStream*>(stream.second)->can_migrate()) |
| 1115 return true; | 1122 return true; |
| 1116 } | 1123 } |
| 1117 return false; | 1124 return false; |
| 1118 } | 1125 } |
| 1119 | 1126 |
| 1120 } // namespace net | 1127 } // namespace net |
| OLD | NEW |