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_client_session.h" | 5 #include "net/quic/quic_client_session.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/metrics/histogram.h" |
9 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
10 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "net/base/io_buffer.h" | 13 #include "net/base/io_buffer.h" |
13 #include "net/base/net_errors.h" | 14 #include "net/base/net_errors.h" |
14 #include "net/quic/quic_connection_helper.h" | 15 #include "net/quic/quic_connection_helper.h" |
15 #include "net/quic/quic_crypto_client_stream_factory.h" | 16 #include "net/quic/quic_crypto_client_stream_factory.h" |
16 #include "net/quic/quic_stream_factory.h" | 17 #include "net/quic/quic_stream_factory.h" |
17 #include "net/udp/datagram_client_socket.h" | 18 #include "net/udp/datagram_client_socket.h" |
18 | 19 |
19 namespace net { | 20 namespace net { |
20 | 21 |
| 22 namespace { |
| 23 |
| 24 // Note: these values must be kept in sync with the corresponding values in: |
| 25 // tools/metrics/histograms/histograms.xml |
| 26 enum HandshakeState { |
| 27 STATE_STARTED = 0, |
| 28 STATE_ENCRYPTION_ESTABLISHED = 1, |
| 29 STATE_HANDSHAKE_CONFIRMED = 2, |
| 30 STATE_FAILED = 3, |
| 31 NUM_HANDSHAKE_STATES = 4 |
| 32 }; |
| 33 |
| 34 void RecordHandshakeState(HandshakeState state) { |
| 35 UMA_HISTOGRAM_ENUMERATION("Net.QuicHandshakeState", state, |
| 36 NUM_HANDSHAKE_STATES); |
| 37 } |
| 38 |
| 39 } // namespace |
| 40 |
21 QuicClientSession::QuicClientSession( | 41 QuicClientSession::QuicClientSession( |
22 QuicConnection* connection, | 42 QuicConnection* connection, |
23 DatagramClientSocket* socket, | 43 DatagramClientSocket* socket, |
24 QuicStreamFactory* stream_factory, | 44 QuicStreamFactory* stream_factory, |
25 QuicCryptoClientStreamFactory* crypto_client_stream_factory, | 45 QuicCryptoClientStreamFactory* crypto_client_stream_factory, |
26 const string& server_hostname, | 46 const string& server_hostname, |
27 const QuicConfig& config, | 47 const QuicConfig& config, |
28 QuicCryptoClientConfig* crypto_config, | 48 QuicCryptoClientConfig* crypto_config, |
29 NetLog* net_log) | 49 NetLog* net_log) |
30 : QuicSession(connection, config, false), | 50 : QuicSession(connection, config, false), |
(...skipping 15 matching lines...) Expand all Loading... |
46 // TODO(rch): pass in full host port proxy pair | 66 // TODO(rch): pass in full host port proxy pair |
47 net_log_.BeginEvent( | 67 net_log_.BeginEvent( |
48 NetLog::TYPE_QUIC_SESSION, | 68 NetLog::TYPE_QUIC_SESSION, |
49 NetLog::StringCallback("host", &server_hostname)); | 69 NetLog::StringCallback("host", &server_hostname)); |
50 } | 70 } |
51 | 71 |
52 QuicClientSession::~QuicClientSession() { | 72 QuicClientSession::~QuicClientSession() { |
53 DCHECK(callback_.is_null()); | 73 DCHECK(callback_.is_null()); |
54 connection()->set_debug_visitor(NULL); | 74 connection()->set_debug_visitor(NULL); |
55 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION); | 75 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION); |
| 76 |
| 77 if (IsEncryptionEstablished()) |
| 78 RecordHandshakeState(STATE_ENCRYPTION_ESTABLISHED); |
| 79 if (IsCryptoHandshakeConfirmed()) |
| 80 RecordHandshakeState(STATE_HANDSHAKE_CONFIRMED); |
| 81 else |
| 82 RecordHandshakeState(STATE_FAILED); |
| 83 |
| 84 UMA_HISTOGRAM_COUNTS("Net.QuicNumSentClientHellos", |
| 85 crypto_stream_->num_sent_client_hellos()); |
| 86 if (IsCryptoHandshakeConfirmed()) { |
| 87 UMA_HISTOGRAM_COUNTS("Net.QuicNumSentClientHellosCryptoHandshakeConfirmed", |
| 88 crypto_stream_->num_sent_client_hellos()); |
| 89 } |
56 } | 90 } |
57 | 91 |
58 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { | 92 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { |
59 if (!crypto_stream_->encryption_established()) { | 93 if (!crypto_stream_->encryption_established()) { |
60 DLOG(INFO) << "Encryption not active so no outgoing stream created."; | 94 DLOG(INFO) << "Encryption not active so no outgoing stream created."; |
61 return NULL; | 95 return NULL; |
62 } | 96 } |
63 if (GetNumOpenStreams() >= get_max_open_streams()) { | 97 if (GetNumOpenStreams() >= get_max_open_streams()) { |
64 DLOG(INFO) << "Failed to create a new outgoing stream. " | 98 DLOG(INFO) << "Failed to create a new outgoing stream. " |
65 << "Already " << GetNumOpenStreams() << " open."; | 99 << "Already " << GetNumOpenStreams() << " open."; |
66 return NULL; | 100 return NULL; |
67 } | 101 } |
68 if (goaway_received()) { | 102 if (goaway_received()) { |
69 DLOG(INFO) << "Failed to create a new outgoing stream. " | 103 DLOG(INFO) << "Failed to create a new outgoing stream. " |
70 << "Already received goaway."; | 104 << "Already received goaway."; |
71 return NULL; | 105 return NULL; |
72 } | 106 } |
73 QuicReliableClientStream* stream = | 107 QuicReliableClientStream* stream = |
74 new QuicReliableClientStream(GetNextStreamId(), this, net_log_); | 108 new QuicReliableClientStream(GetNextStreamId(), this, net_log_); |
75 ActivateStream(stream); | 109 ActivateStream(stream); |
76 ++num_total_streams_; | 110 ++num_total_streams_; |
77 return stream; | 111 return stream; |
78 } | 112 } |
79 | 113 |
80 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { | 114 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { |
81 return crypto_stream_.get(); | 115 return crypto_stream_.get(); |
82 }; | 116 }; |
83 | 117 |
84 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { | 118 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { |
| 119 RecordHandshakeState(STATE_STARTED); |
85 if (!crypto_stream_->CryptoConnect()) { | 120 if (!crypto_stream_->CryptoConnect()) { |
86 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a | 121 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a |
87 // QuicErrorCode and map it to a net error code. | 122 // QuicErrorCode and map it to a net error code. |
88 return ERR_CONNECTION_FAILED; | 123 return ERR_CONNECTION_FAILED; |
89 } | 124 } |
90 | 125 |
91 if (IsEncryptionEstablished()) { | 126 if (IsEncryptionEstablished()) { |
92 return OK; | 127 return OK; |
93 } | 128 } |
94 | 129 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 // use a weak pointer to be safe. | 232 // use a weak pointer to be safe. |
198 connection()->ProcessUdpPacket(local_address, peer_address, packet); | 233 connection()->ProcessUdpPacket(local_address, peer_address, packet); |
199 if (!connection()->connected()) { | 234 if (!connection()->connected()) { |
200 stream_factory_->OnSessionClose(this); | 235 stream_factory_->OnSessionClose(this); |
201 return; | 236 return; |
202 } | 237 } |
203 StartReading(); | 238 StartReading(); |
204 } | 239 } |
205 | 240 |
206 } // namespace net | 241 } // namespace net |
OLD | NEW |