| 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" |
| 11 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
| 12 #include "base/metrics/sparse_histogram.h" | 12 #include "base/metrics/sparse_histogram.h" |
| 13 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/values.h" | 17 #include "base/values.h" |
| 18 #include "net/base/io_buffer.h" | 18 #include "net/base/io_buffer.h" |
| 19 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 20 #include "net/base/network_activity_monitor.h" | 20 #include "net/base/network_activity_monitor.h" |
| 21 #include "net/http/transport_security_state.h" | 21 #include "net/http/transport_security_state.h" |
| 22 #include "net/quic/crypto/proof_verifier_chromium.h" | 22 #include "net/quic/crypto/proof_verifier_chromium.h" |
| 23 #include "net/quic/crypto/quic_server_info.h" | 23 #include "net/quic/crypto/quic_server_info.h" |
| 24 #include "net/quic/quic_connection_helper.h" | 24 #include "net/quic/quic_chromium_connection_helper.h" |
| 25 #include "net/quic/quic_crypto_client_stream_factory.h" | 25 #include "net/quic/quic_crypto_client_stream_factory.h" |
| 26 #include "net/quic/quic_server_id.h" | 26 #include "net/quic/quic_server_id.h" |
| 27 #include "net/quic/quic_stream_factory.h" | 27 #include "net/quic/quic_stream_factory.h" |
| 28 #include "net/spdy/spdy_session.h" | 28 #include "net/spdy/spdy_session.h" |
| 29 #include "net/ssl/channel_id_service.h" | 29 #include "net/ssl/channel_id_service.h" |
| 30 #include "net/ssl/ssl_connection_status_flags.h" | 30 #include "net/ssl/ssl_connection_status_flags.h" |
| 31 #include "net/ssl/ssl_info.h" | 31 #include "net/ssl/ssl_info.h" |
| 32 #include "net/udp/datagram_client_socket.h" | 32 #include "net/udp/datagram_client_socket.h" |
| 33 | 33 |
| 34 namespace net { | 34 namespace net { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } // namespace | 123 } // namespace |
| 124 | 124 |
| 125 QuicChromiumClientSession::StreamRequest::StreamRequest() : stream_(nullptr) {} | 125 QuicChromiumClientSession::StreamRequest::StreamRequest() : stream_(nullptr) {} |
| 126 | 126 |
| 127 QuicChromiumClientSession::StreamRequest::~StreamRequest() { | 127 QuicChromiumClientSession::StreamRequest::~StreamRequest() { |
| 128 CancelRequest(); | 128 CancelRequest(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 int QuicChromiumClientSession::StreamRequest::StartRequest( | 131 int QuicChromiumClientSession::StreamRequest::StartRequest( |
| 132 const base::WeakPtr<QuicChromiumClientSession>& session, | 132 const base::WeakPtr<QuicChromiumClientSession>& session, |
| 133 QuicReliableClientStream** stream, | 133 QuicChromiumClientStream** stream, |
| 134 const CompletionCallback& callback) { | 134 const CompletionCallback& callback) { |
| 135 session_ = session; | 135 session_ = session; |
| 136 stream_ = stream; | 136 stream_ = stream; |
| 137 int rv = session_->TryCreateStream(this, stream_); | 137 int rv = session_->TryCreateStream(this, stream_); |
| 138 if (rv == ERR_IO_PENDING) { | 138 if (rv == ERR_IO_PENDING) { |
| 139 callback_ = callback; | 139 callback_ = callback; |
| 140 } | 140 } |
| 141 | 141 |
| 142 return rv; | 142 return rv; |
| 143 } | 143 } |
| 144 | 144 |
| 145 void QuicChromiumClientSession::StreamRequest::CancelRequest() { | 145 void QuicChromiumClientSession::StreamRequest::CancelRequest() { |
| 146 if (session_) | 146 if (session_) |
| 147 session_->CancelRequest(this); | 147 session_->CancelRequest(this); |
| 148 session_.reset(); | 148 session_.reset(); |
| 149 callback_.Reset(); | 149 callback_.Reset(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteSuccess( | 152 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteSuccess( |
| 153 QuicReliableClientStream* stream) { | 153 QuicChromiumClientStream* stream) { |
| 154 session_.reset(); | 154 session_.reset(); |
| 155 *stream_ = stream; | 155 *stream_ = stream; |
| 156 ResetAndReturn(&callback_).Run(OK); | 156 ResetAndReturn(&callback_).Run(OK); |
| 157 } | 157 } |
| 158 | 158 |
| 159 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure( | 159 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure( |
| 160 int rv) { | 160 int rv) { |
| 161 session_.reset(); | 161 session_.reset(); |
| 162 ResetAndReturn(&callback_).Run(rv); | 162 ResetAndReturn(&callback_).Run(rv); |
| 163 } | 163 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 observers_.insert(observer); | 366 observers_.insert(observer); |
| 367 } | 367 } |
| 368 | 368 |
| 369 void QuicChromiumClientSession::RemoveObserver(Observer* observer) { | 369 void QuicChromiumClientSession::RemoveObserver(Observer* observer) { |
| 370 DCHECK(ContainsKey(observers_, observer)); | 370 DCHECK(ContainsKey(observers_, observer)); |
| 371 observers_.erase(observer); | 371 observers_.erase(observer); |
| 372 } | 372 } |
| 373 | 373 |
| 374 int QuicChromiumClientSession::TryCreateStream( | 374 int QuicChromiumClientSession::TryCreateStream( |
| 375 StreamRequest* request, | 375 StreamRequest* request, |
| 376 QuicReliableClientStream** stream) { | 376 QuicChromiumClientStream** stream) { |
| 377 if (!crypto_stream_->encryption_established()) { | 377 if (!crypto_stream_->encryption_established()) { |
| 378 DLOG(DFATAL) << "Encryption not established."; | 378 DLOG(DFATAL) << "Encryption not established."; |
| 379 return ERR_CONNECTION_CLOSED; | 379 return ERR_CONNECTION_CLOSED; |
| 380 } | 380 } |
| 381 | 381 |
| 382 if (goaway_received()) { | 382 if (goaway_received()) { |
| 383 DVLOG(1) << "Going away."; | 383 DVLOG(1) << "Going away."; |
| 384 return ERR_CONNECTION_CLOSED; | 384 return ERR_CONNECTION_CLOSED; |
| 385 } | 385 } |
| 386 | 386 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 406 void QuicChromiumClientSession::CancelRequest(StreamRequest* request) { | 406 void QuicChromiumClientSession::CancelRequest(StreamRequest* request) { |
| 407 // Remove |request| from the queue while preserving the order of the | 407 // Remove |request| from the queue while preserving the order of the |
| 408 // other elements. | 408 // other elements. |
| 409 StreamRequestQueue::iterator it = | 409 StreamRequestQueue::iterator it = |
| 410 std::find(stream_requests_.begin(), stream_requests_.end(), request); | 410 std::find(stream_requests_.begin(), stream_requests_.end(), request); |
| 411 if (it != stream_requests_.end()) { | 411 if (it != stream_requests_.end()) { |
| 412 it = stream_requests_.erase(it); | 412 it = stream_requests_.erase(it); |
| 413 } | 413 } |
| 414 } | 414 } |
| 415 | 415 |
| 416 QuicReliableClientStream* | 416 QuicChromiumClientStream* |
| 417 QuicChromiumClientSession::CreateOutgoingDynamicStream(SpdyPriority priority) { | 417 QuicChromiumClientSession::CreateOutgoingDynamicStream(SpdyPriority priority) { |
| 418 if (!crypto_stream_->encryption_established()) { | 418 if (!crypto_stream_->encryption_established()) { |
| 419 DVLOG(1) << "Encryption not active so no outgoing stream created."; | 419 DVLOG(1) << "Encryption not active so no outgoing stream created."; |
| 420 return nullptr; | 420 return nullptr; |
| 421 } | 421 } |
| 422 if (GetNumOpenOutgoingStreams() >= get_max_open_streams()) { | 422 if (GetNumOpenOutgoingStreams() >= get_max_open_streams()) { |
| 423 DVLOG(1) << "Failed to create a new outgoing stream. " | 423 DVLOG(1) << "Failed to create a new outgoing stream. " |
| 424 << "Already " << GetNumOpenOutgoingStreams() << " open."; | 424 << "Already " << GetNumOpenOutgoingStreams() << " open."; |
| 425 return nullptr; | 425 return nullptr; |
| 426 } | 426 } |
| 427 if (goaway_received()) { | 427 if (goaway_received()) { |
| 428 DVLOG(1) << "Failed to create a new outgoing stream. " | 428 DVLOG(1) << "Failed to create a new outgoing stream. " |
| 429 << "Already received goaway."; | 429 << "Already received goaway."; |
| 430 return nullptr; | 430 return nullptr; |
| 431 } | 431 } |
| 432 if (going_away_) { | 432 if (going_away_) { |
| 433 RecordUnexpectedOpenStreams(CREATE_OUTGOING_RELIABLE_STREAM); | 433 RecordUnexpectedOpenStreams(CREATE_OUTGOING_RELIABLE_STREAM); |
| 434 return nullptr; | 434 return nullptr; |
| 435 } | 435 } |
| 436 return CreateOutgoingReliableStreamImpl(); | 436 return CreateOutgoingReliableStreamImpl(); |
| 437 } | 437 } |
| 438 | 438 |
| 439 QuicReliableClientStream* | 439 QuicChromiumClientStream* |
| 440 QuicChromiumClientSession::CreateOutgoingReliableStreamImpl() { | 440 QuicChromiumClientSession::CreateOutgoingReliableStreamImpl() { |
| 441 DCHECK(connection()->connected()); | 441 DCHECK(connection()->connected()); |
| 442 QuicReliableClientStream* stream = | 442 QuicChromiumClientStream* stream = |
| 443 new QuicReliableClientStream(GetNextOutgoingStreamId(), this, net_log_); | 443 new QuicChromiumClientStream(GetNextOutgoingStreamId(), this, net_log_); |
| 444 ActivateStream(stream); | 444 ActivateStream(stream); |
| 445 ++num_total_streams_; | 445 ++num_total_streams_; |
| 446 UMA_HISTOGRAM_COUNTS("Net.QuicSession.NumOpenStreams", | 446 UMA_HISTOGRAM_COUNTS("Net.QuicSession.NumOpenStreams", |
| 447 GetNumOpenOutgoingStreams()); | 447 GetNumOpenOutgoingStreams()); |
| 448 // The previous histogram puts 100 in a bucket betweeen 86-113 which does | 448 // The previous histogram puts 100 in a bucket betweeen 86-113 which does |
| 449 // not shed light on if chrome ever things it has more than 100 streams open. | 449 // not shed light on if chrome ever things it has more than 100 streams open. |
| 450 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.TooManyOpenStreams", | 450 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.TooManyOpenStreams", |
| 451 GetNumOpenOutgoingStreams() > 100); | 451 GetNumOpenOutgoingStreams() > 100); |
| 452 return stream; | 452 return stream; |
| 453 } | 453 } |
| (...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 | 862 |
| 863 if (connection()->connected()) | 863 if (connection()->connected()) |
| 864 connection()->CloseConnection(quic_error, false); | 864 connection()->CloseConnection(quic_error, false); |
| 865 DCHECK(!connection()->connected()); | 865 DCHECK(!connection()->connected()); |
| 866 } | 866 } |
| 867 | 867 |
| 868 void QuicChromiumClientSession::CloseAllStreams(int net_error) { | 868 void QuicChromiumClientSession::CloseAllStreams(int net_error) { |
| 869 while (!dynamic_streams().empty()) { | 869 while (!dynamic_streams().empty()) { |
| 870 ReliableQuicStream* stream = dynamic_streams().begin()->second; | 870 ReliableQuicStream* stream = dynamic_streams().begin()->second; |
| 871 QuicStreamId id = stream->id(); | 871 QuicStreamId id = stream->id(); |
| 872 static_cast<QuicReliableClientStream*>(stream)->OnError(net_error); | 872 static_cast<QuicChromiumClientStream*>(stream)->OnError(net_error); |
| 873 CloseStream(id); | 873 CloseStream(id); |
| 874 } | 874 } |
| 875 } | 875 } |
| 876 | 876 |
| 877 void QuicChromiumClientSession::CloseAllObservers(int net_error) { | 877 void QuicChromiumClientSession::CloseAllObservers(int net_error) { |
| 878 while (!observers_.empty()) { | 878 while (!observers_.empty()) { |
| 879 Observer* observer = *observers_.begin(); | 879 Observer* observer = *observers_.begin(); |
| 880 observers_.erase(observer); | 880 observers_.erase(observer); |
| 881 observer->OnSessionClosed(net_error); | 881 observer->OnSessionClosed(net_error); |
| 882 } | 882 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 const DatagramClientSocket* QuicChromiumClientSession::GetDefaultSocket() | 1019 const DatagramClientSocket* QuicChromiumClientSession::GetDefaultSocket() |
| 1020 const { | 1020 const { |
| 1021 DCHECK(sockets_.back().get() != nullptr); | 1021 DCHECK(sockets_.back().get() != nullptr); |
| 1022 // The most recently added socket is the currently active one. | 1022 // The most recently added socket is the currently active one. |
| 1023 return sockets_.back().get(); | 1023 return sockets_.back().get(); |
| 1024 } | 1024 } |
| 1025 | 1025 |
| 1026 } // namespace net | 1026 } // namespace net |
| OLD | NEW |