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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 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
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/callback_helpers.h" 7 #include "base/callback_helpers.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/metrics/sparse_histogram.h" 10 #include "base/metrics/sparse_histogram.h"
(...skipping 24 matching lines...) Expand all
35 DESTRUCTOR = 0, 35 DESTRUCTOR = 0,
36 ADD_OBSERVER = 1, 36 ADD_OBSERVER = 1,
37 TRY_CREATE_STREAM = 2, 37 TRY_CREATE_STREAM = 2,
38 CREATE_OUTGOING_RELIABLE_STREAM = 3, 38 CREATE_OUTGOING_RELIABLE_STREAM = 3,
39 NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER = 4, 39 NOTIFY_FACTORY_OF_SESSION_CLOSED_LATER = 4,
40 NOTIFY_FACTORY_OF_SESSION_CLOSED = 5, 40 NOTIFY_FACTORY_OF_SESSION_CLOSED = 5,
41 NUM_LOCATIONS = 6, 41 NUM_LOCATIONS = 6,
42 }; 42 };
43 43
44 void RecordUnexpectedOpenStreams(Location location) { 44 void RecordUnexpectedOpenStreams(Location location) {
45 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.UnexpectedOpenStreams", location, 45 UMA_HISTOGRAM_ENUMERATION(
46 NUM_LOCATIONS); 46 "Net.QuicSession.UnexpectedOpenStreams", location, NUM_LOCATIONS);
47 } 47 }
48 48
49 void RecordUnexpectedObservers(Location location) { 49 void RecordUnexpectedObservers(Location location) {
50 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.UnexpectedObservers", location, 50 UMA_HISTOGRAM_ENUMERATION(
51 NUM_LOCATIONS); 51 "Net.QuicSession.UnexpectedObservers", location, NUM_LOCATIONS);
52 } 52 }
53 53
54 void RecordUnexpectedNotGoingAway(Location location) { 54 void RecordUnexpectedNotGoingAway(Location location) {
55 UMA_HISTOGRAM_ENUMERATION("Net.QuicSession.UnexpectedNotGoingAway", location, 55 UMA_HISTOGRAM_ENUMERATION(
56 NUM_LOCATIONS); 56 "Net.QuicSession.UnexpectedNotGoingAway", location, NUM_LOCATIONS);
57 } 57 }
58 58
59 // Note: these values must be kept in sync with the corresponding values in: 59 // Note: these values must be kept in sync with the corresponding values in:
60 // tools/metrics/histograms/histograms.xml 60 // tools/metrics/histograms/histograms.xml
61 enum HandshakeState { 61 enum HandshakeState {
62 STATE_STARTED = 0, 62 STATE_STARTED = 0,
63 STATE_ENCRYPTION_ESTABLISHED = 1, 63 STATE_ENCRYPTION_ESTABLISHED = 1,
64 STATE_HANDSHAKE_CONFIRMED = 2, 64 STATE_HANDSHAKE_CONFIRMED = 2,
65 STATE_FAILED = 3, 65 STATE_FAILED = 3,
66 NUM_HANDSHAKE_STATES = 4 66 NUM_HANDSHAKE_STATES = 4
67 }; 67 };
68 68
69 void RecordHandshakeState(HandshakeState state) { 69 void RecordHandshakeState(HandshakeState state) {
70 UMA_HISTOGRAM_ENUMERATION("Net.QuicHandshakeState", state, 70 UMA_HISTOGRAM_ENUMERATION(
71 NUM_HANDSHAKE_STATES); 71 "Net.QuicHandshakeState", state, NUM_HANDSHAKE_STATES);
72 } 72 }
73 73
74 } // namespace 74 } // namespace
75 75
76 QuicClientSession::StreamRequest::StreamRequest() : stream_(NULL) {} 76 QuicClientSession::StreamRequest::StreamRequest() : stream_(NULL) {
77 }
77 78
78 QuicClientSession::StreamRequest::~StreamRequest() { 79 QuicClientSession::StreamRequest::~StreamRequest() {
79 CancelRequest(); 80 CancelRequest();
80 } 81 }
81 82
82 int QuicClientSession::StreamRequest::StartRequest( 83 int QuicClientSession::StreamRequest::StartRequest(
83 const base::WeakPtr<QuicClientSession>& session, 84 const base::WeakPtr<QuicClientSession>& session,
84 QuicReliableClientStream** stream, 85 QuicReliableClientStream** stream,
85 const CompletionCallback& callback) { 86 const CompletionCallback& callback) {
86 session_ = session; 87 session_ = session;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 read_buffer_(new IOBufferWithSize(kMaxPacketSize)), 132 read_buffer_(new IOBufferWithSize(kMaxPacketSize)),
132 server_info_(server_info.Pass()), 133 server_info_(server_info.Pass()),
133 read_pending_(false), 134 read_pending_(false),
134 num_total_streams_(0), 135 num_total_streams_(0),
135 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)), 136 net_log_(BoundNetLog::Make(net_log, NetLog::SOURCE_QUIC_SESSION)),
136 logger_(net_log_), 137 logger_(net_log_),
137 num_packets_read_(0), 138 num_packets_read_(0),
138 going_away_(false), 139 going_away_(false),
139 weak_factory_(this) { 140 weak_factory_(this) {
140 crypto_stream_.reset( 141 crypto_stream_.reset(
141 crypto_client_stream_factory ? 142 crypto_client_stream_factory
142 crypto_client_stream_factory->CreateQuicCryptoClientStream( 143 ? crypto_client_stream_factory->CreateQuicCryptoClientStream(
143 server_id, this, crypto_config) : 144 server_id, this, crypto_config)
144 new QuicCryptoClientStream(server_id, this, 145 : new QuicCryptoClientStream(server_id,
145 new ProofVerifyContextChromium(net_log_), 146 this,
146 crypto_config)); 147 new ProofVerifyContextChromium(net_log_),
148 crypto_config));
147 149
148 connection->set_debug_visitor(&logger_); 150 connection->set_debug_visitor(&logger_);
149 // TODO(rch): pass in full host port proxy pair 151 // TODO(rch): pass in full host port proxy pair
150 net_log_.BeginEvent( 152 net_log_.BeginEvent(NetLog::TYPE_QUIC_SESSION,
151 NetLog::TYPE_QUIC_SESSION, 153 NetLog::StringCallback("host", &server_id.host()));
152 NetLog::StringCallback("host", &server_id.host()));
153 } 154 }
154 155
155 QuicClientSession::~QuicClientSession() { 156 QuicClientSession::~QuicClientSession() {
156 if (!streams()->empty()) 157 if (!streams()->empty())
157 RecordUnexpectedOpenStreams(DESTRUCTOR); 158 RecordUnexpectedOpenStreams(DESTRUCTOR);
158 if (!observers_.empty()) 159 if (!observers_.empty())
159 RecordUnexpectedObservers(DESTRUCTOR); 160 RecordUnexpectedObservers(DESTRUCTOR);
160 if (!going_away_) 161 if (!going_away_)
161 RecordUnexpectedNotGoingAway(DESTRUCTOR); 162 RecordUnexpectedNotGoingAway(DESTRUCTOR);
162 163
163 while (!streams()->empty() || 164 while (!streams()->empty() || !observers_.empty() ||
164 !observers_.empty() ||
165 !stream_requests_.empty()) { 165 !stream_requests_.empty()) {
166 // The session must be closed before it is destroyed. 166 // The session must be closed before it is destroyed.
167 DCHECK(streams()->empty()); 167 DCHECK(streams()->empty());
168 CloseAllStreams(ERR_UNEXPECTED); 168 CloseAllStreams(ERR_UNEXPECTED);
169 DCHECK(observers_.empty()); 169 DCHECK(observers_.empty());
170 CloseAllObservers(ERR_UNEXPECTED); 170 CloseAllObservers(ERR_UNEXPECTED);
171 171
172 connection()->set_debug_visitor(NULL); 172 connection()->set_debug_visitor(NULL);
173 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION); 173 net_log_.EndEvent(NetLog::TYPE_QUIC_SESSION);
174 174
(...skipping 29 matching lines...) Expand all
204 // Don't bother with these histogram during tests, which mock out 204 // Don't bother with these histogram during tests, which mock out
205 // num_sent_client_hellos(). 205 // num_sent_client_hellos().
206 if (round_trip_handshakes < 0 || !stream_factory_) 206 if (round_trip_handshakes < 0 || !stream_factory_)
207 return; 207 return;
208 208
209 bool port_selected = stream_factory_->enable_port_selection(); 209 bool port_selected = stream_factory_->enable_port_selection();
210 SSLInfo ssl_info; 210 SSLInfo ssl_info;
211 if (!GetSSLInfo(&ssl_info) || !ssl_info.cert) { 211 if (!GetSSLInfo(&ssl_info) || !ssl_info.cert) {
212 if (port_selected) { 212 if (port_selected) {
213 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.ConnectSelectPortForHTTP", 213 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.ConnectSelectPortForHTTP",
214 round_trip_handshakes, 0, 3, 4); 214 round_trip_handshakes,
215 0,
216 3,
217 4);
215 } else { 218 } else {
216 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.ConnectRandomPortForHTTP", 219 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.ConnectRandomPortForHTTP",
217 round_trip_handshakes, 0, 3, 4); 220 round_trip_handshakes,
221 0,
222 3,
223 4);
218 } 224 }
219 } else { 225 } else {
220 if (port_selected) { 226 if (port_selected) {
221 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.ConnectSelectPortForHTTPS", 227 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.ConnectSelectPortForHTTPS",
222 round_trip_handshakes, 0, 3, 4); 228 round_trip_handshakes,
229 0,
230 3,
231 4);
223 } else { 232 } else {
224 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.ConnectRandomPortForHTTPS", 233 UMA_HISTOGRAM_CUSTOM_COUNTS("Net.QuicSession.ConnectRandomPortForHTTPS",
225 round_trip_handshakes, 0, 3, 4); 234 round_trip_handshakes,
235 0,
236 3,
237 4);
226 } 238 }
227 } 239 }
228 } 240 }
229 241
230 void QuicClientSession::OnStreamFrames( 242 void QuicClientSession::OnStreamFrames(
231 const std::vector<QuicStreamFrame>& frames) { 243 const std::vector<QuicStreamFrame>& frames) {
232 // Record total number of stream frames. 244 // Record total number of stream frames.
233 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesInPacket", frames.size()); 245 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesInPacket", frames.size());
234 246
235 // Record number of frames per stream in packet. 247 // Record number of frames per stream in packet.
236 typedef std::map<QuicStreamId, size_t> FrameCounter; 248 typedef std::map<QuicStreamId, size_t> FrameCounter;
237 FrameCounter frames_per_stream; 249 FrameCounter frames_per_stream;
238 for (size_t i = 0; i < frames.size(); ++i) { 250 for (size_t i = 0; i < frames.size(); ++i) {
239 frames_per_stream[frames[i].stream_id]++; 251 frames_per_stream[frames[i].stream_id]++;
240 } 252 }
241 for (FrameCounter::const_iterator it = frames_per_stream.begin(); 253 for (FrameCounter::const_iterator it = frames_per_stream.begin();
242 it != frames_per_stream.end(); ++it) { 254 it != frames_per_stream.end();
255 ++it) {
243 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesPerStreamInPacket", 256 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesPerStreamInPacket",
244 it->second); 257 it->second);
245 } 258 }
246 259
247 return QuicSession::OnStreamFrames(frames); 260 return QuicSession::OnStreamFrames(frames);
248 } 261 }
249 262
250 void QuicClientSession::AddObserver(Observer* observer) { 263 void QuicClientSession::AddObserver(Observer* observer) {
251 if (going_away_) { 264 if (going_away_) {
252 RecordUnexpectedObservers(ADD_OBSERVER); 265 RecordUnexpectedObservers(ADD_OBSERVER);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 break; 378 break;
366 case kCC12: 379 case kCC12:
367 cipher_suite = 0xcc13; // TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 380 cipher_suite = 0xcc13; // TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
368 security_bits = 256; 381 security_bits = 256;
369 break; 382 break;
370 default: 383 default:
371 NOTREACHED(); 384 NOTREACHED();
372 return false; 385 return false;
373 } 386 }
374 int ssl_connection_status = 0; 387 int ssl_connection_status = 0;
388 ssl_connection_status |= (cipher_suite & SSL_CONNECTION_CIPHERSUITE_MASK)
389 << SSL_CONNECTION_CIPHERSUITE_SHIFT;
375 ssl_connection_status |= 390 ssl_connection_status |=
376 (cipher_suite & SSL_CONNECTION_CIPHERSUITE_MASK) << 391 (SSL_CONNECTION_VERSION_QUIC & SSL_CONNECTION_VERSION_MASK)
377 SSL_CONNECTION_CIPHERSUITE_SHIFT; 392 << SSL_CONNECTION_VERSION_SHIFT;
378 ssl_connection_status |=
379 (SSL_CONNECTION_VERSION_QUIC & SSL_CONNECTION_VERSION_MASK) <<
380 SSL_CONNECTION_VERSION_SHIFT;
381 393
382 ssl_info->public_key_hashes = cert_verify_result_->public_key_hashes; 394 ssl_info->public_key_hashes = cert_verify_result_->public_key_hashes;
383 ssl_info->is_issued_by_known_root = 395 ssl_info->is_issued_by_known_root =
384 cert_verify_result_->is_issued_by_known_root; 396 cert_verify_result_->is_issued_by_known_root;
385 397
386 ssl_info->connection_status = ssl_connection_status; 398 ssl_info->connection_status = ssl_connection_status;
387 ssl_info->client_cert_sent = false; 399 ssl_info->client_cert_sent = false;
388 ssl_info->channel_id_sent = false; 400 ssl_info->channel_id_sent = false;
389 ssl_info->security_bits = security_bits; 401 ssl_info->security_bits = security_bits;
390 ssl_info->handshake_type = SSLInfo::HANDSHAKE_FULL; 402 ssl_info->handshake_type = SSLInfo::HANDSHAKE_FULL;
391 return true; 403 return true;
392 } 404 }
393 405
394 int QuicClientSession::CryptoConnect(bool require_confirmation, 406 int QuicClientSession::CryptoConnect(bool require_confirmation,
395 const CompletionCallback& callback) { 407 const CompletionCallback& callback) {
396 require_confirmation_ = require_confirmation; 408 require_confirmation_ = require_confirmation;
397 RecordHandshakeState(STATE_STARTED); 409 RecordHandshakeState(STATE_STARTED);
398 if (!crypto_stream_->CryptoConnect()) { 410 if (!crypto_stream_->CryptoConnect()) {
399 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a 411 // TODO(wtc): change crypto_stream_.CryptoConnect() to return a
400 // QuicErrorCode and map it to a net error code. 412 // QuicErrorCode and map it to a net error code.
401 return ERR_CONNECTION_FAILED; 413 return ERR_CONNECTION_FAILED;
402 } 414 }
403 415
404 bool can_notify = require_confirmation_ ? 416 bool can_notify = require_confirmation_ ? IsCryptoHandshakeConfirmed()
405 IsCryptoHandshakeConfirmed() : IsEncryptionEstablished(); 417 : IsEncryptionEstablished();
406 if (can_notify) { 418 if (can_notify) {
407 return OK; 419 return OK;
408 } 420 }
409 421
410 callback_ = callback; 422 callback_ = callback;
411 return ERR_IO_PENDING; 423 return ERR_IO_PENDING;
412 } 424 }
413 425
414 int QuicClientSession::GetNumSentClientHellos() const { 426 int QuicClientSession::GetNumSentClientHellos() const {
415 return crypto_stream_->num_sent_client_hellos(); 427 return crypto_stream_->num_sent_client_hellos();
416 } 428 }
417 429
418 bool QuicClientSession::CanPool(const std::string& hostname) const { 430 bool QuicClientSession::CanPool(const std::string& hostname) const {
419 // TODO(rch): When QUIC supports channel ID or client certificates, this 431 // TODO(rch): When QUIC supports channel ID or client certificates, this
420 // logic will need to be revised. 432 // logic will need to be revised.
421 DCHECK(connection()->connected()); 433 DCHECK(connection()->connected());
422 SSLInfo ssl_info; 434 SSLInfo ssl_info;
423 bool unused = false; 435 bool unused = false;
424 if (!GetSSLInfo(&ssl_info) || !ssl_info.cert) { 436 if (!GetSSLInfo(&ssl_info) || !ssl_info.cert) {
425 // We can always pool with insecure QUIC sessions. 437 // We can always pool with insecure QUIC sessions.
426 return true; 438 return true;
427 } 439 }
428 // Only pool secure QUIC sessions if the cert matches the new hostname. 440 // Only pool secure QUIC sessions if the cert matches the new hostname.
429 return ssl_info.cert->VerifyNameMatch(hostname, &unused); 441 return ssl_info.cert->VerifyNameMatch(hostname, &unused);
430 } 442 }
431 443
432 QuicDataStream* QuicClientSession::CreateIncomingDataStream( 444 QuicDataStream* QuicClientSession::CreateIncomingDataStream(QuicStreamId id) {
433 QuicStreamId id) {
434 DLOG(ERROR) << "Server push not supported"; 445 DLOG(ERROR) << "Server push not supported";
435 return NULL; 446 return NULL;
436 } 447 }
437 448
438 void QuicClientSession::CloseStream(QuicStreamId stream_id) { 449 void QuicClientSession::CloseStream(QuicStreamId stream_id) {
439 ReliableQuicStream* stream = GetStream(stream_id); 450 ReliableQuicStream* stream = GetStream(stream_id);
440 if (stream) { 451 if (stream) {
441 logger_.UpdateReceivedFrameCounts( 452 logger_.UpdateReceivedFrameCounts(stream_id,
442 stream_id, stream->num_frames_received(), 453 stream->num_frames_received(),
443 stream->num_duplicate_frames_received()); 454 stream->num_duplicate_frames_received());
444 } 455 }
445 QuicSession::CloseStream(stream_id); 456 QuicSession::CloseStream(stream_id);
446 OnClosedStream(); 457 OnClosedStream();
447 } 458 }
448 459
449 void QuicClientSession::SendRstStream(QuicStreamId id, 460 void QuicClientSession::SendRstStream(QuicStreamId id,
450 QuicRstStreamErrorCode error, 461 QuicRstStreamErrorCode error,
451 QuicStreamOffset bytes_written) { 462 QuicStreamOffset bytes_written) {
452 QuicSession::SendRstStream(id, error, bytes_written); 463 QuicSession::SendRstStream(id, error, bytes_written);
453 OnClosedStream(); 464 OnClosedStream();
454 } 465 }
455 466
456 void QuicClientSession::OnClosedStream() { 467 void QuicClientSession::OnClosedStream() {
457 if (GetNumOpenStreams() < get_max_open_streams() && 468 if (GetNumOpenStreams() < get_max_open_streams() &&
458 !stream_requests_.empty() && 469 !stream_requests_.empty() && crypto_stream_->encryption_established() &&
459 crypto_stream_->encryption_established() && 470 !goaway_received() && !going_away_ && connection()->connected()) {
460 !goaway_received() &&
461 !going_away_ &&
462 connection()->connected()) {
463 StreamRequest* request = stream_requests_.front(); 471 StreamRequest* request = stream_requests_.front();
464 stream_requests_.pop_front(); 472 stream_requests_.pop_front();
465 request->OnRequestCompleteSuccess(CreateOutgoingReliableStreamImpl()); 473 request->OnRequestCompleteSuccess(CreateOutgoingReliableStreamImpl());
466 } 474 }
467 475
468 if (GetNumOpenStreams() == 0) { 476 if (GetNumOpenStreams() == 0) {
469 stream_factory_->OnIdleSession(this); 477 stream_factory_->OnIdleSession(this);
470 } 478 }
471 } 479 }
472 480
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 state->source_address_token = cached.source_address_token(); 567 state->source_address_token = cached.source_address_token();
560 state->server_config_sig = cached.signature(); 568 state->server_config_sig = cached.signature();
561 state->certs = cached.certs(); 569 state->certs = cached.certs();
562 570
563 server_info_->Persist(); 571 server_info_->Persist();
564 } 572 }
565 573
566 void QuicClientSession::OnProofVerifyDetailsAvailable( 574 void QuicClientSession::OnProofVerifyDetailsAvailable(
567 const ProofVerifyDetails& verify_details) { 575 const ProofVerifyDetails& verify_details) {
568 const CertVerifyResult* cert_verify_result_other = 576 const CertVerifyResult* cert_verify_result_other =
569 &(reinterpret_cast<const ProofVerifyDetailsChromium*>( 577 &(reinterpret_cast<const ProofVerifyDetailsChromium*>(&verify_details))
570 &verify_details))->cert_verify_result; 578 ->cert_verify_result;
571 CertVerifyResult* result_copy = new CertVerifyResult; 579 CertVerifyResult* result_copy = new CertVerifyResult;
572 result_copy->CopyFrom(*cert_verify_result_other); 580 result_copy->CopyFrom(*cert_verify_result_other);
573 cert_verify_result_.reset(result_copy); 581 cert_verify_result_.reset(result_copy);
574 } 582 }
575 583
576 void QuicClientSession::StartReading() { 584 void QuicClientSession::StartReading() {
577 if (read_pending_) { 585 if (read_pending_) {
578 return; 586 return;
579 } 587 }
580 read_pending_ = true; 588 read_pending_ = true;
581 int rv = socket_->Read(read_buffer_.get(), 589 int rv = socket_->Read(read_buffer_.get(),
582 read_buffer_->size(), 590 read_buffer_->size(),
583 base::Bind(&QuicClientSession::OnReadComplete, 591 base::Bind(&QuicClientSession::OnReadComplete,
584 weak_factory_.GetWeakPtr())); 592 weak_factory_.GetWeakPtr()));
585 if (rv == ERR_IO_PENDING) { 593 if (rv == ERR_IO_PENDING) {
586 num_packets_read_ = 0; 594 num_packets_read_ = 0;
587 return; 595 return;
588 } 596 }
589 597
590 if (++num_packets_read_ > 32) { 598 if (++num_packets_read_ > 32) {
591 num_packets_read_ = 0; 599 num_packets_read_ = 0;
592 // Data was read, process it. 600 // Data was read, process it.
593 // Schedule the work through the message loop to avoid recursive 601 // Schedule the work through the message loop to avoid recursive
594 // callbacks. 602 // callbacks.
595 base::MessageLoop::current()->PostTask( 603 base::MessageLoop::current()->PostTask(
596 FROM_HERE, 604 FROM_HERE,
597 base::Bind(&QuicClientSession::OnReadComplete, 605 base::Bind(&QuicClientSession::OnReadComplete,
598 weak_factory_.GetWeakPtr(), rv)); 606 weak_factory_.GetWeakPtr(),
607 rv));
599 } else { 608 } else {
600 OnReadComplete(rv); 609 OnReadComplete(rv);
601 } 610 }
602 } 611 }
603 612
604 void QuicClientSession::CloseSessionOnError(int error) { 613 void QuicClientSession::CloseSessionOnError(int error) {
605 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.CloseSessionOnError", -error); 614 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.CloseSessionOnError", -error);
606 CloseSessionOnErrorInner(error, QUIC_INTERNAL_ERROR); 615 CloseSessionOnErrorInner(error, QUIC_INTERNAL_ERROR);
607 NotifyFactoryOfSessionClosed(); 616 NotifyFactoryOfSessionClosed();
608 } 617 }
609 618
610 void QuicClientSession::CloseSessionOnErrorInner(int net_error, 619 void QuicClientSession::CloseSessionOnErrorInner(int net_error,
611 QuicErrorCode quic_error) { 620 QuicErrorCode quic_error) {
612 if (!callback_.is_null()) { 621 if (!callback_.is_null()) {
613 base::ResetAndReturn(&callback_).Run(net_error); 622 base::ResetAndReturn(&callback_).Run(net_error);
614 } 623 }
615 CloseAllStreams(net_error); 624 CloseAllStreams(net_error);
616 CloseAllObservers(net_error); 625 CloseAllObservers(net_error);
617 net_log_.AddEvent( 626 net_log_.AddEvent(NetLog::TYPE_QUIC_SESSION_CLOSE_ON_ERROR,
618 NetLog::TYPE_QUIC_SESSION_CLOSE_ON_ERROR, 627 NetLog::IntegerCallback("net_error", net_error));
619 NetLog::IntegerCallback("net_error", net_error));
620 628
621 connection()->CloseConnection(quic_error, false); 629 connection()->CloseConnection(quic_error, false);
622 DCHECK(!connection()->connected()); 630 DCHECK(!connection()->connected());
623 } 631 }
624 632
625 void QuicClientSession::CloseAllStreams(int net_error) { 633 void QuicClientSession::CloseAllStreams(int net_error) {
626 while (!streams()->empty()) { 634 while (!streams()->empty()) {
627 ReliableQuicStream* stream = streams()->begin()->second; 635 ReliableQuicStream* stream = streams()->begin()->second;
628 QuicStreamId id = stream->id(); 636 QuicStreamId id = stream->id();
629 static_cast<QuicReliableClientStream*>(stream)->OnError(net_error); 637 static_cast<QuicReliableClientStream*>(stream)->OnError(net_error);
(...skipping 18 matching lines...) Expand all
648 dict->SetInteger("open_streams", GetNumOpenStreams()); 656 dict->SetInteger("open_streams", GetNumOpenStreams());
649 dict->SetInteger("total_streams", num_total_streams_); 657 dict->SetInteger("total_streams", num_total_streams_);
650 dict->SetString("peer_address", peer_address().ToString()); 658 dict->SetString("peer_address", peer_address().ToString());
651 dict->SetString("connection_id", base::Uint64ToString(connection_id())); 659 dict->SetString("connection_id", base::Uint64ToString(connection_id()));
652 dict->SetBoolean("connected", connection()->connected()); 660 dict->SetBoolean("connected", connection()->connected());
653 SSLInfo ssl_info; 661 SSLInfo ssl_info;
654 dict->SetBoolean("secure", GetSSLInfo(&ssl_info) && ssl_info.cert); 662 dict->SetBoolean("secure", GetSSLInfo(&ssl_info) && ssl_info.cert);
655 663
656 base::ListValue* alias_list = new base::ListValue(); 664 base::ListValue* alias_list = new base::ListValue();
657 for (std::set<HostPortPair>::const_iterator it = aliases.begin(); 665 for (std::set<HostPortPair>::const_iterator it = aliases.begin();
658 it != aliases.end(); it++) { 666 it != aliases.end();
667 it++) {
659 alias_list->Append(new base::StringValue(it->ToString())); 668 alias_list->Append(new base::StringValue(it->ToString()));
660 } 669 }
661 dict->Set("aliases", alias_list); 670 dict->Set("aliases", alias_list);
662 671
663 return dict; 672 return dict;
664 } 673 }
665 674
666 base::WeakPtr<QuicClientSession> QuicClientSession::GetWeakPtr() { 675 base::WeakPtr<QuicClientSession> QuicClientSession::GetWeakPtr() {
667 return weak_factory_.GetWeakPtr(); 676 return weak_factory_.GetWeakPtr();
668 } 677 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED); 737 RecordUnexpectedNotGoingAway(NOTIFY_FACTORY_OF_SESSION_CLOSED);
729 738
730 going_away_ = true; 739 going_away_ = true;
731 DCHECK_EQ(0u, GetNumOpenStreams()); 740 DCHECK_EQ(0u, GetNumOpenStreams());
732 // Will delete |this|. 741 // Will delete |this|.
733 if (stream_factory_) 742 if (stream_factory_)
734 stream_factory_->OnSessionClosed(this); 743 stream_factory_->OnSessionClosed(this);
735 } 744 }
736 745
737 } // namespace net 746 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698