| 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/chromium/quic_chromium_client_session.h" | 5 #include "net/quic/chromium/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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 QuicCryptoClientConfig* crypto_config, | 243 QuicCryptoClientConfig* crypto_config, |
| 244 const char* const connection_description, | 244 const char* const connection_description, |
| 245 base::TimeTicks dns_resolution_start_time, | 245 base::TimeTicks dns_resolution_start_time, |
| 246 base::TimeTicks dns_resolution_end_time, | 246 base::TimeTicks dns_resolution_end_time, |
| 247 QuicClientPushPromiseIndex* push_promise_index, | 247 QuicClientPushPromiseIndex* push_promise_index, |
| 248 ServerPushDelegate* push_delegate, | 248 ServerPushDelegate* push_delegate, |
| 249 base::TaskRunner* task_runner, | 249 base::TaskRunner* task_runner, |
| 250 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, | 250 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher, |
| 251 NetLog* net_log) | 251 NetLog* net_log) |
| 252 : QuicClientSessionBase(connection, push_promise_index, config), | 252 : QuicClientSessionBase(connection, push_promise_index, config), |
| 253 received_go_away_(false), |
| 254 received_read_error_(false), |
| 255 connection_closed_(false), |
| 256 notified_session_going_away_(false), |
| 257 notified_session_closed_later_(false), |
| 258 notified_session_closed_(false), |
| 253 server_id_(server_id), | 259 server_id_(server_id), |
| 254 require_confirmation_(require_confirmation), | 260 require_confirmation_(require_confirmation), |
| 255 stream_factory_(stream_factory), | 261 stream_factory_(stream_factory), |
| 256 transport_security_state_(transport_security_state), | 262 transport_security_state_(transport_security_state), |
| 257 server_info_(std::move(server_info)), | 263 server_info_(std::move(server_info)), |
| 258 pkp_bypassed_(false), | 264 pkp_bypassed_(false), |
| 259 num_total_streams_(0), | 265 num_total_streams_(0), |
| 260 task_runner_(task_runner), | 266 task_runner_(task_runner), |
| 261 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::QUIC_SESSION)), | 267 net_log_(NetLogWithSource::Make(net_log, NetLogSourceType::QUIC_SESSION)), |
| 262 logger_(new QuicConnectionLogger(this, | 268 logger_(new QuicConnectionLogger(this, |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 919 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.RejectLength", | 925 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.RejectLength", |
| 920 message.GetSerialized().length(), 1000, 10000, | 926 message.GetSerialized().length(), 1000, 10000, |
| 921 50); | 927 50); |
| 922 base::StringPiece proof; | 928 base::StringPiece proof; |
| 923 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.RejectHasProof", | 929 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.RejectHasProof", |
| 924 message.GetStringPiece(kPROF, &proof)); | 930 message.GetStringPiece(kPROF, &proof)); |
| 925 } | 931 } |
| 926 } | 932 } |
| 927 | 933 |
| 928 void QuicChromiumClientSession::OnGoAway(const QuicGoAwayFrame& frame) { | 934 void QuicChromiumClientSession::OnGoAway(const QuicGoAwayFrame& frame) { |
| 935 received_go_away_ = true; |
| 929 QuicSession::OnGoAway(frame); | 936 QuicSession::OnGoAway(frame); |
| 930 NotifyFactoryOfSessionGoingAway(); | 937 NotifyFactoryOfSessionGoingAway(); |
| 931 port_migration_detected_ = frame.error_code == QUIC_ERROR_MIGRATING_PORT; | 938 port_migration_detected_ = frame.error_code == QUIC_ERROR_MIGRATING_PORT; |
| 932 } | 939 } |
| 933 | 940 |
| 934 void QuicChromiumClientSession::OnRstStream(const QuicRstStreamFrame& frame) { | 941 void QuicChromiumClientSession::OnRstStream(const QuicRstStreamFrame& frame) { |
| 935 QuicSession::OnRstStream(frame); | 942 QuicSession::OnRstStream(frame); |
| 936 OnClosedStream(); | 943 OnClosedStream(); |
| 937 } | 944 } |
| 938 | 945 |
| 939 void QuicChromiumClientSession::OnConnectionClosed( | 946 void QuicChromiumClientSession::OnConnectionClosed( |
| 940 QuicErrorCode error, | 947 QuicErrorCode error, |
| 941 const std::string& error_details, | 948 const std::string& error_details, |
| 942 ConnectionCloseSource source) { | 949 ConnectionCloseSource source) { |
| 950 connection_closed_ = true; |
| 943 DCHECK(!connection()->connected()); | 951 DCHECK(!connection()->connected()); |
| 944 logger_->OnConnectionClosed(error, error_details, source); | 952 logger_->OnConnectionClosed(error, error_details, source); |
| 945 if (source == ConnectionCloseSource::FROM_PEER) { | 953 if (source == ConnectionCloseSource::FROM_PEER) { |
| 946 if (IsCryptoHandshakeConfirmed()) { | 954 if (IsCryptoHandshakeConfirmed()) { |
| 947 UMA_HISTOGRAM_SPARSE_SLOWLY( | 955 UMA_HISTOGRAM_SPARSE_SLOWLY( |
| 948 "Net.QuicSession.ConnectionCloseErrorCodeServer.HandshakeConfirmed", | 956 "Net.QuicSession.ConnectionCloseErrorCodeServer.HandshakeConfirmed", |
| 949 error); | 957 error); |
| 950 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( | 958 base::HistogramBase* histogram = base::SparseHistogram::FactoryGet( |
| 951 "Net.QuicSession.StreamCloseErrorCodeServer.HandshakeConfirmed", | 959 "Net.QuicSession.StreamCloseErrorCodeServer.HandshakeConfirmed", |
| 952 base::HistogramBase::kUmaTargetedHistogramFlag); | 960 base::HistogramBase::kUmaTargetedHistogramFlag); |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1329 } | 1337 } |
| 1330 | 1338 |
| 1331 base::WeakPtr<QuicChromiumClientSession> | 1339 base::WeakPtr<QuicChromiumClientSession> |
| 1332 QuicChromiumClientSession::GetWeakPtr() { | 1340 QuicChromiumClientSession::GetWeakPtr() { |
| 1333 return weak_factory_.GetWeakPtr(); | 1341 return weak_factory_.GetWeakPtr(); |
| 1334 } | 1342 } |
| 1335 | 1343 |
| 1336 void QuicChromiumClientSession::OnReadError( | 1344 void QuicChromiumClientSession::OnReadError( |
| 1337 int result, | 1345 int result, |
| 1338 const DatagramClientSocket* socket) { | 1346 const DatagramClientSocket* socket) { |
| 1347 received_read_error_ = true; |
| 1339 DCHECK(socket != nullptr); | 1348 DCHECK(socket != nullptr); |
| 1340 if (socket != GetDefaultSocket()) { | 1349 if (socket != GetDefaultSocket()) { |
| 1341 // Ignore read errors from old sockets that are no longer active. | 1350 // Ignore read errors from old sockets that are no longer active. |
| 1342 // TODO(jri): Maybe clean up old sockets on error. | 1351 // TODO(jri): Maybe clean up old sockets on error. |
| 1343 return; | 1352 return; |
| 1344 } | 1353 } |
| 1345 DVLOG(1) << "Closing session on read error: " << result; | 1354 DVLOG(1) << "Closing session on read error: " << result; |
| 1346 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.ReadError", -result); | 1355 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.ReadError", -result); |
| 1347 NotifyFactoryOfSessionGoingAway(); | 1356 NotifyFactoryOfSessionGoingAway(); |
| 1348 CloseSessionOnErrorInner(result, QUIC_PACKET_READ_ERROR); | 1357 CloseSessionOnErrorInner(result, QUIC_PACKET_READ_ERROR); |
| 1349 NotifyFactoryOfSessionClosedLater(); | 1358 NotifyFactoryOfSessionClosedLater(); |
| 1350 } | 1359 } |
| 1351 | 1360 |
| 1352 bool QuicChromiumClientSession::OnPacket(const QuicReceivedPacket& packet, | 1361 bool QuicChromiumClientSession::OnPacket(const QuicReceivedPacket& packet, |
| 1353 IPEndPoint local_address, | 1362 IPEndPoint local_address, |
| 1354 IPEndPoint peer_address) { | 1363 IPEndPoint peer_address) { |
| 1355 ProcessUdpPacket(QuicSocketAddress(QuicSocketAddressImpl(local_address)), | 1364 ProcessUdpPacket(QuicSocketAddress(QuicSocketAddressImpl(local_address)), |
| 1356 QuicSocketAddress(QuicSocketAddressImpl(peer_address)), | 1365 QuicSocketAddress(QuicSocketAddressImpl(peer_address)), |
| 1357 packet); | 1366 packet); |
| 1358 if (!connection()->connected()) { | 1367 if (!connection()->connected()) { |
| 1359 NotifyFactoryOfSessionClosedLater(); | 1368 NotifyFactoryOfSessionClosedLater(); |
| 1360 return false; | 1369 return false; |
| 1361 } | 1370 } |
| 1362 return true; | 1371 return true; |
| 1363 } | 1372 } |
| 1364 | 1373 |
| 1365 void QuicChromiumClientSession::NotifyFactoryOfSessionGoingAway() { | 1374 void QuicChromiumClientSession::NotifyFactoryOfSessionGoingAway() { |
| 1375 notified_session_going_away_ = true; |
| 1366 going_away_ = true; | 1376 going_away_ = true; |
| 1367 if (stream_factory_) | 1377 if (stream_factory_) |
| 1368 stream_factory_->OnSessionGoingAway(this); | 1378 stream_factory_->OnSessionGoingAway(this); |
| 1369 } | 1379 } |
| 1370 | 1380 |
| 1371 void QuicChromiumClientSession::NotifyFactoryOfSessionClosedLater() { | 1381 void QuicChromiumClientSession::NotifyFactoryOfSessionClosedLater() { |
| 1382 notified_session_closed_later_ = true; |
| 1372 if (!dynamic_streams().empty()) | 1383 if (!dynamic_streams().empty()) |
| 1373 RecordUnexpectedOpenStreams(NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER); | 1384 RecordUnexpectedOpenStreams(NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER); |
| 1374 | 1385 |
| 1375 if (!going_away_) | 1386 if (!going_away_) |
| 1376 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER); | 1387 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER); |
| 1377 | 1388 |
| 1378 going_away_ = true; | 1389 going_away_ = true; |
| 1379 DCHECK_EQ(0u, GetNumActiveStreams()); | 1390 DCHECK_EQ(0u, GetNumActiveStreams()); |
| 1380 DCHECK(!connection()->connected()); | 1391 DCHECK(!connection()->connected()); |
| 1381 base::ThreadTaskRunnerHandle::Get()->PostTask( | 1392 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 1382 FROM_HERE, | 1393 FROM_HERE, |
| 1383 base::Bind(&QuicChromiumClientSession::NotifyFactoryOfSessionClosed, | 1394 base::Bind(&QuicChromiumClientSession::NotifyFactoryOfSessionClosed, |
| 1384 weak_factory_.GetWeakPtr())); | 1395 weak_factory_.GetWeakPtr())); |
| 1385 } | 1396 } |
| 1386 | 1397 |
| 1387 void QuicChromiumClientSession::NotifyFactoryOfSessionClosed() { | 1398 void QuicChromiumClientSession::NotifyFactoryOfSessionClosed() { |
| 1399 notified_session_closed_ = true; |
| 1388 if (!dynamic_streams().empty()) | 1400 if (!dynamic_streams().empty()) |
| 1389 RecordUnexpectedOpenStreams(NOTIFY_FACTORY_OF_SESSION_CLOSED); | 1401 RecordUnexpectedOpenStreams(NOTIFY_FACTORY_OF_SESSION_CLOSED); |
| 1390 | 1402 |
| 1391 if (!going_away_) | 1403 if (!going_away_) |
| 1392 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); | 1404 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); |
| 1393 | 1405 |
| 1394 going_away_ = true; | 1406 going_away_ = true; |
| 1395 DCHECK_EQ(0u, GetNumActiveStreams()); | 1407 DCHECK_EQ(0u, GetNumActiveStreams()); |
| 1396 // Will delete |this|. | 1408 // Will delete |this|. |
| 1397 if (stream_factory_) | 1409 if (stream_factory_) |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1520 } | 1532 } |
| 1521 | 1533 |
| 1522 size_t QuicChromiumClientSession::EstimateMemoryUsage() const { | 1534 size_t QuicChromiumClientSession::EstimateMemoryUsage() const { |
| 1523 // TODO(xunjieli): Estimate |crypto_stream_|, QuicSpdySession's | 1535 // TODO(xunjieli): Estimate |crypto_stream_|, QuicSpdySession's |
| 1524 // QuicHeaderList, QuicSession's QuiCWriteBlockedList, open streams and | 1536 // QuicHeaderList, QuicSession's QuiCWriteBlockedList, open streams and |
| 1525 // unacked packet map. | 1537 // unacked packet map. |
| 1526 return base::trace_event::EstimateMemoryUsage(packet_readers_); | 1538 return base::trace_event::EstimateMemoryUsage(packet_readers_); |
| 1527 } | 1539 } |
| 1528 | 1540 |
| 1529 } // namespace net | 1541 } // namespace net |
| OLD | NEW |