| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 | 179 |
| 180 const GURL& GetURL() const override { return request_url_; } | 180 const GURL& GetURL() const override { return request_url_; } |
| 181 | 181 |
| 182 private: | 182 private: |
| 183 base::WeakPtr<QuicChromiumClientSession> session_; | 183 base::WeakPtr<QuicChromiumClientSession> session_; |
| 184 const GURL request_url_; | 184 const GURL request_url_; |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 } // namespace | 187 } // namespace |
| 188 | 188 |
| 189 QuicChromiumClientSession::Handle::Handle( |
| 190 const base::WeakPtr<QuicChromiumClientSession>& session) |
| 191 : MultiplexedSessionHandle(session), |
| 192 session_(session), |
| 193 net_log_(session_->net_log()), |
| 194 was_handshake_confirmed_(session->IsCryptoHandshakeConfirmed()), |
| 195 error_(OK), |
| 196 port_migration_detected_(false), |
| 197 server_id_(session_->server_id()), |
| 198 quic_version_(session->connection()->version()) { |
| 199 DCHECK(session_); |
| 200 session_->AddHandle(this); |
| 201 } |
| 202 |
| 203 QuicChromiumClientSession::Handle::~Handle() { |
| 204 if (session_) |
| 205 session_->RemoveHandle(this); |
| 206 } |
| 207 |
| 208 void QuicChromiumClientSession::Handle::OnCryptoHandshakeConfirmed() { |
| 209 was_handshake_confirmed_ = true; |
| 210 } |
| 211 |
| 212 void QuicChromiumClientSession::Handle::OnSessionClosed( |
| 213 QuicVersion quic_version, |
| 214 int error, |
| 215 bool port_migration_detected, |
| 216 LoadTimingInfo::ConnectTiming connect_timing) { |
| 217 session_ = nullptr; |
| 218 port_migration_detected_ = port_migration_detected; |
| 219 error_ = error; |
| 220 quic_version_ = quic_version; |
| 221 connect_timing_ = connect_timing; |
| 222 } |
| 223 |
| 224 bool QuicChromiumClientSession::Handle::IsConnected() const { |
| 225 return session_ != nullptr; |
| 226 } |
| 227 |
| 228 bool QuicChromiumClientSession::Handle::IsCryptoHandshakeConfirmed() const { |
| 229 return was_handshake_confirmed_; |
| 230 } |
| 231 |
| 232 const LoadTimingInfo::ConnectTiming& |
| 233 QuicChromiumClientSession::Handle::GetConnectTiming() { |
| 234 if (!session_) |
| 235 return connect_timing_; |
| 236 |
| 237 return session_->GetConnectTiming(); |
| 238 } |
| 239 |
| 240 Error QuicChromiumClientSession::Handle::GetTokenBindingSignature( |
| 241 crypto::ECPrivateKey* key, |
| 242 TokenBindingType tb_type, |
| 243 std::vector<uint8_t>* out) { |
| 244 if (!session_) |
| 245 return ERR_CONNECTION_CLOSED; |
| 246 |
| 247 return session_->GetTokenBindingSignature(key, tb_type, out); |
| 248 } |
| 249 |
| 250 void QuicChromiumClientSession::Handle::PopulateNetErrorDetails( |
| 251 NetErrorDetails* details) const { |
| 252 if (session_) { |
| 253 session_->PopulateNetErrorDetails(details); |
| 254 } else { |
| 255 details->quic_port_migration_detected = port_migration_detected_; |
| 256 } |
| 257 } |
| 258 |
| 259 QuicVersion QuicChromiumClientSession::Handle::GetQuicVersion() const { |
| 260 if (!session_) |
| 261 return quic_version_; |
| 262 |
| 263 return session_->connection()->version(); |
| 264 } |
| 265 |
| 266 void QuicChromiumClientSession::Handle::ResetPromised( |
| 267 QuicStreamId id, |
| 268 QuicRstStreamErrorCode error_code) { |
| 269 if (session_) |
| 270 session_->ResetPromised(id, error_code); |
| 271 } |
| 272 |
| 273 std::unique_ptr<QuicConnection::ScopedPacketBundler> |
| 274 QuicChromiumClientSession::Handle::CreatePacketBundler( |
| 275 QuicConnection::AckBundling bundling_mode) { |
| 276 if (!session_) |
| 277 return nullptr; |
| 278 |
| 279 return base::MakeUnique<QuicConnection::ScopedPacketBundler>( |
| 280 session_->connection(), bundling_mode); |
| 281 } |
| 282 |
| 283 bool QuicChromiumClientSession::Handle::SharesSameSession( |
| 284 const Handle& other) const { |
| 285 return session_.get() == other.session_.get(); |
| 286 } |
| 287 |
| 288 int QuicChromiumClientSession::Handle::RequestStream( |
| 289 bool requires_confirmation, |
| 290 const CompletionCallback& callback) { |
| 291 DCHECK(!stream_request_); |
| 292 |
| 293 if (!session_) |
| 294 return ERR_CONNECTION_CLOSED; |
| 295 |
| 296 // base::MakeUnique does not work because the StreamRequest constructor |
| 297 // is private. |
| 298 stream_request_ = std::unique_ptr<StreamRequest>( |
| 299 new StreamRequest(session_->CreateHandle(), requires_confirmation)); |
| 300 return stream_request_->StartRequest(callback); |
| 301 } |
| 302 |
| 303 QuicChromiumClientStream* QuicChromiumClientSession::Handle::ReleaseStream() { |
| 304 DCHECK(stream_request_); |
| 305 |
| 306 auto* stream = stream_request_->ReleaseStream(); |
| 307 stream_request_.reset(); |
| 308 return stream; |
| 309 } |
| 310 |
| 311 int QuicChromiumClientSession::Handle::WaitForHandshakeConfirmation( |
| 312 const CompletionCallback& callback) { |
| 313 if (!session_) |
| 314 return ERR_CONNECTION_CLOSED; |
| 315 |
| 316 return session_->WaitForHandshakeConfirmation(callback); |
| 317 } |
| 318 |
| 319 void QuicChromiumClientSession::Handle::CancelRequest(StreamRequest* request) { |
| 320 if (session_) |
| 321 session_->CancelRequest(request); |
| 322 } |
| 323 |
| 324 int QuicChromiumClientSession::Handle::TryCreateStream(StreamRequest* request) { |
| 325 if (!session_) |
| 326 return ERR_CONNECTION_CLOSED; |
| 327 |
| 328 return session_->TryCreateStream(request); |
| 329 } |
| 330 |
| 331 QuicClientPushPromiseIndex* |
| 332 QuicChromiumClientSession::Handle::GetPushPromiseIndex() { |
| 333 if (!session_) |
| 334 return push_promise_index_; |
| 335 |
| 336 return session_->push_promise_index(); |
| 337 } |
| 338 |
| 339 int QuicChromiumClientSession::Handle::GetPeerAddress( |
| 340 IPEndPoint* address) const { |
| 341 if (!session_) |
| 342 return ERR_CONNECTION_CLOSED; |
| 343 |
| 344 *address = session_->peer_address().impl().socket_address(); |
| 345 return OK; |
| 346 } |
| 347 |
| 189 QuicChromiumClientSession::StreamRequest::StreamRequest( | 348 QuicChromiumClientSession::StreamRequest::StreamRequest( |
| 190 const base::WeakPtr<QuicChromiumClientSession>& session, | 349 std::unique_ptr<QuicChromiumClientSession::Handle> session, |
| 191 bool requires_confirmation) | 350 bool requires_confirmation) |
| 192 : session_(session), | 351 : session_(std::move(session)), |
| 193 requires_confirmation_(requires_confirmation), | 352 requires_confirmation_(requires_confirmation), |
| 194 stream_(nullptr), | 353 stream_(nullptr), |
| 195 next_state_(STATE_NONE), | |
| 196 weak_factory_(this) {} | 354 weak_factory_(this) {} |
| 197 | 355 |
| 198 QuicChromiumClientSession::StreamRequest::~StreamRequest() { | 356 QuicChromiumClientSession::StreamRequest::~StreamRequest() { |
| 199 if (stream_) | 357 if (stream_) |
| 200 stream_->Reset(QUIC_STREAM_CANCELLED); | 358 stream_->Reset(QUIC_STREAM_CANCELLED); |
| 201 | 359 |
| 202 if (session_) | 360 if (session_->IsConnected()) |
| 203 session_->CancelRequest(this); | 361 session_->CancelRequest(this); |
| 204 } | 362 } |
| 205 | 363 |
| 206 int QuicChromiumClientSession::StreamRequest::StartRequest( | 364 int QuicChromiumClientSession::StreamRequest::StartRequest( |
| 207 const CompletionCallback& callback) { | 365 const CompletionCallback& callback) { |
| 208 DCHECK(session_); | 366 if (!session_->IsConnected()) |
| 367 return ERR_CONNECTION_CLOSED; |
| 209 | 368 |
| 210 next_state_ = STATE_WAIT_FOR_CONFIRMATION; | 369 next_state_ = STATE_WAIT_FOR_CONFIRMATION; |
| 211 int rv = DoLoop(OK); | 370 int rv = DoLoop(OK); |
| 212 if (rv == ERR_IO_PENDING) | 371 if (rv == ERR_IO_PENDING) |
| 213 callback_ = callback; | 372 callback_ = callback; |
| 214 | 373 |
| 215 return rv; | 374 return rv; |
| 216 } | 375 } |
| 217 | 376 |
| 218 QuicChromiumClientStream* | 377 QuicChromiumClientStream* |
| 219 QuicChromiumClientSession::StreamRequest::ReleaseStream() { | 378 QuicChromiumClientSession::StreamRequest::ReleaseStream() { |
| 220 DCHECK(stream_); | 379 DCHECK(stream_); |
| 221 QuicChromiumClientStream* stream = stream_; | 380 QuicChromiumClientStream* stream = stream_; |
| 222 stream_ = nullptr; | 381 stream_ = nullptr; |
| 223 return stream; | 382 return stream; |
| 224 } | 383 } |
| 225 | 384 |
| 226 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteSuccess( | 385 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteSuccess( |
| 227 QuicChromiumClientStream* stream) { | 386 QuicChromiumClientStream* stream) { |
| 228 DCHECK_EQ(STATE_REQUEST_STREAM_COMPLETE, next_state_); | 387 DCHECK_EQ(STATE_REQUEST_STREAM_COMPLETE, next_state_); |
| 229 session_.reset(); | 388 |
| 230 stream_ = stream; | 389 stream_ = stream; |
| 231 // This method is called even when the request completes synchronously. | 390 // This method is called even when the request completes synchronously. |
| 232 if (callback_) | 391 if (callback_) |
| 233 DoCallback(OK); | 392 DoCallback(OK); |
| 234 } | 393 } |
| 235 | 394 |
| 236 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure( | 395 void QuicChromiumClientSession::StreamRequest::OnRequestCompleteFailure( |
| 237 int rv) { | 396 int rv) { |
| 238 DCHECK_EQ(STATE_REQUEST_STREAM_COMPLETE, next_state_); | 397 DCHECK_EQ(STATE_REQUEST_STREAM_COMPLETE, next_state_); |
| 239 session_.reset(); | |
| 240 // This method is called even when the request completes synchronously. | 398 // This method is called even when the request completes synchronously. |
| 241 if (callback_) | 399 if (callback_) |
| 242 DoCallback(rv); | 400 DoCallback(rv); |
| 243 } | 401 } |
| 244 | 402 |
| 245 void QuicChromiumClientSession::StreamRequest::OnIOComplete(int rv) { | 403 void QuicChromiumClientSession::StreamRequest::OnIOComplete(int rv) { |
| 246 rv = DoLoop(rv); | 404 rv = DoLoop(rv); |
| 247 | 405 |
| 248 if (rv != ERR_IO_PENDING && !callback_.is_null()) { | 406 if (rv != ERR_IO_PENDING && !callback_.is_null()) { |
| 249 DoCallback(rv); | 407 DoCallback(rv); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 } | 467 } |
| 310 | 468 |
| 311 int QuicChromiumClientSession::StreamRequest::DoRequestStream() { | 469 int QuicChromiumClientSession::StreamRequest::DoRequestStream() { |
| 312 next_state_ = STATE_REQUEST_STREAM_COMPLETE; | 470 next_state_ = STATE_REQUEST_STREAM_COMPLETE; |
| 313 | 471 |
| 314 return session_->TryCreateStream(this); | 472 return session_->TryCreateStream(this); |
| 315 } | 473 } |
| 316 | 474 |
| 317 int QuicChromiumClientSession::StreamRequest::DoRequestStreamComplete(int rv) { | 475 int QuicChromiumClientSession::StreamRequest::DoRequestStreamComplete(int rv) { |
| 318 DCHECK(rv == OK || !stream_); | 476 DCHECK(rv == OK || !stream_); |
| 319 session_.reset(); | |
| 320 | 477 |
| 321 return rv; | 478 return rv; |
| 322 } | 479 } |
| 323 | 480 |
| 324 QuicChromiumClientSession::QuicChromiumClientSession( | 481 QuicChromiumClientSession::QuicChromiumClientSession( |
| 325 QuicConnection* connection, | 482 QuicConnection* connection, |
| 326 std::unique_ptr<DatagramClientSocket> socket, | 483 std::unique_ptr<DatagramClientSocket> socket, |
| 327 QuicStreamFactory* stream_factory, | 484 QuicStreamFactory* stream_factory, |
| 328 QuicCryptoClientStreamFactory* crypto_client_stream_factory, | 485 QuicCryptoClientStreamFactory* crypto_client_stream_factory, |
| 329 QuicClock* clock, | 486 QuicClock* clock, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 connect_timing_.dns_end = dns_resolution_end_time; | 549 connect_timing_.dns_end = dns_resolution_end_time; |
| 393 } | 550 } |
| 394 | 551 |
| 395 QuicChromiumClientSession::~QuicChromiumClientSession() { | 552 QuicChromiumClientSession::~QuicChromiumClientSession() { |
| 396 DCHECK(callback_.is_null()); | 553 DCHECK(callback_.is_null()); |
| 397 | 554 |
| 398 net_log_.EndEvent(NetLogEventType::QUIC_SESSION); | 555 net_log_.EndEvent(NetLogEventType::QUIC_SESSION); |
| 399 DCHECK(waiting_for_confirmation_callbacks_.empty()); | 556 DCHECK(waiting_for_confirmation_callbacks_.empty()); |
| 400 if (!dynamic_streams().empty()) | 557 if (!dynamic_streams().empty()) |
| 401 RecordUnexpectedOpenStreams(DESTRUCTOR); | 558 RecordUnexpectedOpenStreams(DESTRUCTOR); |
| 402 if (!observers_.empty()) | 559 if (!handles_.empty()) |
| 403 RecordUnexpectedObservers(DESTRUCTOR); | 560 RecordUnexpectedObservers(DESTRUCTOR); |
| 404 if (!going_away_) | 561 if (!going_away_) |
| 405 RecordUnexpectedNotGoingAway(DESTRUCTOR); | 562 RecordUnexpectedNotGoingAway(DESTRUCTOR); |
| 406 | 563 |
| 407 while (!dynamic_streams().empty() || !observers_.empty() || | 564 while (!dynamic_streams().empty() || !handles_.empty() || |
| 408 !stream_requests_.empty()) { | 565 !stream_requests_.empty()) { |
| 409 // The session must be closed before it is destroyed. | 566 // The session must be closed before it is destroyed. |
| 410 DCHECK(dynamic_streams().empty()); | 567 DCHECK(dynamic_streams().empty()); |
| 411 CloseAllStreams(ERR_UNEXPECTED); | 568 CloseAllStreams(ERR_UNEXPECTED); |
| 412 DCHECK(observers_.empty()); | 569 DCHECK(handles_.empty()); |
| 413 CloseAllObservers(ERR_UNEXPECTED); | 570 CloseAllHandles(ERR_UNEXPECTED); |
| 414 CancelAllRequests(ERR_UNEXPECTED); | 571 CancelAllRequests(ERR_UNEXPECTED); |
| 415 | 572 |
| 416 connection()->set_debug_visitor(nullptr); | 573 connection()->set_debug_visitor(nullptr); |
| 417 } | 574 } |
| 418 | 575 |
| 419 if (connection()->connected()) { | 576 if (connection()->connected()) { |
| 420 // Ensure that the connection is closed by the time the session is | 577 // Ensure that the connection is closed by the time the session is |
| 421 // destroyed. | 578 // destroyed. |
| 422 connection()->CloseConnection(QUIC_INTERNAL_ERROR, "session torn down", | 579 connection()->CloseConnection(QUIC_INTERNAL_ERROR, "session torn down", |
| 423 ConnectionCloseBehavior::SILENT_CLOSE); | 580 ConnectionCloseBehavior::SILENT_CLOSE); |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 void QuicChromiumClientSession::OnStreamFrame(const QuicStreamFrame& frame) { | 678 void QuicChromiumClientSession::OnStreamFrame(const QuicStreamFrame& frame) { |
| 522 // Record total number of stream frames. | 679 // Record total number of stream frames. |
| 523 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesInPacket", 1); | 680 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesInPacket", 1); |
| 524 | 681 |
| 525 // Record number of frames per stream in packet. | 682 // Record number of frames per stream in packet. |
| 526 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesPerStreamInPacket", 1); | 683 UMA_HISTOGRAM_COUNTS("Net.QuicNumStreamFramesPerStreamInPacket", 1); |
| 527 | 684 |
| 528 return QuicSpdySession::OnStreamFrame(frame); | 685 return QuicSpdySession::OnStreamFrame(frame); |
| 529 } | 686 } |
| 530 | 687 |
| 531 void QuicChromiumClientSession::AddObserver(Observer* observer) { | 688 void QuicChromiumClientSession::AddHandle(Handle* handle) { |
| 532 if (going_away_) { | 689 if (going_away_) { |
| 533 RecordUnexpectedObservers(ADD_OBSERVER); | 690 RecordUnexpectedObservers(ADD_OBSERVER); |
| 534 observer->OnSessionClosed(ERR_UNEXPECTED, port_migration_detected_); | 691 handle->OnSessionClosed(connection()->version(), ERR_UNEXPECTED, |
| 692 port_migration_detected_, |
| 693 |
| 694 GetConnectTiming()); |
| 535 return; | 695 return; |
| 536 } | 696 } |
| 537 | 697 |
| 538 DCHECK(!base::ContainsKey(observers_, observer)); | 698 DCHECK(!base::ContainsKey(handles_, handle)); |
| 539 observers_.insert(observer); | 699 handles_.insert(handle); |
| 540 } | 700 } |
| 541 | 701 |
| 542 void QuicChromiumClientSession::RemoveObserver(Observer* observer) { | 702 void QuicChromiumClientSession::RemoveHandle(Handle* handle) { |
| 543 DCHECK(base::ContainsKey(observers_, observer)); | 703 DCHECK(base::ContainsKey(handles_, handle)); |
| 544 observers_.erase(observer); | 704 handles_.erase(handle); |
| 545 } | |
| 546 | |
| 547 std::unique_ptr<QuicChromiumClientSession::StreamRequest> | |
| 548 QuicChromiumClientSession::CreateStreamRequest(bool requires_confirmation) { | |
| 549 // base::MakeUnique does not work because the StreamRequest constructor | |
| 550 // is private. | |
| 551 return std::unique_ptr<StreamRequest>( | |
| 552 new StreamRequest(weak_factory_.GetWeakPtr(), requires_confirmation)); | |
| 553 } | 705 } |
| 554 | 706 |
| 555 int QuicChromiumClientSession::WaitForHandshakeConfirmation( | 707 int QuicChromiumClientSession::WaitForHandshakeConfirmation( |
| 556 const CompletionCallback& callback) { | 708 const CompletionCallback& callback) { |
| 557 if (!connection()->connected()) | 709 if (!connection()->connected()) |
| 558 return ERR_CONNECTION_CLOSED; | 710 return ERR_CONNECTION_CLOSED; |
| 559 | 711 |
| 560 if (IsCryptoHandshakeConfirmed()) | 712 if (IsCryptoHandshakeConfirmed()) |
| 561 return OK; | 713 return OK; |
| 562 | 714 |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 "Net.QuicSession.HandshakeConfirmedTime", | 1105 "Net.QuicSession.HandshakeConfirmedTime", |
| 954 connect_timing_.connect_end - connect_timing_.connect_start); | 1106 connect_timing_.connect_end - connect_timing_.connect_start); |
| 955 // Track how long it has taken to finish handshake after we have finished | 1107 // Track how long it has taken to finish handshake after we have finished |
| 956 // DNS host resolution. | 1108 // DNS host resolution. |
| 957 if (!connect_timing_.dns_end.is_null()) { | 1109 if (!connect_timing_.dns_end.is_null()) { |
| 958 UMA_HISTOGRAM_TIMES( | 1110 UMA_HISTOGRAM_TIMES( |
| 959 "Net.QuicSession.HostResolution.HandshakeConfirmedTime", | 1111 "Net.QuicSession.HostResolution.HandshakeConfirmedTime", |
| 960 base::TimeTicks::Now() - connect_timing_.dns_end); | 1112 base::TimeTicks::Now() - connect_timing_.dns_end); |
| 961 } | 1113 } |
| 962 | 1114 |
| 963 ObserverSet::iterator it = observers_.begin(); | 1115 HandleSet::iterator it = handles_.begin(); |
| 964 while (it != observers_.end()) { | 1116 while (it != handles_.end()) { |
| 965 Observer* observer = *it; | 1117 Handle* handle = *it; |
| 966 ++it; | 1118 ++it; |
| 967 observer->OnCryptoHandshakeConfirmed(); | 1119 handle->OnCryptoHandshakeConfirmed(); |
| 968 } | 1120 } |
| 969 | 1121 |
| 970 NotifyRequestsOfConfirmation(OK); | 1122 NotifyRequestsOfConfirmation(OK); |
| 971 } | 1123 } |
| 972 QuicSpdySession::OnCryptoHandshakeEvent(event); | 1124 QuicSpdySession::OnCryptoHandshakeEvent(event); |
| 973 } | 1125 } |
| 974 | 1126 |
| 975 void QuicChromiumClientSession::OnCryptoHandshakeMessageSent( | 1127 void QuicChromiumClientSession::OnCryptoHandshakeMessageSent( |
| 976 const CryptoHandshakeMessage& message) { | 1128 const CryptoHandshakeMessage& message) { |
| 977 logger_->OnCryptoHandshakeMessageSent(message); | 1129 logger_->OnCryptoHandshakeMessageSent(message); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1101 | 1253 |
| 1102 if (!callback_.is_null()) { | 1254 if (!callback_.is_null()) { |
| 1103 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); | 1255 base::ResetAndReturn(&callback_).Run(ERR_QUIC_PROTOCOL_ERROR); |
| 1104 } | 1256 } |
| 1105 | 1257 |
| 1106 for (auto& socket : sockets_) { | 1258 for (auto& socket : sockets_) { |
| 1107 socket->Close(); | 1259 socket->Close(); |
| 1108 } | 1260 } |
| 1109 DCHECK(dynamic_streams().empty()); | 1261 DCHECK(dynamic_streams().empty()); |
| 1110 CloseAllStreams(ERR_UNEXPECTED); | 1262 CloseAllStreams(ERR_UNEXPECTED); |
| 1111 CloseAllObservers(ERR_UNEXPECTED); | 1263 CloseAllHandles(ERR_UNEXPECTED); |
| 1112 CancelAllRequests(ERR_CONNECTION_CLOSED); | 1264 CancelAllRequests(ERR_CONNECTION_CLOSED); |
| 1113 NotifyRequestsOfConfirmation(ERR_CONNECTION_CLOSED); | 1265 NotifyRequestsOfConfirmation(ERR_CONNECTION_CLOSED); |
| 1114 NotifyFactoryOfSessionClosedLater(); | 1266 NotifyFactoryOfSessionClosedLater(); |
| 1115 } | 1267 } |
| 1116 | 1268 |
| 1117 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( | 1269 void QuicChromiumClientSession::OnSuccessfulVersionNegotiation( |
| 1118 const QuicVersion& version) { | 1270 const QuicVersion& version) { |
| 1119 logger_->OnSuccessfulVersionNegotiation(version); | 1271 logger_->OnSuccessfulVersionNegotiation(version); |
| 1120 QuicSpdySession::OnSuccessfulVersionNegotiation(version); | 1272 QuicSpdySession::OnSuccessfulVersionNegotiation(version); |
| 1121 | |
| 1122 ObserverSet::iterator it = observers_.begin(); | |
| 1123 while (it != observers_.end()) { | |
| 1124 Observer* observer = *it; | |
| 1125 ++it; | |
| 1126 observer->OnSuccessfulVersionNegotiation(version); | |
| 1127 } | |
| 1128 } | 1273 } |
| 1129 | 1274 |
| 1130 int QuicChromiumClientSession::HandleWriteError( | 1275 int QuicChromiumClientSession::HandleWriteError( |
| 1131 int error_code, | 1276 int error_code, |
| 1132 scoped_refptr<StringIOBuffer> packet) { | 1277 scoped_refptr<StringIOBuffer> packet) { |
| 1133 if (stream_factory_ == nullptr || | 1278 if (stream_factory_ == nullptr || |
| 1134 !stream_factory_->migrate_sessions_on_network_change()) { | 1279 !stream_factory_->migrate_sessions_on_network_change()) { |
| 1135 return error_code; | 1280 return error_code; |
| 1136 } | 1281 } |
| 1137 DCHECK(packet != nullptr); | 1282 DCHECK(packet != nullptr); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1323 | 1468 |
| 1324 void QuicChromiumClientSession::CloseSessionOnError(int net_error, | 1469 void QuicChromiumClientSession::CloseSessionOnError(int net_error, |
| 1325 QuicErrorCode quic_error) { | 1470 QuicErrorCode quic_error) { |
| 1326 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.CloseSessionOnError", | 1471 UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.CloseSessionOnError", |
| 1327 -net_error); | 1472 -net_error); |
| 1328 | 1473 |
| 1329 if (!callback_.is_null()) { | 1474 if (!callback_.is_null()) { |
| 1330 base::ResetAndReturn(&callback_).Run(net_error); | 1475 base::ResetAndReturn(&callback_).Run(net_error); |
| 1331 } | 1476 } |
| 1332 CloseAllStreams(net_error); | 1477 CloseAllStreams(net_error); |
| 1333 CloseAllObservers(net_error); | 1478 CloseAllHandles(net_error); |
| 1334 net_log_.AddEvent(NetLogEventType::QUIC_SESSION_CLOSE_ON_ERROR, | 1479 net_log_.AddEvent(NetLogEventType::QUIC_SESSION_CLOSE_ON_ERROR, |
| 1335 NetLog::IntCallback("net_error", net_error)); | 1480 NetLog::IntCallback("net_error", net_error)); |
| 1336 | 1481 |
| 1337 if (connection()->connected()) | 1482 if (connection()->connected()) |
| 1338 connection()->CloseConnection(quic_error, "net error", | 1483 connection()->CloseConnection(quic_error, "net error", |
| 1339 ConnectionCloseBehavior::SILENT_CLOSE); | 1484 ConnectionCloseBehavior::SILENT_CLOSE); |
| 1340 DCHECK(!connection()->connected()); | 1485 DCHECK(!connection()->connected()); |
| 1341 | 1486 |
| 1342 NotifyFactoryOfSessionClosed(); | 1487 NotifyFactoryOfSessionClosed(); |
| 1343 } | 1488 } |
| 1344 | 1489 |
| 1345 void QuicChromiumClientSession::CloseAllStreams(int net_error) { | 1490 void QuicChromiumClientSession::CloseAllStreams(int net_error) { |
| 1346 while (!dynamic_streams().empty()) { | 1491 while (!dynamic_streams().empty()) { |
| 1347 QuicStream* stream = dynamic_streams().begin()->second.get(); | 1492 QuicStream* stream = dynamic_streams().begin()->second.get(); |
| 1348 QuicStreamId id = stream->id(); | 1493 QuicStreamId id = stream->id(); |
| 1349 static_cast<QuicChromiumClientStream*>(stream)->OnError(net_error); | 1494 static_cast<QuicChromiumClientStream*>(stream)->OnError(net_error); |
| 1350 CloseStream(id); | 1495 CloseStream(id); |
| 1351 } | 1496 } |
| 1352 } | 1497 } |
| 1353 | 1498 |
| 1354 void QuicChromiumClientSession::CloseAllObservers(int net_error) { | 1499 void QuicChromiumClientSession::CloseAllHandles(int net_error) { |
| 1355 while (!observers_.empty()) { | 1500 while (!handles_.empty()) { |
| 1356 Observer* observer = *observers_.begin(); | 1501 Handle* handle = *handles_.begin(); |
| 1357 observers_.erase(observer); | 1502 handles_.erase(handle); |
| 1358 observer->OnSessionClosed(net_error, port_migration_detected_); | 1503 handle->OnSessionClosed(connection()->version(), net_error, |
| 1504 port_migration_detected_, GetConnectTiming()); |
| 1359 } | 1505 } |
| 1360 } | 1506 } |
| 1361 | 1507 |
| 1362 void QuicChromiumClientSession::CancelAllRequests(int net_error) { | 1508 void QuicChromiumClientSession::CancelAllRequests(int net_error) { |
| 1363 UMA_HISTOGRAM_COUNTS_1000("Net.QuicSession.AbortedPendingStreamRequests", | 1509 UMA_HISTOGRAM_COUNTS_1000("Net.QuicSession.AbortedPendingStreamRequests", |
| 1364 stream_requests_.size()); | 1510 stream_requests_.size()); |
| 1365 | 1511 |
| 1366 while (!stream_requests_.empty()) { | 1512 while (!stream_requests_.empty()) { |
| 1367 StreamRequest* request = stream_requests_.front(); | 1513 StreamRequest* request = stream_requests_.front(); |
| 1368 stream_requests_.pop_front(); | 1514 stream_requests_.pop_front(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1403 std::unique_ptr<base::ListValue> alias_list(new base::ListValue()); | 1549 std::unique_ptr<base::ListValue> alias_list(new base::ListValue()); |
| 1404 for (std::set<HostPortPair>::const_iterator it = aliases.begin(); | 1550 for (std::set<HostPortPair>::const_iterator it = aliases.begin(); |
| 1405 it != aliases.end(); it++) { | 1551 it != aliases.end(); it++) { |
| 1406 alias_list->AppendString(it->ToString()); | 1552 alias_list->AppendString(it->ToString()); |
| 1407 } | 1553 } |
| 1408 dict->Set("aliases", std::move(alias_list)); | 1554 dict->Set("aliases", std::move(alias_list)); |
| 1409 | 1555 |
| 1410 return std::move(dict); | 1556 return std::move(dict); |
| 1411 } | 1557 } |
| 1412 | 1558 |
| 1413 base::WeakPtr<QuicChromiumClientSession> | 1559 std::unique_ptr<QuicChromiumClientSession::Handle> |
| 1414 QuicChromiumClientSession::GetWeakPtr() { | 1560 QuicChromiumClientSession::CreateHandle() { |
| 1415 return weak_factory_.GetWeakPtr(); | 1561 return base::MakeUnique<QuicChromiumClientSession::Handle>( |
| 1562 weak_factory_.GetWeakPtr()); |
| 1416 } | 1563 } |
| 1417 | 1564 |
| 1418 void QuicChromiumClientSession::OnReadError( | 1565 void QuicChromiumClientSession::OnReadError( |
| 1419 int result, | 1566 int result, |
| 1420 const DatagramClientSocket* socket) { | 1567 const DatagramClientSocket* socket) { |
| 1421 DCHECK(socket != nullptr); | 1568 DCHECK(socket != nullptr); |
| 1422 if (socket != GetDefaultSocket()) { | 1569 if (socket != GetDefaultSocket()) { |
| 1423 // Ignore read errors from old sockets that are no longer active. | 1570 // Ignore read errors from old sockets that are no longer active. |
| 1424 // TODO(jri): Maybe clean up old sockets on error. | 1571 // TODO(jri): Maybe clean up old sockets on error. |
| 1425 return; | 1572 return; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 // on the write to the new socket. | 1648 // on the write to the new socket. |
| 1502 task_runner_->PostTask( | 1649 task_runner_->PostTask( |
| 1503 FROM_HERE, base::Bind(&QuicChromiumClientSession::WriteToNewSocket, | 1650 FROM_HERE, base::Bind(&QuicChromiumClientSession::WriteToNewSocket, |
| 1504 weak_factory_.GetWeakPtr())); | 1651 weak_factory_.GetWeakPtr())); |
| 1505 // Migration completed. | 1652 // Migration completed. |
| 1506 migration_pending_ = false; | 1653 migration_pending_ = false; |
| 1507 return true; | 1654 return true; |
| 1508 } | 1655 } |
| 1509 | 1656 |
| 1510 void QuicChromiumClientSession::PopulateNetErrorDetails( | 1657 void QuicChromiumClientSession::PopulateNetErrorDetails( |
| 1511 NetErrorDetails* details) { | 1658 NetErrorDetails* details) const { |
| 1512 details->quic_port_migration_detected = port_migration_detected_; | 1659 details->quic_port_migration_detected = port_migration_detected_; |
| 1513 } | 1660 } |
| 1514 | 1661 |
| 1515 const DatagramClientSocket* QuicChromiumClientSession::GetDefaultSocket() | 1662 const DatagramClientSocket* QuicChromiumClientSession::GetDefaultSocket() |
| 1516 const { | 1663 const { |
| 1517 DCHECK(sockets_.back().get() != nullptr); | 1664 DCHECK(sockets_.back().get() != nullptr); |
| 1518 // The most recently added socket is the currently active one. | 1665 // The most recently added socket is the currently active one. |
| 1519 return sockets_.back().get(); | 1666 return sockets_.back().get(); |
| 1520 } | 1667 } |
| 1521 | 1668 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1601 } | 1748 } |
| 1602 | 1749 |
| 1603 size_t QuicChromiumClientSession::EstimateMemoryUsage() const { | 1750 size_t QuicChromiumClientSession::EstimateMemoryUsage() const { |
| 1604 // TODO(xunjieli): Estimate |crypto_stream_|, QuicSpdySession's | 1751 // TODO(xunjieli): Estimate |crypto_stream_|, QuicSpdySession's |
| 1605 // QuicHeaderList, QuicSession's QuiCWriteBlockedList, open streams and | 1752 // QuicHeaderList, QuicSession's QuiCWriteBlockedList, open streams and |
| 1606 // unacked packet map. | 1753 // unacked packet map. |
| 1607 return base::trace_event::EstimateMemoryUsage(packet_readers_); | 1754 return base::trace_event::EstimateMemoryUsage(packet_readers_); |
| 1608 } | 1755 } |
| 1609 | 1756 |
| 1610 } // namespace net | 1757 } // namespace net |
| OLD | NEW |