Chromium Code Reviews| 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_stream_factory.h" | 5 #include "net/quic/chromium/quic_stream_factory.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <tuple> | 8 #include <tuple> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 void RunAuxilaryJob(); | 335 void RunAuxilaryJob(); |
| 336 | 336 |
| 337 void Cancel(); | 337 void Cancel(); |
| 338 | 338 |
| 339 void CancelWaitForDataReadyCallback(); | 339 void CancelWaitForDataReadyCallback(); |
| 340 | 340 |
| 341 const QuicSessionKey& key() const { return key_; } | 341 const QuicSessionKey& key() const { return key_; } |
| 342 | 342 |
| 343 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } | 343 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
| 344 | 344 |
| 345 const NetLogWithSource net_log() { return job_net_log_; } | |
| 346 | |
| 345 private: | 347 private: |
| 346 enum IoState { | 348 enum IoState { |
| 347 STATE_NONE, | 349 STATE_NONE, |
| 348 STATE_RESOLVE_HOST, | 350 STATE_RESOLVE_HOST, |
| 349 STATE_RESOLVE_HOST_COMPLETE, | 351 STATE_RESOLVE_HOST_COMPLETE, |
| 350 STATE_LOAD_SERVER_INFO, | 352 STATE_LOAD_SERVER_INFO, |
| 351 STATE_LOAD_SERVER_INFO_COMPLETE, | 353 STATE_LOAD_SERVER_INFO_COMPLETE, |
| 352 STATE_CONNECT, | 354 STATE_CONNECT, |
| 353 STATE_RESUME_CONNECT, | 355 STATE_RESUME_CONNECT, |
| 354 STATE_CONNECT_COMPLETE, | 356 STATE_CONNECT_COMPLETE, |
| 355 }; | 357 }; |
| 356 IoState io_state_; | 358 IoState io_state_; |
| 357 | 359 |
| 358 QuicStreamFactory* factory_; | 360 QuicStreamFactory* factory_; |
| 359 HostResolver* host_resolver_; | 361 HostResolver* host_resolver_; |
| 360 std::unique_ptr<HostResolver::Request> request_; | 362 std::unique_ptr<HostResolver::Request> request_; |
| 361 QuicSessionKey key_; | 363 QuicSessionKey key_; |
| 362 int cert_verify_flags_; | 364 int cert_verify_flags_; |
| 363 bool was_alternative_service_recently_broken_; | 365 bool was_alternative_service_recently_broken_; |
| 364 std::unique_ptr<QuicServerInfo> server_info_; | 366 std::unique_ptr<QuicServerInfo> server_info_; |
| 365 bool started_another_job_; | 367 bool started_another_job_; |
| 366 const NetLogWithSource net_log_; | 368 const NetLogWithSource net_log_; |
| 369 const NetLogWithSource job_net_log_; | |
| 367 int num_sent_client_hellos_; | 370 int num_sent_client_hellos_; |
| 368 QuicChromiumClientSession* session_; | 371 QuicChromiumClientSession* session_; |
| 369 CompletionCallback callback_; | 372 CompletionCallback callback_; |
| 370 AddressList address_list_; | 373 AddressList address_list_; |
| 371 base::TimeTicks dns_resolution_start_time_; | 374 base::TimeTicks dns_resolution_start_time_; |
| 372 base::TimeTicks dns_resolution_end_time_; | 375 base::TimeTicks dns_resolution_end_time_; |
| 373 base::WeakPtrFactory<Job> weak_factory_; | 376 base::WeakPtrFactory<Job> weak_factory_; |
| 374 DISALLOW_COPY_AND_ASSIGN(Job); | 377 DISALLOW_COPY_AND_ASSIGN(Job); |
| 375 }; | 378 }; |
| 376 | 379 |
| 377 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 380 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
| 378 HostResolver* host_resolver, | 381 HostResolver* host_resolver, |
| 379 const QuicSessionKey& key, | 382 const QuicSessionKey& key, |
| 380 bool was_alternative_service_recently_broken, | 383 bool was_alternative_service_recently_broken, |
| 381 int cert_verify_flags, | 384 int cert_verify_flags, |
| 382 std::unique_ptr<QuicServerInfo> server_info, | 385 std::unique_ptr<QuicServerInfo> server_info, |
| 383 const NetLogWithSource& net_log) | 386 const NetLogWithSource& net_log) |
| 384 : io_state_(STATE_RESOLVE_HOST), | 387 : io_state_(STATE_RESOLVE_HOST), |
| 385 factory_(factory), | 388 factory_(factory), |
| 386 host_resolver_(host_resolver), | 389 host_resolver_(host_resolver), |
| 387 key_(key), | 390 key_(key), |
| 388 cert_verify_flags_(cert_verify_flags), | 391 cert_verify_flags_(cert_verify_flags), |
| 389 was_alternative_service_recently_broken_( | 392 was_alternative_service_recently_broken_( |
| 390 was_alternative_service_recently_broken), | 393 was_alternative_service_recently_broken), |
| 391 server_info_(std::move(server_info)), | 394 server_info_(std::move(server_info)), |
| 392 started_another_job_(false), | 395 started_another_job_(false), |
| 393 net_log_(net_log), | 396 net_log_(net_log), |
| 397 job_net_log_( | |
| 398 NetLogWithSource::Make(net_log.net_log(), | |
| 399 NetLogSourceType::QUIC_STREAM_FACTORY_JOB)), | |
| 394 num_sent_client_hellos_(0), | 400 num_sent_client_hellos_(0), |
| 395 session_(nullptr), | 401 session_(nullptr), |
| 396 weak_factory_(this) {} | 402 weak_factory_(this) { |
| 403 job_net_log_.BeginEvent( | |
| 404 NetLogEventType::QUIC_STREAM_FACTORY_JOB, | |
| 405 NetLog::BoolCallback("resume_exisiting_session", false)); | |
| 406 net_log_.AddEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND, | |
| 407 job_net_log_.source().ToEventParametersCallback()); | |
| 408 | |
| 409 job_net_log_.AddEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND, | |
| 410 net_log_.source().ToEventParametersCallback()); | |
| 411 } | |
| 397 | 412 |
| 398 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 413 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
| 399 HostResolver* host_resolver, | 414 HostResolver* host_resolver, |
| 400 QuicChromiumClientSession* session, | 415 QuicChromiumClientSession* session, |
| 401 const QuicSessionKey& key) | 416 const QuicSessionKey& key) |
| 402 : io_state_(STATE_RESUME_CONNECT), | 417 : io_state_(STATE_RESUME_CONNECT), |
| 403 factory_(factory), | 418 factory_(factory), |
| 404 host_resolver_(host_resolver), // unused | 419 host_resolver_(host_resolver), // unused |
| 405 key_(key), | 420 key_(key), |
| 406 cert_verify_flags_(0), // unused | 421 cert_verify_flags_(0), // unused |
| 407 was_alternative_service_recently_broken_(false), // unused | 422 was_alternative_service_recently_broken_(false), // unused |
| 408 started_another_job_(false), // unused | 423 started_another_job_(false), // unused |
| 409 net_log_(session->net_log()), // unused | 424 net_log_(session->net_log()), // unused |
| 425 job_net_log_( | |
| 426 NetLogWithSource::Make(session->net_log().net_log(), | |
| 427 NetLogSourceType::QUIC_STREAM_FACTORY_JOB)), | |
| 410 num_sent_client_hellos_(0), | 428 num_sent_client_hellos_(0), |
| 411 session_(session), | 429 session_(session), |
| 412 weak_factory_(this) {} | 430 weak_factory_(this) { |
| 431 job_net_log_.BeginEvent( | |
| 432 NetLogEventType::QUIC_STREAM_FACTORY_JOB, | |
| 433 NetLog::BoolCallback("resume_exisiting_session", true)); | |
| 434 } | |
| 413 | 435 |
| 414 QuicStreamFactory::Job::~Job() { | 436 QuicStreamFactory::Job::~Job() { |
| 437 job_net_log_.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB); | |
| 415 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback. | 438 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback. |
| 416 if (server_info_) | 439 if (server_info_) |
| 417 server_info_->ResetWaitForDataReadyCallback(); | 440 server_info_->ResetWaitForDataReadyCallback(); |
| 418 } | 441 } |
| 419 | 442 |
| 420 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { | 443 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { |
| 421 int rv = DoLoop(OK); | 444 int rv = DoLoop(OK); |
| 422 if (rv == ERR_IO_PENDING) | 445 if (rv == ERR_IO_PENDING) |
| 423 callback_ = callback; | 446 callback_ = callback; |
| 424 | 447 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 472 } | 495 } |
| 473 | 496 |
| 474 void QuicStreamFactory::Job::RunAuxilaryJob() { | 497 void QuicStreamFactory::Job::RunAuxilaryJob() { |
| 475 int rv = Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 498 int rv = Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 476 base::Unretained(factory_), this)); | 499 base::Unretained(factory_), this)); |
| 477 if (rv != ERR_IO_PENDING) | 500 if (rv != ERR_IO_PENDING) |
| 478 factory_->OnJobComplete(this, rv); | 501 factory_->OnJobComplete(this, rv); |
| 479 } | 502 } |
| 480 | 503 |
| 481 void QuicStreamFactory::Job::Cancel() { | 504 void QuicStreamFactory::Job::Cancel() { |
| 505 job_net_log_.AddEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_CANCELLED); | |
| 482 callback_.Reset(); | 506 callback_.Reset(); |
| 483 if (session_) | 507 if (session_) |
| 484 session_->connection()->CloseConnection( | 508 session_->connection()->CloseConnection( |
| 485 QUIC_CONNECTION_CANCELLED, "New job canceled.", | 509 QUIC_CONNECTION_CANCELLED, "New job canceled.", |
| 486 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 510 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
| 487 } | 511 } |
| 488 | 512 |
| 489 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { | 513 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { |
| 490 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. | 514 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. |
| 491 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) | 515 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) |
| 492 return; | 516 return; |
| 493 server_info_->CancelWaitForDataReadyCallback(); | 517 server_info_->CancelWaitForDataReadyCallback(); |
| 494 OnIOComplete(OK); | 518 OnIOComplete(OK); |
| 495 } | 519 } |
| 496 | 520 |
| 497 int QuicStreamFactory::Job::DoResolveHost() { | 521 int QuicStreamFactory::Job::DoResolveHost() { |
| 522 job_net_log_.BeginEvent( | |
| 523 NetLogEventType::QUIC_STREAM_FACTORY_JOB_RESOLVE_HOST, | |
| 524 NetLog::BoolCallback("load_server_info", server_info_.get() != nullptr)); | |
| 498 dns_resolution_start_time_ = base::TimeTicks::Now(); | 525 dns_resolution_start_time_ = base::TimeTicks::Now(); |
| 499 // Start loading the data now, and wait for it after we resolve the host. | 526 // Start loading the data now, and wait for it after we resolve the host. |
| 500 if (server_info_) | 527 if (server_info_) |
| 501 server_info_->Start(); | 528 server_info_->Start(); |
| 502 | 529 |
| 503 io_state_ = STATE_RESOLVE_HOST_COMPLETE; | 530 io_state_ = STATE_RESOLVE_HOST_COMPLETE; |
| 504 return host_resolver_->Resolve( | 531 return host_resolver_->Resolve( |
| 505 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, | 532 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, |
| 506 &address_list_, | 533 &address_list_, |
| 507 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), | 534 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), |
| 508 &request_, net_log_); | 535 &request_, job_net_log_); |
| 509 } | 536 } |
| 510 | 537 |
| 511 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { | 538 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { |
| 539 job_net_log_.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_RESOLVE_HOST); | |
| 540 | |
| 512 dns_resolution_end_time_ = base::TimeTicks::Now(); | 541 dns_resolution_end_time_ = base::TimeTicks::Now(); |
| 513 if (rv != OK) | 542 if (rv != OK) |
| 514 return rv; | 543 return rv; |
| 515 | 544 |
| 516 DCHECK(!factory_->HasActiveSession(key_.server_id())); | 545 DCHECK(!factory_->HasActiveSession(key_.server_id())); |
| 517 | 546 |
| 518 // Inform the factory of this resolution, which will set up | 547 // Inform the factory of this resolution, which will set up |
| 519 // a session alias, if possible. | 548 // a session alias, if possible. |
| 520 if (factory_->OnResolution(key_, address_list_)) | 549 if (factory_->OnResolution(key_, address_list_)) |
| 521 return OK; | 550 return OK; |
| 522 | 551 |
| 523 if (server_info_) | 552 if (server_info_) |
| 524 io_state_ = STATE_LOAD_SERVER_INFO; | 553 io_state_ = STATE_LOAD_SERVER_INFO; |
| 525 else | 554 else |
| 526 io_state_ = STATE_CONNECT; | 555 io_state_ = STATE_CONNECT; |
| 527 return OK; | 556 return OK; |
| 528 } | 557 } |
| 529 | 558 |
| 530 int QuicStreamFactory::Job::DoLoadServerInfo() { | 559 int QuicStreamFactory::Job::DoLoadServerInfo() { |
| 531 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; | 560 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; |
| 532 | 561 |
| 533 DCHECK(server_info_); | 562 DCHECK(server_info_); |
| 534 | 563 |
| 535 // To mitigate the effects of disk cache taking too long to load QUIC server | 564 // To mitigate the effects of disk cache taking too long to load QUIC server |
| 536 // information, set up a timer to cancel WaitForDataReady's callback. | 565 // information, set up a timer to cancel WaitForDataReady's callback. |
| 566 | |
| 567 int64_t load_server_info_timeout_ms = 0; | |
| 537 if (factory_->load_server_info_timeout_srtt_multiplier_ > 0) { | 568 if (factory_->load_server_info_timeout_srtt_multiplier_ > 0) { |
| 538 const int kMaxLoadServerInfoTimeoutMs = 50; | 569 const int kMaxLoadServerInfoTimeoutMs = 50; |
| 539 // Wait for DiskCache a maximum of 50ms. | 570 // Wait for DiskCache a maximum of 50ms. |
| 540 int64_t load_server_info_timeout_ms = | 571 load_server_info_timeout_ms = |
| 541 std::min(static_cast<int>( | 572 std::min(static_cast<int>( |
| 542 (factory_->load_server_info_timeout_srtt_multiplier_ * | 573 (factory_->load_server_info_timeout_srtt_multiplier_ * |
| 543 factory_->GetServerNetworkStatsSmoothedRttInMicroseconds( | 574 factory_->GetServerNetworkStatsSmoothedRttInMicroseconds( |
| 544 key_.server_id())) / | 575 key_.server_id())) / |
| 545 1000), | 576 1000), |
| 546 kMaxLoadServerInfoTimeoutMs); | 577 kMaxLoadServerInfoTimeoutMs); |
| 547 if (load_server_info_timeout_ms > 0) { | 578 if (load_server_info_timeout_ms > 0) { |
| 548 factory_->task_runner_->PostDelayedTask( | 579 factory_->task_runner_->PostDelayedTask( |
| 549 FROM_HERE, | 580 FROM_HERE, |
| 550 base::Bind(&QuicStreamFactory::Job::CancelWaitForDataReadyCallback, | 581 base::Bind(&QuicStreamFactory::Job::CancelWaitForDataReadyCallback, |
| 551 GetWeakPtr()), | 582 GetWeakPtr()), |
| 552 base::TimeDelta::FromMilliseconds(load_server_info_timeout_ms)); | 583 base::TimeDelta::FromMilliseconds(load_server_info_timeout_ms)); |
| 553 } | 584 } |
| 554 } | 585 } |
| 555 | 586 |
| 587 job_net_log_.BeginEvent( | |
| 588 NetLogEventType::QUIC_STREAM_FACTORY_JOB_LOAD_SERVER_INFO, | |
| 589 NetLog::Int64Callback("load_server_info_timeout_ms", | |
| 590 load_server_info_timeout_ms)); | |
| 591 | |
| 556 int rv = server_info_->WaitForDataReady( | 592 int rv = server_info_->WaitForDataReady( |
| 557 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); | 593 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
| 558 if (rv == ERR_IO_PENDING && factory_->enable_connection_racing()) { | 594 if (rv == ERR_IO_PENDING && factory_->enable_connection_racing()) { |
| 559 // If we are waiting to load server config from the disk cache, then start | 595 // If we are waiting to load server config from the disk cache, then start |
| 560 // another job. | 596 // another job. |
| 561 started_another_job_ = true; | 597 started_another_job_ = true; |
| 598 job_net_log_.AddEvent(NetLogEventType::QUIC_STREAM_FACTORY_START_AUX_JOB); | |
| 562 factory_->CreateAuxilaryJob(key_, cert_verify_flags_, net_log_); | 599 factory_->CreateAuxilaryJob(key_, cert_verify_flags_, net_log_); |
| 563 } | 600 } |
| 601 | |
| 564 return rv; | 602 return rv; |
| 565 } | 603 } |
| 566 | 604 |
| 567 int QuicStreamFactory::Job::DoLoadServerInfoComplete(int rv) { | 605 int QuicStreamFactory::Job::DoLoadServerInfoComplete(int rv) { |
| 568 UMA_HISTOGRAM_TIMES("Net.QuicServerInfo.DiskCacheWaitForDataReadyTime", | 606 UMA_HISTOGRAM_TIMES("Net.QuicServerInfo.DiskCacheWaitForDataReadyTime", |
| 569 base::TimeTicks::Now() - dns_resolution_end_time_); | 607 base::TimeTicks::Now() - dns_resolution_end_time_); |
| 570 | 608 |
| 609 job_net_log_.EndEvent( | |
| 610 NetLogEventType::QUIC_STREAM_FACTORY_JOB_LOAD_SERVER_INFO); | |
| 611 | |
| 571 if (rv != OK) | 612 if (rv != OK) |
| 572 server_info_.reset(); | 613 server_info_.reset(); |
| 573 | 614 |
| 574 if (started_another_job_ && | 615 if (started_another_job_ && |
| 575 (!server_info_ || server_info_->state().server_config.empty() || | 616 (!server_info_ || server_info_->state().server_config.empty() || |
| 576 !factory_->CryptoConfigCacheIsEmpty(key_.server_id()))) { | 617 !factory_->CryptoConfigCacheIsEmpty(key_.server_id()))) { |
| 577 // If we have started another job and if we didn't load the server config | 618 // If we have started another job and if we didn't load the server config |
| 578 // from the disk cache or if we have received a new server config from the | 619 // from the disk cache or if we have received a new server config from the |
| 579 // server, then cancel the current job. | 620 // server, then cancel the current job. |
| 580 io_state_ = STATE_NONE; | 621 io_state_ = STATE_NONE; |
| 581 return ERR_CONNECTION_CLOSED; | 622 return ERR_CONNECTION_CLOSED; |
| 582 } | 623 } |
| 583 | 624 |
| 584 io_state_ = STATE_CONNECT; | 625 io_state_ = STATE_CONNECT; |
| 585 return OK; | 626 return OK; |
| 586 } | 627 } |
| 587 | 628 |
| 588 int QuicStreamFactory::Job::DoConnect() { | 629 int QuicStreamFactory::Job::DoConnect() { |
| 589 io_state_ = STATE_CONNECT_COMPLETE; | 630 io_state_ = STATE_CONNECT_COMPLETE; |
| 590 | 631 |
| 591 bool require_confirmation = factory_->require_confirmation() || | 632 bool require_confirmation = factory_->require_confirmation() || |
| 592 was_alternative_service_recently_broken_; | 633 was_alternative_service_recently_broken_; |
| 634 job_net_log_.BeginEvent( | |
| 635 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT, | |
| 636 NetLog::BoolCallback("require_confirmation", require_confirmation)); | |
| 593 | 637 |
| 594 int rv = factory_->CreateSession( | 638 int rv = factory_->CreateSession( |
| 595 key_, cert_verify_flags_, std::move(server_info_), require_confirmation, | 639 key_, cert_verify_flags_, std::move(server_info_), require_confirmation, |
| 596 address_list_, dns_resolution_start_time_, dns_resolution_end_time_, | 640 address_list_, dns_resolution_start_time_, dns_resolution_end_time_, |
| 597 net_log_, &session_); | 641 job_net_log_, &session_); |
| 598 if (rv != OK) { | 642 if (rv != OK) { |
| 599 DCHECK(rv != ERR_IO_PENDING); | 643 DCHECK(rv != ERR_IO_PENDING); |
| 600 DCHECK(!session_); | 644 DCHECK(!session_); |
| 601 return rv; | 645 return rv; |
| 602 } | 646 } |
| 603 | 647 |
| 604 if (!session_->connection()->connected()) | 648 if (!session_->connection()->connected()) |
| 605 return ERR_CONNECTION_CLOSED; | 649 return ERR_CONNECTION_CLOSED; |
| 606 | 650 |
| 607 session_->StartReading(); | 651 session_->StartReading(); |
| 608 if (!session_->connection()->connected()) | 652 if (!session_->connection()->connected()) |
| 609 return ERR_QUIC_PROTOCOL_ERROR; | 653 return ERR_QUIC_PROTOCOL_ERROR; |
| 610 | 654 |
| 611 rv = session_->CryptoConnect( | 655 rv = session_->CryptoConnect( |
| 612 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); | 656 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
| 613 | 657 |
| 614 if (!session_->connection()->connected() && | 658 if (!session_->connection()->connected() && |
| 615 session_->error() == QUIC_PROOF_INVALID) { | 659 session_->error() == QUIC_PROOF_INVALID) { |
| 616 return ERR_QUIC_HANDSHAKE_FAILED; | 660 return ERR_QUIC_HANDSHAKE_FAILED; |
| 617 } | 661 } |
| 618 | 662 |
| 619 return rv; | 663 return rv; |
| 620 } | 664 } |
| 621 | 665 |
| 622 int QuicStreamFactory::Job::DoResumeConnect() { | 666 int QuicStreamFactory::Job::DoResumeConnect() { |
| 667 job_net_log_.BeginEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT, | |
| 668 NetLog::BoolCallback("resume_connection", true)); | |
| 623 io_state_ = STATE_CONNECT_COMPLETE; | 669 io_state_ = STATE_CONNECT_COMPLETE; |
| 624 | 670 |
| 625 int rv = session_->ResumeCryptoConnect( | 671 int rv = session_->ResumeCryptoConnect( |
| 626 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); | 672 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
| 627 | 673 |
| 628 return rv; | 674 return rv; |
| 629 } | 675 } |
| 630 | 676 |
| 631 int QuicStreamFactory::Job::DoConnectComplete(int rv) { | 677 int QuicStreamFactory::Job::DoConnectComplete(int rv) { |
| 678 job_net_log_.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT); | |
| 632 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { | 679 if (session_ && session_->error() == QUIC_CRYPTO_HANDSHAKE_STATELESS_REJECT) { |
| 633 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); | 680 num_sent_client_hellos_ += session_->GetNumSentClientHellos(); |
| 634 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) | 681 if (num_sent_client_hellos_ >= QuicCryptoClientStream::kMaxClientHellos) |
| 635 return ERR_QUIC_HANDSHAKE_FAILED; | 682 return ERR_QUIC_HANDSHAKE_FAILED; |
| 636 // The handshake was rejected statelessly, so create another connection | 683 // The handshake was rejected statelessly, so create another connection |
| 637 // to resume the handshake. | 684 // to resume the handshake. |
| 638 io_state_ = STATE_CONNECT; | 685 io_state_ = STATE_CONNECT; |
| 639 return OK; | 686 return OK; |
| 640 } | 687 } |
| 641 | 688 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 694 DCHECK(session_); | 741 DCHECK(session_); |
| 695 return rv; | 742 return rv; |
| 696 } | 743 } |
| 697 | 744 |
| 698 void QuicStreamRequest::SetSession(QuicChromiumClientSession* session) { | 745 void QuicStreamRequest::SetSession(QuicChromiumClientSession* session) { |
| 699 DCHECK(session); | 746 DCHECK(session); |
| 700 session_ = session->GetWeakPtr(); | 747 session_ = session->GetWeakPtr(); |
| 701 } | 748 } |
| 702 | 749 |
| 703 void QuicStreamRequest::OnRequestComplete(int rv) { | 750 void QuicStreamRequest::OnRequestComplete(int rv) { |
| 751 net_log_.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_CREATE_HTTP_STREAM); | |
| 704 factory_ = nullptr; | 752 factory_ = nullptr; |
| 705 callback_.Run(rv); | 753 callback_.Run(rv); |
| 706 } | 754 } |
| 707 | 755 |
| 708 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { | 756 base::TimeDelta QuicStreamRequest::GetTimeDelayForWaitingJob() const { |
| 709 if (!factory_) | 757 if (!factory_) |
| 710 return base::TimeDelta(); | 758 return base::TimeDelta(); |
| 711 return factory_->GetTimeDelayForWaitingJob(server_id_); | 759 return factory_->GetTimeDelayForWaitingJob(server_id_); |
| 712 } | 760 } |
| 713 | 761 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 bool migrate_sessions_early, | 810 bool migrate_sessions_early, |
| 763 bool allow_server_migration, | 811 bool allow_server_migration, |
| 764 bool force_hol_blocking, | 812 bool force_hol_blocking, |
| 765 bool race_cert_verification, | 813 bool race_cert_verification, |
| 766 bool do_not_fragment, | 814 bool do_not_fragment, |
| 767 bool estimate_initial_rtt, | 815 bool estimate_initial_rtt, |
| 768 const QuicTagVector& connection_options, | 816 const QuicTagVector& connection_options, |
| 769 bool enable_token_binding) | 817 bool enable_token_binding) |
| 770 : require_confirmation_(true), | 818 : require_confirmation_(true), |
| 771 net_log_(net_log), | 819 net_log_(net_log), |
| 820 quic_net_log_( | |
| 821 NetLogWithSource::Make(net_log, | |
| 822 NetLogSourceType::QUIC_STREAM_FACTORY)), | |
| 772 host_resolver_(host_resolver), | 823 host_resolver_(host_resolver), |
| 773 client_socket_factory_(client_socket_factory), | 824 client_socket_factory_(client_socket_factory), |
| 774 http_server_properties_(http_server_properties), | 825 http_server_properties_(http_server_properties), |
| 775 push_delegate_(nullptr), | 826 push_delegate_(nullptr), |
| 776 proxy_delegate_(proxy_delegate), | 827 proxy_delegate_(proxy_delegate), |
| 777 transport_security_state_(transport_security_state), | 828 transport_security_state_(transport_security_state), |
| 778 cert_transparency_verifier_(cert_transparency_verifier), | 829 cert_transparency_verifier_(cert_transparency_verifier), |
| 779 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), | 830 quic_crypto_client_stream_factory_(quic_crypto_client_stream_factory), |
| 780 random_generator_(random_generator), | 831 random_generator_(random_generator), |
| 781 clock_(clock), | 832 clock_(clock), |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 return false; | 1014 return false; |
| 964 } | 1015 } |
| 965 | 1016 |
| 966 int QuicStreamFactory::Create(const QuicServerId& server_id, | 1017 int QuicStreamFactory::Create(const QuicServerId& server_id, |
| 967 const HostPortPair& destination, | 1018 const HostPortPair& destination, |
| 968 int cert_verify_flags, | 1019 int cert_verify_flags, |
| 969 const GURL& url, | 1020 const GURL& url, |
| 970 base::StringPiece method, | 1021 base::StringPiece method, |
| 971 const NetLogWithSource& net_log, | 1022 const NetLogWithSource& net_log, |
| 972 QuicStreamRequest* request) { | 1023 QuicStreamRequest* request) { |
| 1024 std::string server_id_string = server_id.ToString(); | |
| 1025 net_log.BeginEvent(NetLogEventType::QUIC_STREAM_FACTORY_CREATE_HTTP_STREAM, | |
| 1026 NetLog::StringCallback("server_id", &server_id_string)); | |
| 973 if (clock_skew_detector_.ClockSkewDetected(base::TimeTicks::Now(), | 1027 if (clock_skew_detector_.ClockSkewDetected(base::TimeTicks::Now(), |
| 974 base::Time::Now())) { | 1028 base::Time::Now())) { |
| 975 while (!active_sessions_.empty()) { | 1029 while (!active_sessions_.empty()) { |
| 976 QuicChromiumClientSession* session = active_sessions_.begin()->second; | 1030 QuicChromiumClientSession* session = active_sessions_.begin()->second; |
| 977 OnSessionGoingAway(session); | 1031 OnSessionGoingAway(session); |
| 978 // TODO(rch): actually close the session? | 1032 // TODO(rch): actually close the session? |
| 979 } | 1033 } |
| 980 } | 1034 } |
| 981 DCHECK(server_id.host_port_pair().Equals(HostPortPair::FromURL(url))); | 1035 DCHECK(server_id.host_port_pair().Equals(HostPortPair::FromURL(url))); |
| 982 // Enforce session affinity for promised streams. | 1036 // Enforce session affinity for promised streams. |
| 983 QuicClientPromisedInfo* promised = | 1037 QuicClientPromisedInfo* promised = |
| 984 push_promise_index_.GetPromised(url.spec()); | 1038 push_promise_index_.GetPromised(url.spec()); |
| 985 if (promised) { | 1039 if (promised) { |
| 986 QuicChromiumClientSession* session = | 1040 QuicChromiumClientSession* session = |
| 987 static_cast<QuicChromiumClientSession*>(promised->session()); | 1041 static_cast<QuicChromiumClientSession*>(promised->session()); |
| 988 DCHECK(session); | 1042 DCHECK(session); |
| 989 if (session->server_id().privacy_mode() == server_id.privacy_mode()) { | 1043 if (session->server_id().privacy_mode() == server_id.privacy_mode()) { |
| 990 request->SetSession(session); | 1044 request->SetSession(session); |
| 991 ++num_push_streams_created_; | 1045 ++num_push_streams_created_; |
| 1046 net_log.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_CREATE_HTTP_STREAM, | |
| 1047 NetLog::BoolCallback("is_promised", true)); | |
| 992 return OK; | 1048 return OK; |
| 993 } | 1049 } |
| 994 // This should happen extremely rarely (if ever), but if somehow a | 1050 // This should happen extremely rarely (if ever), but if somehow a |
| 995 // request comes in with a mismatched privacy mode, consider the | 1051 // request comes in with a mismatched privacy mode, consider the |
| 996 // promise borked. | 1052 // promise borked. |
| 997 promised->Cancel(); | 1053 promised->Cancel(); |
| 998 } | 1054 } |
| 999 | 1055 |
| 1000 // Use active session for |server_id| if such exists. | 1056 // Use active session for |server_id| if such exists. |
| 1001 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. | 1057 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() checks. |
| 1002 if (!active_sessions_.empty()) { | 1058 if (!active_sessions_.empty()) { |
| 1003 SessionMap::iterator it = active_sessions_.find(server_id); | 1059 SessionMap::iterator it = active_sessions_.find(server_id); |
| 1004 if (it != active_sessions_.end()) { | 1060 if (it != active_sessions_.end()) { |
| 1005 QuicChromiumClientSession* session = it->second; | 1061 QuicChromiumClientSession* session = it->second; |
| 1006 request->SetSession(session); | 1062 request->SetSession(session); |
| 1063 net_log.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_CREATE_HTTP_STREAM, | |
| 1064 NetLog::BoolCallback("active_session_exists", true)); | |
| 1007 return OK; | 1065 return OK; |
| 1008 } | 1066 } |
| 1009 } | 1067 } |
| 1010 | 1068 |
| 1011 // Associate with active job to |server_id| if such exists. | 1069 // Associate with active job to |server_id| if such exists. |
| 1012 if (HasActiveJob(server_id)) { | 1070 if (HasActiveJob(server_id)) { |
| 1013 active_requests_[request] = server_id; | 1071 active_requests_[request] = server_id; |
| 1014 job_requests_map_[server_id].insert(request); | 1072 job_requests_map_[server_id].insert(request); |
| 1073 if (active_jobs_[server_id].size() == 1) { | |
| 1074 const NetLogWithSource job_net_log = | |
| 1075 active_jobs_[server_id].begin()->first->net_log(); | |
| 1076 job_net_log.AddEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND, | |
| 1077 net_log.source().ToEventParametersCallback()); | |
| 1078 net_log.AddEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND, | |
| 1079 job_net_log.source().ToEventParametersCallback()); | |
| 1080 } | |
| 1081 // Safe access, HasActiveJob. | |
| 1082 size_t job_count = active_jobs_[server_id].size(); | |
| 1083 net_log.AddEvent( | |
| 1084 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_BOUND_TO_ACTIVE_JOB, | |
| 1085 NetLog::Int64Callback("job_count", job_count)); | |
|
eroman
2017/03/16 04:32:09
nit: I don't think an int64 is necessary here.
| |
| 1086 net_log.AddEvent( | |
| 1087 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_BOUND_TO_ACTIVE_JOB, | |
| 1088 NetLog::BoolCallback("active_jobs_exist", true)); | |
| 1015 return ERR_IO_PENDING; | 1089 return ERR_IO_PENDING; |
| 1016 } | 1090 } |
| 1017 | 1091 |
| 1018 // Pool to active session to |destination| if possible. | 1092 // Pool to active session to |destination| if possible. |
| 1019 if (!active_sessions_.empty() && !disable_connection_pooling_) { | 1093 if (!active_sessions_.empty() && !disable_connection_pooling_) { |
| 1020 for (const auto& key_value : active_sessions_) { | 1094 for (const auto& key_value : active_sessions_) { |
| 1021 QuicChromiumClientSession* session = key_value.second; | 1095 QuicChromiumClientSession* session = key_value.second; |
| 1022 if (destination.Equals(all_sessions_[session].destination()) && | 1096 if (destination.Equals(all_sessions_[session].destination()) && |
| 1023 session->CanPool(server_id.host(), server_id.privacy_mode())) { | 1097 session->CanPool(server_id.host(), server_id.privacy_mode())) { |
| 1024 request->SetSession(session); | 1098 request->SetSession(session); |
| 1099 net_log.EndEvent( | |
| 1100 NetLogEventType::QUIC_STREAM_FACTORY_CREATE_HTTP_STREAM, | |
| 1101 NetLog::BoolCallback("pool_to_active_session", true)); | |
| 1025 return OK; | 1102 return OK; |
| 1026 } | 1103 } |
| 1027 } | 1104 } |
| 1028 } | 1105 } |
| 1029 | 1106 |
| 1030 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ | 1107 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ |
| 1031 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. | 1108 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. |
| 1032 if (!task_runner_) | 1109 if (!task_runner_) |
| 1033 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); | 1110 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); |
| 1034 | 1111 |
| 1035 std::unique_ptr<QuicServerInfo> quic_server_info; | 1112 std::unique_ptr<QuicServerInfo> quic_server_info; |
| 1036 if (quic_server_info_factory_.get()) { | 1113 if (quic_server_info_factory_.get()) { |
| 1037 bool load_from_disk_cache = !disable_disk_cache_; | 1114 bool load_from_disk_cache = !disable_disk_cache_; |
| 1038 MaybeInitialize(); | 1115 MaybeInitialize(); |
| 1039 if (!base::ContainsKey(quic_supported_servers_at_startup_, destination)) { | 1116 if (!base::ContainsKey(quic_supported_servers_at_startup_, destination)) { |
| 1040 // If there is no entry for QUIC, consider that as a new server and | 1117 // If there is no entry for QUIC, consider that as a new server and |
| 1041 // don't wait for Cache thread to load the data for that server. | 1118 // don't wait for Cache thread to load the data for that server. |
| 1042 load_from_disk_cache = false; | 1119 load_from_disk_cache = false; |
| 1043 } | 1120 } |
| 1044 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) | 1121 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) |
| 1045 quic_server_info = quic_server_info_factory_->GetForServer(server_id); | 1122 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
| 1046 } | 1123 } |
| 1047 | 1124 |
| 1048 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); | 1125 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); |
| 1049 | 1126 |
| 1050 QuicSessionKey key(destination, server_id); | 1127 QuicSessionKey key(destination, server_id); |
| 1128 | |
| 1129 size_t job_count; | |
| 1130 // Log that we create a new Job to serve the request. | |
| 1131 net_log.AddEvent(NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_CREATE_NEW_JOB); | |
| 1132 | |
| 1051 std::unique_ptr<Job> job = base::MakeUnique<Job>( | 1133 std::unique_ptr<Job> job = base::MakeUnique<Job>( |
| 1052 this, host_resolver_, key, WasQuicRecentlyBroken(server_id), | 1134 this, host_resolver_, key, WasQuicRecentlyBroken(server_id), |
| 1053 cert_verify_flags, std::move(quic_server_info), net_log); | 1135 cert_verify_flags, std::move(quic_server_info), net_log); |
| 1054 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 1136 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 1055 base::Unretained(this), job.get())); | 1137 base::Unretained(this), job.get())); |
| 1056 if (rv == ERR_IO_PENDING) { | 1138 if (rv == ERR_IO_PENDING) { |
| 1057 active_requests_[request] = server_id; | 1139 active_requests_[request] = server_id; |
| 1058 job_requests_map_[server_id].insert(request); | 1140 job_requests_map_[server_id].insert(request); |
| 1059 Job* job_ptr = job.get(); | 1141 Job* job_ptr = job.get(); |
| 1060 active_jobs_[server_id][job_ptr] = std::move(job); | 1142 active_jobs_[server_id][job_ptr] = std::move(job); |
| 1143 | |
| 1144 // Safe access after insertion. | |
| 1145 job_count = active_jobs_[server_id].size(); | |
| 1146 | |
| 1147 // The new job can't finish immediately, added to active job list. | |
| 1148 net_log.AddEvent( | |
| 1149 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_NEW_JOB_PENDING, | |
| 1150 NetLog::Int64Callback("active_job_count", job_count)); | |
|
eroman
2017/03/16 04:32:08
same
| |
| 1151 | |
| 1152 // Once one of the associated job finishes, QuicStreamFactory::OnJobComplete | |
| 1153 // will be invoked. On success, notify all the requests. Else if there's no | |
| 1154 // other job, it will notify request(s). Else, ignore if there's other jobs | |
| 1155 // running. | |
| 1061 return rv; | 1156 return rv; |
| 1062 } | 1157 } |
| 1063 if (rv == OK) { | 1158 if (rv == OK) { |
| 1159 job_count = 0; | |
| 1160 if (HasActiveJob(server_id)) { | |
| 1161 job_count = active_jobs_[server_id].size(); | |
| 1162 } | |
| 1163 bool active_session_found = | |
| 1164 (active_sessions_.find(server_id) != active_sessions_.end()); | |
| 1165 net_log.AddEvent( | |
| 1166 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_NEW_JOB_SUCCEED, | |
| 1167 NetLog::Int64Callback("job_count", job_count)); | |
| 1168 net_log.AddEvent( | |
| 1169 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_NEW_JOB_SUCCEED, | |
| 1170 NetLog::BoolCallback("active_session_found", active_session_found)); | |
| 1064 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() | 1171 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() |
| 1065 // related changes. | 1172 // related changes. |
| 1066 if (active_sessions_.empty()) | 1173 if (active_sessions_.empty()) |
| 1067 return ERR_QUIC_PROTOCOL_ERROR; | 1174 return ERR_QUIC_PROTOCOL_ERROR; |
| 1068 SessionMap::iterator it = active_sessions_.find(server_id); | 1175 SessionMap::iterator it = active_sessions_.find(server_id); |
| 1069 DCHECK(it != active_sessions_.end()); | 1176 DCHECK(it != active_sessions_.end()); |
| 1070 if (it == active_sessions_.end()) | 1177 if (it == active_sessions_.end()) |
| 1071 return ERR_QUIC_PROTOCOL_ERROR; | 1178 return ERR_QUIC_PROTOCOL_ERROR; |
| 1072 QuicChromiumClientSession* session = it->second; | 1179 QuicChromiumClientSession* session = it->second; |
| 1073 request->SetSession(session); | 1180 request->SetSession(session); |
| 1181 } else { | |
| 1182 job_count = 0; | |
| 1183 if (HasActiveJob(server_id)) { | |
| 1184 job_count = active_jobs_[server_id].size(); | |
| 1185 } | |
| 1186 | |
| 1187 bool active_session_found = | |
| 1188 (active_sessions_.find(server_id) != active_sessions_.end()); | |
| 1189 net_log.AddEvent( | |
| 1190 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_NEW_JOB_FAILED, | |
| 1191 NetLog::Int64Callback("job_count", job_count)); | |
| 1192 net_log.AddEvent( | |
| 1193 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_NEW_JOB_FAILED, | |
| 1194 NetLog::BoolCallback("active_session_found", active_session_found)); | |
| 1074 } | 1195 } |
| 1196 net_log.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_CREATE_HTTP_STREAM); | |
| 1075 return rv; | 1197 return rv; |
| 1076 } | 1198 } |
| 1077 | 1199 |
| 1078 QuicStreamFactory::QuicSessionKey::QuicSessionKey( | 1200 QuicStreamFactory::QuicSessionKey::QuicSessionKey( |
| 1079 const HostPortPair& destination, | 1201 const HostPortPair& destination, |
| 1080 const QuicServerId& server_id) | 1202 const QuicServerId& server_id) |
| 1081 : destination_(destination), server_id_(server_id) {} | 1203 : destination_(destination), server_id_(server_id) {} |
| 1082 | 1204 |
| 1083 bool QuicStreamFactory::QuicSessionKey::operator<( | 1205 bool QuicStreamFactory::QuicSessionKey::operator<( |
| 1084 const QuicSessionKey& other) const { | 1206 const QuicSessionKey& other) const { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1128 return true; | 1250 return true; |
| 1129 } | 1251 } |
| 1130 } | 1252 } |
| 1131 return false; | 1253 return false; |
| 1132 } | 1254 } |
| 1133 | 1255 |
| 1134 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { | 1256 void QuicStreamFactory::OnJobComplete(Job* job, int rv) { |
| 1135 // Copy |server_id|, because |job| might be destroyed before this method | 1257 // Copy |server_id|, because |job| might be destroyed before this method |
| 1136 // returns. | 1258 // returns. |
| 1137 const QuicServerId server_id(job->key().server_id()); | 1259 const QuicServerId server_id(job->key().server_id()); |
| 1260 std::string server_id_string = server_id.ToString(); | |
| 1261 quic_net_log_.BeginEvent( | |
| 1262 NetLogEventType::QUIC_STREAM_FACTORY_JOB_COMPLETE, | |
| 1263 NetLog::StringCallback("server id", &server_id_string)); | |
| 1264 | |
| 1138 if (rv != OK) { | 1265 if (rv != OK) { |
| 1266 CHECK(HasActiveJob(server_id)); | |
| 1139 JobSet* jobs = &(active_jobs_[server_id]); | 1267 JobSet* jobs = &(active_jobs_[server_id]); |
| 1140 if (jobs->size() > 1) { | 1268 if (jobs->size() > 1) { |
| 1141 // If there is another pending job, then we can delete this job and let | 1269 // If there is another pending job, then we can delete this job and let |
| 1142 // the other job handle the request. | 1270 // the other job handle the request. |
| 1271 job->net_log().AddEvent( | |
| 1272 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CANCELLED_BY_FACTORY); | |
| 1273 | |
| 1143 job->Cancel(); | 1274 job->Cancel(); |
| 1275 | |
| 1276 size_t job_count = active_jobs_[server_id].size(); | |
| 1277 quic_net_log_.AddEvent( | |
| 1278 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_ACTIVE_JOB_COUNT, | |
| 1279 NetLog::Int64Callback("job count before erase", job_count)); | |
| 1144 jobs->erase(job); | 1280 jobs->erase(job); |
| 1281 job_count = active_jobs_[server_id].size(); | |
| 1282 quic_net_log_.EndEvent( | |
| 1283 NetLogEventType::QUIC_STREAM_FACTORY_JOB_COMPLETE, | |
| 1284 NetLog::BoolCallback("has_active_job", HasActiveJob(server_id))); | |
| 1145 return; | 1285 return; |
| 1146 } | 1286 } |
| 1147 } | 1287 } |
| 1148 | 1288 |
| 1289 job->net_log().AddEvent( | |
| 1290 NetLogEventType::QUIC_STREAM_FACTORY_JOB_COMPLTE_FROM_FACTORY, | |
| 1291 NetLog::BoolCallback("is_success", rv == OK)); | |
| 1292 | |
| 1149 if (rv == OK) { | 1293 if (rv == OK) { |
| 1150 if (!always_require_handshake_confirmation_) | 1294 if (!always_require_handshake_confirmation_) |
| 1151 set_require_confirmation(false); | 1295 set_require_confirmation(false); |
| 1152 | 1296 |
| 1153 if (!job_requests_map_[server_id].empty()) { | 1297 if (!job_requests_map_[server_id].empty()) { |
| 1154 SessionMap::iterator session_it = active_sessions_.find(server_id); | 1298 SessionMap::iterator session_it = active_sessions_.find(server_id); |
| 1155 DCHECK(session_it != active_sessions_.end()); | 1299 DCHECK(session_it != active_sessions_.end()); |
| 1156 QuicChromiumClientSession* session = session_it->second; | 1300 QuicChromiumClientSession* session = session_it->second; |
| 1157 for (QuicStreamRequest* request : job_requests_map_[server_id]) { | 1301 for (QuicStreamRequest* request : job_requests_map_[server_id]) { |
| 1158 DCHECK(request->server_id() == server_id); | 1302 DCHECK(request->server_id() == server_id); |
| 1159 // Do not notify |request| yet. | 1303 // Do not notify |request| yet. |
| 1160 request->SetSession(session); | 1304 request->SetSession(session); |
| 1161 } | 1305 } |
| 1162 } | 1306 } |
| 1163 } | 1307 } |
| 1164 | 1308 |
| 1165 while (!job_requests_map_[server_id].empty()) { | 1309 while (!job_requests_map_[server_id].empty()) { |
| 1166 RequestSet::iterator it = job_requests_map_[server_id].begin(); | 1310 RequestSet::iterator it = job_requests_map_[server_id].begin(); |
| 1167 QuicStreamRequest* request = *it; | 1311 QuicStreamRequest* request = *it; |
| 1168 job_requests_map_[server_id].erase(it); | 1312 job_requests_map_[server_id].erase(it); |
| 1169 active_requests_.erase(request); | 1313 active_requests_.erase(request); |
| 1170 // Even though we're invoking callbacks here, we don't need to worry | 1314 // Even though we're invoking callbacks here, we don't need to worry |
| 1171 // about |this| being deleted, because the factory is owned by the | 1315 // about |this| being deleted, because the factory is owned by the |
| 1172 // profile which can not be deleted via callbacks. | 1316 // profile which can not be deleted via callbacks. |
| 1173 request->OnRequestComplete(rv); | 1317 request->OnRequestComplete(rv); |
| 1174 } | 1318 } |
| 1175 | 1319 |
| 1320 CHECK(HasActiveJob(server_id)); | |
| 1321 | |
| 1176 for (auto& other_job : active_jobs_[server_id]) { | 1322 for (auto& other_job : active_jobs_[server_id]) { |
| 1177 if (other_job.first != job) | 1323 if (other_job.first != job) { |
| 1324 other_job.first->net_log().AddEvent( | |
| 1325 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CANCELLED_BY_FACTORY); | |
| 1178 other_job.first->Cancel(); | 1326 other_job.first->Cancel(); |
| 1327 } | |
| 1179 } | 1328 } |
| 1180 | 1329 |
| 1330 size_t job_count = active_jobs_[server_id].size(); | |
| 1331 quic_net_log_.AddEvent( | |
| 1332 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_ACTIVE_JOB_COUNT, | |
| 1333 NetLog::Int64Callback("job count before clear", job_count)); | |
| 1334 | |
| 1181 active_jobs_[server_id].clear(); | 1335 active_jobs_[server_id].clear(); |
| 1182 active_jobs_.erase(server_id); | 1336 active_jobs_.erase(server_id); |
| 1183 job_requests_map_.erase(server_id); | 1337 job_requests_map_.erase(server_id); |
| 1338 | |
| 1339 quic_net_log_.EndEvent( | |
| 1340 NetLogEventType::QUIC_STREAM_FACTORY_JOB_COMPLETE, | |
| 1341 NetLog::BoolCallback("has_active_job", HasActiveJob(server_id))); | |
| 1184 } | 1342 } |
| 1185 | 1343 |
| 1186 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) { | 1344 void QuicStreamFactory::OnCertVerifyJobComplete(CertVerifierJob* job, int rv) { |
| 1187 active_cert_verifier_jobs_.erase(job->server_id()); | 1345 active_cert_verifier_jobs_.erase(job->server_id()); |
| 1188 } | 1346 } |
| 1189 | 1347 |
| 1190 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( | 1348 std::unique_ptr<QuicHttpStream> QuicStreamFactory::CreateFromSession( |
| 1191 QuicChromiumClientSession* session) { | 1349 QuicChromiumClientSession* session) { |
| 1192 return std::unique_ptr<QuicHttpStream>( | 1350 return std::unique_ptr<QuicHttpStream>( |
| 1193 new QuicHttpStream(session->GetWeakPtr())); | 1351 new QuicHttpStream(session->GetWeakPtr())); |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1571 CloseAllSessions(ERR_CERT_DATABASE_CHANGED, QUIC_CONNECTION_CANCELLED); | 1729 CloseAllSessions(ERR_CERT_DATABASE_CHANGED, QUIC_CONNECTION_CANCELLED); |
| 1572 } | 1730 } |
| 1573 | 1731 |
| 1574 bool QuicStreamFactory::HasActiveSession(const QuicServerId& server_id) const { | 1732 bool QuicStreamFactory::HasActiveSession(const QuicServerId& server_id) const { |
| 1575 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. | 1733 // TODO(rtenneti): crbug.com/498823 - delete active_sessions_.empty() check. |
| 1576 if (active_sessions_.empty()) | 1734 if (active_sessions_.empty()) |
| 1577 return false; | 1735 return false; |
| 1578 return base::ContainsKey(active_sessions_, server_id); | 1736 return base::ContainsKey(active_sessions_, server_id); |
| 1579 } | 1737 } |
| 1580 | 1738 |
| 1581 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) const { | 1739 bool QuicStreamFactory::HasActiveJob(const QuicServerId& server_id) { |
| 1582 return base::ContainsKey(active_jobs_, server_id); | 1740 bool has = base::ContainsKey(active_jobs_, server_id); |
| 1741 | |
| 1742 size_t job_count = 0; | |
| 1743 if (has) { | |
| 1744 job_count = active_jobs_[server_id].size(); | |
| 1745 } | |
| 1746 | |
| 1747 quic_net_log_.AddEvent( | |
| 1748 NetLogEventType::QUIC_STREAM_FACTORY_REQUEST_ACTIVE_JOB_COUNT, | |
| 1749 NetLog::Int64Callback("has_active_job_count", job_count)); | |
| 1750 return has; | |
| 1583 } | 1751 } |
| 1584 | 1752 |
| 1585 bool QuicStreamFactory::HasActiveCertVerifierJob( | 1753 bool QuicStreamFactory::HasActiveCertVerifierJob( |
| 1586 const QuicServerId& server_id) const { | 1754 const QuicServerId& server_id) const { |
| 1587 return base::ContainsKey(active_cert_verifier_jobs_, server_id); | 1755 return base::ContainsKey(active_cert_verifier_jobs_, server_id); |
| 1588 } | 1756 } |
| 1589 | 1757 |
| 1590 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, | 1758 int QuicStreamFactory::ConfigureSocket(DatagramClientSocket* socket, |
| 1591 IPEndPoint addr, | 1759 IPEndPoint addr, |
| 1592 NetworkHandle network) { | 1760 NetworkHandle network) { |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1983 void QuicStreamFactory::OpenFactory() { | 2151 void QuicStreamFactory::OpenFactory() { |
| 1984 status_ = OPEN; | 2152 status_ = OPEN; |
| 1985 } | 2153 } |
| 1986 | 2154 |
| 1987 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { | 2155 void QuicStreamFactory::MaybeClearConsecutiveDisabledCount() { |
| 1988 if (status_ == OPEN) | 2156 if (status_ == OPEN) |
| 1989 consecutive_disabled_count_ = 0; | 2157 consecutive_disabled_count_ = 0; |
| 1990 } | 2158 } |
| 1991 | 2159 |
| 1992 } // namespace net | 2160 } // namespace net |
| OLD | NEW |