Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(697)

Side by Side Diff: net/quic/quic_client_session.cc

Issue 12253020: Enhance net internals/net log output for QUIC. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix use after free Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_client_session_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "net/base/io_buffer.h" 11 #include "net/base/io_buffer.h"
12 #include "net/base/net_errors.h" 12 #include "net/base/net_errors.h"
13 #include "net/quic/quic_connection_helper.h" 13 #include "net/quic/quic_connection_helper.h"
14 #include "net/quic/quic_stream_factory.h" 14 #include "net/quic/quic_stream_factory.h"
15 #include "net/udp/datagram_client_socket.h" 15 #include "net/udp/datagram_client_socket.h"
16 16
17 namespace net { 17 namespace net {
18 18
19 QuicClientSession::QuicClientSession(QuicConnection* connection, 19 QuicClientSession::QuicClientSession(QuicConnection* connection,
20 QuicConnectionHelper* helper, 20 QuicConnectionHelper* helper,
21 QuicStreamFactory* stream_factory, 21 QuicStreamFactory* stream_factory,
22 const string& server_hostname) 22 const string& server_hostname,
23 NetLog* net_log)
23 : QuicSession(connection, false), 24 : QuicSession(connection, false),
24 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 25 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
25 ALLOW_THIS_IN_INITIALIZER_LIST(crypto_stream_(this, server_hostname)), 26 ALLOW_THIS_IN_INITIALIZER_LIST(crypto_stream_(this, server_hostname)),
26 helper_(helper), 27 helper_(helper),
27 stream_factory_(stream_factory), 28 stream_factory_(stream_factory),
28 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), 29 read_buffer_(new IOBufferWithSize(kMaxPacketSize)),
29 read_pending_(false) { 30 read_pending_(false),
31 num_total_streams_(0),
32 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)) {
33 // TODO(rch): pass in full host port proxy pair
34 net_log_.BeginEvent(
35 NetLog::TYPE_QUIC_SESSION,
36 NetLog::StringCallback("host", &server_hostname));
30 } 37 }
31 38
32 QuicClientSession::~QuicClientSession() { 39 QuicClientSession::~QuicClientSession() {
40 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION);
33 } 41 }
34 42
35 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() { 43 QuicReliableClientStream* QuicClientSession::CreateOutgoingReliableStream() {
36 if (!crypto_stream_.handshake_complete()) { 44 if (!crypto_stream_.handshake_complete()) {
37 DLOG(INFO) << "Crypto handshake not complete, no outgoing stream created."; 45 DLOG(INFO) << "Crypto handshake not complete, no outgoing stream created.";
38 return NULL; 46 return NULL;
39 } 47 }
40 if (GetNumOpenStreams() >= get_max_open_streams()) { 48 if (GetNumOpenStreams() >= get_max_open_streams()) {
41 DLOG(INFO) << "Failed to create a new outgoing stream. " 49 DLOG(INFO) << "Failed to create a new outgoing stream. "
42 << "Already " << GetNumOpenStreams() << " open."; 50 << "Already " << GetNumOpenStreams() << " open.";
43 return NULL; 51 return NULL;
44 } 52 }
45 QuicReliableClientStream* stream = 53 QuicReliableClientStream* stream =
46 new QuicReliableClientStream(GetNextStreamId(), this); 54 new QuicReliableClientStream(GetNextStreamId(), this, net_log_);
47 ActivateStream(stream); 55 ActivateStream(stream);
56 ++num_total_streams_;
48 return stream; 57 return stream;
49 } 58 }
50 59
51 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() { 60 QuicCryptoClientStream* QuicClientSession::GetCryptoStream() {
52 return &crypto_stream_; 61 return &crypto_stream_;
53 }; 62 };
54 63
55 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) { 64 int QuicClientSession::CryptoConnect(const CompletionCallback& callback) {
56 if (!crypto_stream_.CryptoConnect()) { 65 if (!crypto_stream_.CryptoConnect()) {
57 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a 66 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 weak_factory_.GetWeakPtr(), rv)); 117 weak_factory_.GetWeakPtr(), rv));
109 } 118 }
110 119
111 void QuicClientSession::CloseSessionOnError(int error) { 120 void QuicClientSession::CloseSessionOnError(int error) {
112 while (!streams()->empty()) { 121 while (!streams()->empty()) {
113 ReliableQuicStream* stream = streams()->begin()->second; 122 ReliableQuicStream* stream = streams()->begin()->second;
114 QuicStreamId id = stream->id(); 123 QuicStreamId id = stream->id();
115 static_cast<QuicReliableClientStream*>(stream)->OnError(error); 124 static_cast<QuicReliableClientStream*>(stream)->OnError(error);
116 CloseStream(id); 125 CloseStream(id);
117 } 126 }
127 net_log_.BeginEvent(
128 NetLog::TYPE_QUIC_SESSION,
129 NetLog::IntegerCallback("net_error", error));
130 // Will delete |this|.
118 stream_factory_->OnSessionClose(this); 131 stream_factory_->OnSessionClose(this);
119 } 132 }
120 133
121 Value* QuicClientSession::GetInfoAsValue(const HostPortPair& pair) const { 134 Value* QuicClientSession::GetInfoAsValue(const HostPortPair& pair) const {
122 DictionaryValue* dict = new DictionaryValue(); 135 DictionaryValue* dict = new DictionaryValue();
123 dict->SetString("host_port_pair", pair.ToString()); 136 dict->SetString("host_port_pair", pair.ToString());
124 dict->SetInteger("open_streams", GetNumOpenStreams()); 137 dict->SetInteger("open_streams", GetNumOpenStreams());
138 dict->SetInteger("total_streams", num_total_streams_);
125 dict->SetString("peer_address", peer_address().ToString()); 139 dict->SetString("peer_address", peer_address().ToString());
126 dict->SetString("guid", base::Uint64ToString(guid())); 140 dict->SetString("guid", base::Uint64ToString(guid()));
127 return dict; 141 return dict;
128 } 142 }
129 143
130 void QuicClientSession::OnReadComplete(int result) { 144 void QuicClientSession::OnReadComplete(int result) {
131 read_pending_ = false; 145 read_pending_ = false;
132 // TODO(rch): Inform the connection about the result. 146 // TODO(rch): Inform the connection about the result.
133 if (result > 0) { 147 if (result > 0) {
134 scoped_refptr<IOBufferWithSize> buffer(read_buffer_); 148 scoped_refptr<IOBufferWithSize> buffer(read_buffer_);
135 read_buffer_ = new IOBufferWithSize(kMaxPacketSize); 149 read_buffer_ = new IOBufferWithSize(kMaxPacketSize);
136 QuicEncryptedPacket packet(buffer->data(), result); 150 QuicEncryptedPacket packet(buffer->data(), result);
137 IPEndPoint local_address; 151 IPEndPoint local_address;
138 IPEndPoint peer_address; 152 IPEndPoint peer_address;
139 helper_->GetLocalAddress(&local_address); 153 helper_->GetLocalAddress(&local_address);
140 helper_->GetPeerAddress(&peer_address); 154 helper_->GetPeerAddress(&peer_address);
141 // ProcessUdpPacket might result in |this| being deleted, so we 155 // ProcessUdpPacket might result in |this| being deleted, so we
142 // use a weak pointer to be safe. 156 // use a weak pointer to be safe.
143 connection()->ProcessUdpPacket(local_address, peer_address, packet); 157 connection()->ProcessUdpPacket(local_address, peer_address, packet);
144 if (!connection()->connected()) { 158 if (!connection()->connected()) {
145 stream_factory_->OnSessionClose(this); 159 stream_factory_->OnSessionClose(this);
146 return; 160 return;
147 } 161 }
148 StartReading(); 162 StartReading();
149 } 163 }
150 } 164 }
151 165
152 } // namespace net 166 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/quic_client_session.h ('k') | net/quic/quic_client_session_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698