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 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 // Responsible for creating a new QUIC session to the specified server, and | 325 // Responsible for creating a new QUIC session to the specified server, and |
326 // for notifying any associated requests when complete. | 326 // for notifying any associated requests when complete. |
327 class QuicStreamFactory::Job { | 327 class QuicStreamFactory::Job { |
328 public: | 328 public: |
329 Job(QuicStreamFactory* factory, | 329 Job(QuicStreamFactory* factory, |
330 HostResolver* host_resolver, | 330 HostResolver* host_resolver, |
331 const QuicSessionKey& key, | 331 const QuicSessionKey& key, |
332 bool was_alternative_service_recently_broken, | 332 bool was_alternative_service_recently_broken, |
333 int cert_verify_flags, | 333 int cert_verify_flags, |
| 334 std::unique_ptr<QuicServerInfo> server_info, |
334 const NetLogWithSource& net_log); | 335 const NetLogWithSource& net_log); |
335 | 336 |
| 337 // Creates a new job to handle the resumption of for connecting an |
| 338 // existing session. |
| 339 Job(QuicStreamFactory* factory, |
| 340 HostResolver* host_resolver, |
| 341 QuicChromiumClientSession* session, |
| 342 const QuicSessionKey& key); |
| 343 |
336 ~Job(); | 344 ~Job(); |
337 | 345 |
338 int Run(const CompletionCallback& callback); | 346 int Run(const CompletionCallback& callback); |
339 | 347 |
340 int DoLoop(int rv); | 348 int DoLoop(int rv); |
341 int DoResolveHost(); | 349 int DoResolveHost(); |
342 int DoResolveHostComplete(int rv); | 350 int DoResolveHostComplete(int rv); |
| 351 int DoLoadServerInfo(); |
| 352 int DoLoadServerInfoComplete(int rv); |
343 int DoConnect(); | 353 int DoConnect(); |
344 int DoConnectComplete(int rv); | 354 int DoConnectComplete(int rv); |
345 | 355 |
346 void OnIOComplete(int rv); | 356 void OnIOComplete(int rv); |
347 | 357 |
| 358 void RunAuxilaryJob(); |
| 359 |
348 void Cancel(); | 360 void Cancel(); |
349 | 361 |
| 362 void CancelWaitForDataReadyCallback(); |
| 363 |
350 const QuicSessionKey& key() const { return key_; } | 364 const QuicSessionKey& key() const { return key_; } |
351 | 365 |
352 const NetLogWithSource& net_log() const { return net_log_; } | 366 const NetLogWithSource& net_log() const { return net_log_; } |
353 | 367 |
354 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } | 368 base::WeakPtr<Job> GetWeakPtr() { return weak_factory_.GetWeakPtr(); } |
355 | 369 |
356 // Returns the estimate of dynamically allocated memory in bytes. | 370 // Returns the estimate of dynamically allocated memory in bytes. |
357 size_t EstimateMemoryUsage() const; | 371 size_t EstimateMemoryUsage() const; |
358 | 372 |
359 private: | 373 private: |
360 enum IoState { | 374 enum IoState { |
361 STATE_NONE, | 375 STATE_NONE, |
362 STATE_RESOLVE_HOST, | 376 STATE_RESOLVE_HOST, |
363 STATE_RESOLVE_HOST_COMPLETE, | 377 STATE_RESOLVE_HOST_COMPLETE, |
| 378 STATE_LOAD_SERVER_INFO, |
| 379 STATE_LOAD_SERVER_INFO_COMPLETE, |
364 STATE_CONNECT, | 380 STATE_CONNECT, |
365 STATE_CONNECT_COMPLETE, | 381 STATE_CONNECT_COMPLETE, |
366 }; | 382 }; |
367 IoState io_state_; | 383 IoState io_state_; |
368 | 384 |
369 QuicStreamFactory* factory_; | 385 QuicStreamFactory* factory_; |
370 HostResolver* host_resolver_; | 386 HostResolver* host_resolver_; |
371 std::unique_ptr<HostResolver::Request> request_; | 387 std::unique_ptr<HostResolver::Request> request_; |
372 const QuicSessionKey key_; | 388 const QuicSessionKey key_; |
373 const int cert_verify_flags_; | 389 const int cert_verify_flags_; |
374 const bool was_alternative_service_recently_broken_; | 390 const bool was_alternative_service_recently_broken_; |
| 391 std::unique_ptr<QuicServerInfo> server_info_; |
| 392 bool started_another_job_; |
375 const NetLogWithSource net_log_; | 393 const NetLogWithSource net_log_; |
376 int num_sent_client_hellos_; | 394 int num_sent_client_hellos_; |
377 QuicChromiumClientSession* session_; | 395 QuicChromiumClientSession* session_; |
378 CompletionCallback callback_; | 396 CompletionCallback callback_; |
379 AddressList address_list_; | 397 AddressList address_list_; |
380 base::TimeTicks dns_resolution_start_time_; | 398 base::TimeTicks dns_resolution_start_time_; |
381 base::TimeTicks dns_resolution_end_time_; | 399 base::TimeTicks dns_resolution_end_time_; |
382 base::WeakPtrFactory<Job> weak_factory_; | 400 base::WeakPtrFactory<Job> weak_factory_; |
383 DISALLOW_COPY_AND_ASSIGN(Job); | 401 DISALLOW_COPY_AND_ASSIGN(Job); |
384 }; | 402 }; |
385 | 403 |
386 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 404 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
387 HostResolver* host_resolver, | 405 HostResolver* host_resolver, |
388 const QuicSessionKey& key, | 406 const QuicSessionKey& key, |
389 bool was_alternative_service_recently_broken, | 407 bool was_alternative_service_recently_broken, |
390 int cert_verify_flags, | 408 int cert_verify_flags, |
| 409 std::unique_ptr<QuicServerInfo> server_info, |
391 const NetLogWithSource& net_log) | 410 const NetLogWithSource& net_log) |
392 : io_state_(STATE_RESOLVE_HOST), | 411 : io_state_(STATE_RESOLVE_HOST), |
393 factory_(factory), | 412 factory_(factory), |
394 host_resolver_(host_resolver), | 413 host_resolver_(host_resolver), |
395 key_(key), | 414 key_(key), |
396 cert_verify_flags_(cert_verify_flags), | 415 cert_verify_flags_(cert_verify_flags), |
397 was_alternative_service_recently_broken_( | 416 was_alternative_service_recently_broken_( |
398 was_alternative_service_recently_broken), | 417 was_alternative_service_recently_broken), |
| 418 server_info_(std::move(server_info)), |
| 419 started_another_job_(false), |
399 net_log_( | 420 net_log_( |
400 NetLogWithSource::Make(net_log.net_log(), | 421 NetLogWithSource::Make(net_log.net_log(), |
401 NetLogSourceType::QUIC_STREAM_FACTORY_JOB)), | 422 NetLogSourceType::QUIC_STREAM_FACTORY_JOB)), |
402 num_sent_client_hellos_(0), | 423 num_sent_client_hellos_(0), |
403 session_(nullptr), | 424 session_(nullptr), |
404 weak_factory_(this) { | 425 weak_factory_(this) { |
405 net_log_.BeginEvent( | 426 net_log_.BeginEvent( |
406 NetLogEventType::QUIC_STREAM_FACTORY_JOB, | 427 NetLogEventType::QUIC_STREAM_FACTORY_JOB, |
407 base::Bind(&NetLogQuicStreamFactoryJobCallback, &key_.server_id())); | 428 base::Bind(&NetLogQuicStreamFactoryJobCallback, &key_.server_id())); |
408 // Associate |net_log_| with |net_log|. | 429 // Associate |net_log_| with |net_log|. |
409 net_log_.AddEvent( | 430 net_log_.AddEvent( |
410 NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND_TO_HTTP_STREAM_JOB, | 431 NetLogEventType::QUIC_STREAM_FACTORY_JOB_BOUND_TO_HTTP_STREAM_JOB, |
411 net_log.source().ToEventParametersCallback()); | 432 net_log.source().ToEventParametersCallback()); |
412 net_log.AddEvent( | 433 net_log.AddEvent( |
413 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_QUIC_STREAM_FACTORY_JOB, | 434 NetLogEventType::HTTP_STREAM_JOB_BOUND_TO_QUIC_STREAM_FACTORY_JOB, |
414 net_log_.source().ToEventParametersCallback()); | 435 net_log_.source().ToEventParametersCallback()); |
415 } | 436 } |
416 | 437 |
417 QuicStreamFactory::Job::~Job() { | 438 QuicStreamFactory::Job::~Job() { |
418 net_log_.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB); | 439 net_log_.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB); |
419 DCHECK(callback_.is_null()); | 440 DCHECK(callback_.is_null()); |
| 441 |
| 442 // If disk cache has a pending WaitForDataReadyCallback, cancel that callback. |
| 443 if (server_info_) |
| 444 server_info_->ResetWaitForDataReadyCallback(); |
420 } | 445 } |
421 | 446 |
422 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { | 447 int QuicStreamFactory::Job::Run(const CompletionCallback& callback) { |
423 int rv = DoLoop(OK); | 448 int rv = DoLoop(OK); |
424 if (rv == ERR_IO_PENDING) | 449 if (rv == ERR_IO_PENDING) |
425 callback_ = callback; | 450 callback_ = callback; |
426 | 451 |
427 return rv > 0 ? OK : rv; | 452 return rv > 0 ? OK : rv; |
428 } | 453 } |
429 | 454 |
430 int QuicStreamFactory::Job::DoLoop(int rv) { | 455 int QuicStreamFactory::Job::DoLoop(int rv) { |
431 TRACE_EVENT0(kNetTracingCategory, "QuicStreamFactory::Job::DoLoop"); | 456 TRACE_EVENT0(kNetTracingCategory, "QuicStreamFactory::Job::DoLoop"); |
432 do { | 457 do { |
433 IoState state = io_state_; | 458 IoState state = io_state_; |
434 io_state_ = STATE_NONE; | 459 io_state_ = STATE_NONE; |
435 switch (state) { | 460 switch (state) { |
436 case STATE_RESOLVE_HOST: | 461 case STATE_RESOLVE_HOST: |
437 CHECK_EQ(OK, rv); | 462 CHECK_EQ(OK, rv); |
438 rv = DoResolveHost(); | 463 rv = DoResolveHost(); |
439 break; | 464 break; |
440 case STATE_RESOLVE_HOST_COMPLETE: | 465 case STATE_RESOLVE_HOST_COMPLETE: |
441 rv = DoResolveHostComplete(rv); | 466 rv = DoResolveHostComplete(rv); |
442 break; | 467 break; |
| 468 case STATE_LOAD_SERVER_INFO: |
| 469 CHECK_EQ(OK, rv); |
| 470 rv = DoLoadServerInfo(); |
| 471 break; |
| 472 case STATE_LOAD_SERVER_INFO_COMPLETE: |
| 473 rv = DoLoadServerInfoComplete(rv); |
| 474 break; |
443 case STATE_CONNECT: | 475 case STATE_CONNECT: |
444 CHECK_EQ(OK, rv); | 476 CHECK_EQ(OK, rv); |
445 rv = DoConnect(); | 477 rv = DoConnect(); |
446 break; | 478 break; |
447 case STATE_CONNECT_COMPLETE: | 479 case STATE_CONNECT_COMPLETE: |
448 rv = DoConnectComplete(rv); | 480 rv = DoConnectComplete(rv); |
449 break; | 481 break; |
450 default: | 482 default: |
451 NOTREACHED() << "io_state_: " << io_state_; | 483 NOTREACHED() << "io_state_: " << io_state_; |
452 break; | 484 break; |
453 } | 485 } |
454 } while (io_state_ != STATE_NONE && rv != ERR_IO_PENDING); | 486 } while (io_state_ != STATE_NONE && rv != ERR_IO_PENDING); |
455 return rv; | 487 return rv; |
456 } | 488 } |
457 | 489 |
458 void QuicStreamFactory::Job::OnIOComplete(int rv) { | 490 void QuicStreamFactory::Job::OnIOComplete(int rv) { |
459 rv = DoLoop(rv); | 491 rv = DoLoop(rv); |
460 if (rv != ERR_IO_PENDING && !callback_.is_null()) | 492 if (rv != ERR_IO_PENDING && !callback_.is_null()) |
461 base::ResetAndReturn(&callback_).Run(rv); | 493 base::ResetAndReturn(&callback_).Run(rv); |
462 } | 494 } |
463 | 495 |
| 496 void QuicStreamFactory::Job::RunAuxilaryJob() { |
| 497 int rv = Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
| 498 base::Unretained(factory_), this)); |
| 499 if (rv != ERR_IO_PENDING) |
| 500 factory_->OnJobComplete(this, rv); |
| 501 } |
| 502 |
464 void QuicStreamFactory::Job::Cancel() { | 503 void QuicStreamFactory::Job::Cancel() { |
465 callback_.Reset(); | 504 callback_.Reset(); |
466 if (session_) | 505 if (session_) |
467 session_->connection()->CloseConnection( | 506 session_->connection()->CloseConnection( |
468 QUIC_CONNECTION_CANCELLED, "New job canceled.", | 507 QUIC_CONNECTION_CANCELLED, "New job canceled.", |
469 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); | 508 ConnectionCloseBehavior::SEND_CONNECTION_CLOSE_PACKET); |
470 } | 509 } |
471 | 510 |
| 511 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { |
| 512 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. |
| 513 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) |
| 514 return; |
| 515 server_info_->CancelWaitForDataReadyCallback(); |
| 516 OnIOComplete(OK); |
| 517 } |
| 518 |
472 size_t QuicStreamFactory::Job::EstimateMemoryUsage() const { | 519 size_t QuicStreamFactory::Job::EstimateMemoryUsage() const { |
473 return base::trace_event::EstimateMemoryUsage(key_); | 520 return base::trace_event::EstimateMemoryUsage(key_) + |
| 521 base::trace_event::EstimateMemoryUsage(server_info_); |
474 } | 522 } |
475 | 523 |
476 int QuicStreamFactory::Job::DoResolveHost() { | 524 int QuicStreamFactory::Job::DoResolveHost() { |
477 dns_resolution_start_time_ = base::TimeTicks::Now(); | 525 dns_resolution_start_time_ = base::TimeTicks::Now(); |
| 526 // Start loading the data now, and wait for it after we resolve the host. |
| 527 if (server_info_) |
| 528 server_info_->Start(); |
478 | 529 |
479 io_state_ = STATE_RESOLVE_HOST_COMPLETE; | 530 io_state_ = STATE_RESOLVE_HOST_COMPLETE; |
480 return host_resolver_->Resolve( | 531 return host_resolver_->Resolve( |
481 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, | 532 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, |
482 &address_list_, | 533 &address_list_, |
483 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), | 534 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), |
484 &request_, net_log_); | 535 &request_, net_log_); |
485 } | 536 } |
486 | 537 |
487 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { | 538 int QuicStreamFactory::Job::DoResolveHostComplete(int rv) { |
488 dns_resolution_end_time_ = base::TimeTicks::Now(); | 539 dns_resolution_end_time_ = base::TimeTicks::Now(); |
489 if (rv != OK) | 540 if (rv != OK) |
490 return rv; | 541 return rv; |
491 | 542 |
492 DCHECK(!factory_->HasActiveSession(key_.server_id())); | 543 DCHECK(!factory_->HasActiveSession(key_.server_id())); |
493 | 544 |
494 // Inform the factory of this resolution, which will set up | 545 // Inform the factory of this resolution, which will set up |
495 // a session alias, if possible. | 546 // a session alias, if possible. |
496 if (factory_->OnResolution(key_, address_list_)) | 547 if (factory_->OnResolution(key_, address_list_)) |
497 return OK; | 548 return OK; |
498 | 549 |
| 550 if (server_info_) |
| 551 io_state_ = STATE_LOAD_SERVER_INFO; |
| 552 else |
| 553 io_state_ = STATE_CONNECT; |
| 554 return OK; |
| 555 } |
| 556 |
| 557 int QuicStreamFactory::Job::DoLoadServerInfo() { |
| 558 net_log_.BeginEvent( |
| 559 NetLogEventType::QUIC_STREAM_FACTORY_JOB_LOAD_SERVER_INFO); |
| 560 |
| 561 io_state_ = STATE_LOAD_SERVER_INFO_COMPLETE; |
| 562 |
| 563 DCHECK(server_info_); |
| 564 |
| 565 // To mitigate the effects of disk cache taking too long to load QUIC server |
| 566 // information, set up a timer to cancel WaitForDataReady's callback. |
| 567 if (factory_->load_server_info_timeout_srtt_multiplier_ > 0) { |
| 568 const int kMaxLoadServerInfoTimeoutMs = 50; |
| 569 // Wait for DiskCache a maximum of 50ms. |
| 570 int64_t load_server_info_timeout_ms = |
| 571 std::min(static_cast<int>( |
| 572 (factory_->load_server_info_timeout_srtt_multiplier_ * |
| 573 factory_->GetServerNetworkStatsSmoothedRttInMicroseconds( |
| 574 key_.server_id())) / |
| 575 1000), |
| 576 kMaxLoadServerInfoTimeoutMs); |
| 577 if (load_server_info_timeout_ms > 0) { |
| 578 factory_->task_runner_->PostDelayedTask( |
| 579 FROM_HERE, |
| 580 base::Bind(&QuicStreamFactory::Job::CancelWaitForDataReadyCallback, |
| 581 GetWeakPtr()), |
| 582 base::TimeDelta::FromMilliseconds(load_server_info_timeout_ms)); |
| 583 } |
| 584 } |
| 585 |
| 586 int rv = server_info_->WaitForDataReady( |
| 587 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr())); |
| 588 if (rv == ERR_IO_PENDING && factory_->enable_connection_racing()) { |
| 589 // If we are waiting to load server config from the disk cache, then start |
| 590 // another job. |
| 591 started_another_job_ = true; |
| 592 factory_->CreateAuxilaryJob(key_, cert_verify_flags_, net_log_); |
| 593 } |
| 594 return rv; |
| 595 } |
| 596 |
| 597 int QuicStreamFactory::Job::DoLoadServerInfoComplete(int rv) { |
| 598 net_log_.EndEvent(NetLogEventType::QUIC_STREAM_FACTORY_JOB_LOAD_SERVER_INFO); |
| 599 UMA_HISTOGRAM_TIMES("Net.QuicServerInfo.DiskCacheWaitForDataReadyTime", |
| 600 base::TimeTicks::Now() - dns_resolution_end_time_); |
| 601 |
| 602 if (rv != OK) |
| 603 server_info_.reset(); |
| 604 |
| 605 if (started_another_job_ && |
| 606 (!server_info_ || server_info_->state().server_config.empty() || |
| 607 !factory_->CryptoConfigCacheIsEmpty(key_.server_id()))) { |
| 608 // If we have started another job and if we didn't load the server config |
| 609 // from the disk cache or if we have received a new server config from the |
| 610 // server, then cancel the current job. |
| 611 io_state_ = STATE_NONE; |
| 612 return ERR_CONNECTION_CLOSED; |
| 613 } |
| 614 |
499 io_state_ = STATE_CONNECT; | 615 io_state_ = STATE_CONNECT; |
500 return OK; | 616 return OK; |
501 } | 617 } |
502 | 618 |
503 int QuicStreamFactory::Job::DoConnect() { | 619 int QuicStreamFactory::Job::DoConnect() { |
504 io_state_ = STATE_CONNECT_COMPLETE; | 620 io_state_ = STATE_CONNECT_COMPLETE; |
505 | 621 |
506 bool require_confirmation = factory_->require_confirmation() || | 622 bool require_confirmation = factory_->require_confirmation() || |
507 was_alternative_service_recently_broken_; | 623 was_alternative_service_recently_broken_; |
508 net_log_.BeginEvent( | 624 net_log_.BeginEvent( |
509 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT, | 625 NetLogEventType::QUIC_STREAM_FACTORY_JOB_CONNECT, |
510 NetLog::BoolCallback("require_confirmation", require_confirmation)); | 626 NetLog::BoolCallback("require_confirmation", require_confirmation)); |
511 | 627 |
512 int rv = | 628 int rv = factory_->CreateSession( |
513 factory_->CreateSession(key_, cert_verify_flags_, require_confirmation, | 629 key_, cert_verify_flags_, std::move(server_info_), require_confirmation, |
514 address_list_, dns_resolution_start_time_, | 630 address_list_, dns_resolution_start_time_, dns_resolution_end_time_, |
515 dns_resolution_end_time_, net_log_, &session_); | 631 net_log_, &session_); |
516 if (rv != OK) { | 632 if (rv != OK) { |
517 DCHECK(rv != ERR_IO_PENDING); | 633 DCHECK(rv != ERR_IO_PENDING); |
518 DCHECK(!session_); | 634 DCHECK(!session_); |
519 return rv; | 635 return rv; |
520 } | 636 } |
521 | 637 |
522 if (!session_->connection()->connected()) | 638 if (!session_->connection()->connected()) |
523 return ERR_CONNECTION_CLOSED; | 639 return ERR_CONNECTION_CLOSED; |
524 | 640 |
525 session_->StartReading(); | 641 session_->StartReading(); |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 ChannelIDService* channel_id_service, | 764 ChannelIDService* channel_id_service, |
649 TransportSecurityState* transport_security_state, | 765 TransportSecurityState* transport_security_state, |
650 CTVerifier* cert_transparency_verifier, | 766 CTVerifier* cert_transparency_verifier, |
651 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, | 767 SocketPerformanceWatcherFactory* socket_performance_watcher_factory, |
652 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, | 768 QuicCryptoClientStreamFactory* quic_crypto_client_stream_factory, |
653 QuicRandom* random_generator, | 769 QuicRandom* random_generator, |
654 QuicClock* clock, | 770 QuicClock* clock, |
655 size_t max_packet_length, | 771 size_t max_packet_length, |
656 const std::string& user_agent_id, | 772 const std::string& user_agent_id, |
657 const QuicVersionVector& supported_versions, | 773 const QuicVersionVector& supported_versions, |
| 774 float load_server_info_timeout_srtt_multiplier, |
| 775 bool enable_connection_racing, |
658 bool enable_non_blocking_io, | 776 bool enable_non_blocking_io, |
659 bool store_server_configs_in_properties, | 777 bool disable_disk_cache, |
| 778 int max_server_configs_stored_in_properties, |
660 bool close_sessions_on_ip_change, | 779 bool close_sessions_on_ip_change, |
661 bool mark_quic_broken_when_network_blackholes, | 780 bool mark_quic_broken_when_network_blackholes, |
662 int idle_connection_timeout_seconds, | 781 int idle_connection_timeout_seconds, |
663 int reduced_ping_timeout_seconds, | 782 int reduced_ping_timeout_seconds, |
664 int packet_reader_yield_after_duration_milliseconds, | 783 int packet_reader_yield_after_duration_milliseconds, |
665 bool migrate_sessions_on_network_change, | 784 bool migrate_sessions_on_network_change, |
666 bool migrate_sessions_early, | 785 bool migrate_sessions_early, |
667 bool allow_server_migration, | 786 bool allow_server_migration, |
668 bool force_hol_blocking, | 787 bool force_hol_blocking, |
669 bool race_cert_verification, | 788 bool race_cert_verification, |
(...skipping 17 matching lines...) Expand all Loading... |
687 clock_skew_detector_(base::TimeTicks::Now(), base::Time::Now()), | 806 clock_skew_detector_(base::TimeTicks::Now(), base::Time::Now()), |
688 socket_performance_watcher_factory_(socket_performance_watcher_factory), | 807 socket_performance_watcher_factory_(socket_performance_watcher_factory), |
689 config_(InitializeQuicConfig(connection_options, | 808 config_(InitializeQuicConfig(connection_options, |
690 idle_connection_timeout_seconds)), | 809 idle_connection_timeout_seconds)), |
691 crypto_config_(base::WrapUnique( | 810 crypto_config_(base::WrapUnique( |
692 new ProofVerifierChromium(cert_verifier, | 811 new ProofVerifierChromium(cert_verifier, |
693 ct_policy_enforcer, | 812 ct_policy_enforcer, |
694 transport_security_state, | 813 transport_security_state, |
695 cert_transparency_verifier))), | 814 cert_transparency_verifier))), |
696 supported_versions_(supported_versions), | 815 supported_versions_(supported_versions), |
| 816 load_server_info_timeout_srtt_multiplier_( |
| 817 load_server_info_timeout_srtt_multiplier), |
| 818 enable_connection_racing_(enable_connection_racing), |
697 enable_non_blocking_io_(enable_non_blocking_io), | 819 enable_non_blocking_io_(enable_non_blocking_io), |
| 820 disable_disk_cache_(disable_disk_cache), |
698 mark_quic_broken_when_network_blackholes_( | 821 mark_quic_broken_when_network_blackholes_( |
699 mark_quic_broken_when_network_blackholes), | 822 mark_quic_broken_when_network_blackholes), |
700 store_server_configs_in_properties_(store_server_configs_in_properties), | |
701 ping_timeout_(QuicTime::Delta::FromSeconds(kPingTimeoutSecs)), | 823 ping_timeout_(QuicTime::Delta::FromSeconds(kPingTimeoutSecs)), |
702 reduced_ping_timeout_( | 824 reduced_ping_timeout_( |
703 QuicTime::Delta::FromSeconds(reduced_ping_timeout_seconds)), | 825 QuicTime::Delta::FromSeconds(reduced_ping_timeout_seconds)), |
704 yield_after_packets_(kQuicYieldAfterPacketsRead), | 826 yield_after_packets_(kQuicYieldAfterPacketsRead), |
705 yield_after_duration_(QuicTime::Delta::FromMilliseconds( | 827 yield_after_duration_(QuicTime::Delta::FromMilliseconds( |
706 packet_reader_yield_after_duration_milliseconds)), | 828 packet_reader_yield_after_duration_milliseconds)), |
707 close_sessions_on_ip_change_(close_sessions_on_ip_change), | 829 close_sessions_on_ip_change_(close_sessions_on_ip_change), |
708 migrate_sessions_on_network_change_( | 830 migrate_sessions_on_network_change_( |
709 migrate_sessions_on_network_change && | 831 migrate_sessions_on_network_change && |
710 NetworkChangeNotifier::AreNetworkHandlesSupported()), | 832 NetworkChangeNotifier::AreNetworkHandlesSupported()), |
711 migrate_sessions_early_(migrate_sessions_early && | 833 migrate_sessions_early_(migrate_sessions_early && |
712 migrate_sessions_on_network_change_), | 834 migrate_sessions_on_network_change_), |
713 allow_server_migration_(allow_server_migration), | 835 allow_server_migration_(allow_server_migration), |
714 force_hol_blocking_(force_hol_blocking), | 836 force_hol_blocking_(force_hol_blocking), |
715 race_cert_verification_(race_cert_verification), | 837 race_cert_verification_(race_cert_verification), |
716 do_not_fragment_(do_not_fragment), | 838 do_not_fragment_(do_not_fragment), |
717 estimate_initial_rtt(estimate_initial_rtt), | 839 estimate_initial_rtt(estimate_initial_rtt), |
718 check_persisted_supports_quic_(true), | 840 check_persisted_supports_quic_(true), |
| 841 has_initialized_data_(false), |
719 num_push_streams_created_(0), | 842 num_push_streams_created_(0), |
720 task_runner_(nullptr), | 843 task_runner_(nullptr), |
721 ssl_config_service_(ssl_config_service), | 844 ssl_config_service_(ssl_config_service), |
722 weak_factory_(this) { | 845 weak_factory_(this) { |
723 if (ssl_config_service_.get()) | 846 if (ssl_config_service_.get()) |
724 ssl_config_service_->AddObserver(this); | 847 ssl_config_service_->AddObserver(this); |
725 DCHECK(transport_security_state_); | 848 DCHECK(transport_security_state_); |
726 DCHECK(http_server_properties_); | 849 DCHECK(http_server_properties_); |
727 crypto_config_.set_user_agent_id(user_agent_id); | 850 crypto_config_.set_user_agent_id(user_agent_id); |
728 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); | 851 crypto_config_.AddCanonicalSuffix(".c.youtube.com"); |
729 crypto_config_.AddCanonicalSuffix(".ggpht.com"); | 852 crypto_config_.AddCanonicalSuffix(".ggpht.com"); |
730 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); | 853 crypto_config_.AddCanonicalSuffix(".googlevideo.com"); |
731 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); | 854 crypto_config_.AddCanonicalSuffix(".googleusercontent.com"); |
732 // TODO(rtenneti): http://crbug.com/487355. Temporary fix for b/20760730 until | 855 // TODO(rtenneti): http://crbug.com/487355. Temporary fix for b/20760730 until |
733 // channel_id_service is supported in cronet. | 856 // channel_id_service is supported in cronet. |
734 if (channel_id_service) { | 857 if (channel_id_service) { |
735 crypto_config_.SetChannelIDSource( | 858 crypto_config_.SetChannelIDSource( |
736 new ChannelIDSourceChromium(channel_id_service)); | 859 new ChannelIDSourceChromium(channel_id_service)); |
737 } | 860 } |
738 if (enable_token_binding && channel_id_service) | 861 if (enable_token_binding && channel_id_service) |
739 crypto_config_.tb_key_params.push_back(kTB10); | 862 crypto_config_.tb_key_params.push_back(kTB10); |
740 crypto::EnsureOpenSSLInit(); | 863 crypto::EnsureOpenSSLInit(); |
741 bool has_aes_hardware_support = !!EVP_has_aes_hardware(); | 864 bool has_aes_hardware_support = !!EVP_has_aes_hardware(); |
742 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.PreferAesGcm", | 865 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.PreferAesGcm", |
743 has_aes_hardware_support); | 866 has_aes_hardware_support); |
744 if (has_aes_hardware_support) | 867 if (has_aes_hardware_support) |
745 crypto_config_.PreferAesGcm(); | 868 crypto_config_.PreferAesGcm(); |
| 869 // When disk cache is used to store the server configs, HttpCache code calls |
| 870 // |set_quic_server_info_factory| if |quic_server_info_factory_| wasn't |
| 871 // created. |
| 872 if (max_server_configs_stored_in_properties > 0) { |
| 873 quic_server_info_factory_.reset( |
| 874 new PropertiesBasedQuicServerInfoFactory(http_server_properties_)); |
| 875 } |
746 | 876 |
747 // migrate_sessions_early should only be set to true if | 877 // migrate_sessions_early should only be set to true if |
748 // migrate_sessions_on_network_change is set to true. | 878 // migrate_sessions_on_network_change is set to true. |
749 if (migrate_sessions_early) | 879 if (migrate_sessions_early) |
750 DCHECK(migrate_sessions_on_network_change); | 880 DCHECK(migrate_sessions_on_network_change); |
751 // close_sessions_on_ip_change and migrate_sessions_on_network_change should | 881 // close_sessions_on_ip_change and migrate_sessions_on_network_change should |
752 // never be simultaneously set to true. | 882 // never be simultaneously set to true. |
753 DCHECK(!(close_sessions_on_ip_change && migrate_sessions_on_network_change)); | 883 DCHECK(!(close_sessions_on_ip_change && migrate_sessions_on_network_change)); |
754 | 884 |
755 if (migrate_sessions_on_network_change_) { | 885 if (migrate_sessions_on_network_change_) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 int64_t srtt = | 923 int64_t srtt = |
794 1.5 * GetServerNetworkStatsSmoothedRttInMicroseconds(server_id); | 924 1.5 * GetServerNetworkStatsSmoothedRttInMicroseconds(server_id); |
795 // Picked 300ms based on mean time from | 925 // Picked 300ms based on mean time from |
796 // Net.QuicSession.HostResolution.HandshakeConfirmedTime histogram. | 926 // Net.QuicSession.HostResolution.HandshakeConfirmedTime histogram. |
797 const int kDefaultRTT = 300 * kNumMicrosPerMilli; | 927 const int kDefaultRTT = 300 * kNumMicrosPerMilli; |
798 if (!srtt) | 928 if (!srtt) |
799 srtt = kDefaultRTT; | 929 srtt = kDefaultRTT; |
800 return base::TimeDelta::FromMicroseconds(srtt); | 930 return base::TimeDelta::FromMicroseconds(srtt); |
801 } | 931 } |
802 | 932 |
| 933 void QuicStreamFactory::set_quic_server_info_factory( |
| 934 QuicServerInfoFactory* quic_server_info_factory) { |
| 935 quic_server_info_factory_.reset(quic_server_info_factory); |
| 936 } |
| 937 |
803 void QuicStreamFactory::DumpMemoryStats( | 938 void QuicStreamFactory::DumpMemoryStats( |
804 base::trace_event::ProcessMemoryDump* pmd, | 939 base::trace_event::ProcessMemoryDump* pmd, |
805 const std::string& parent_absolute_name) const { | 940 const std::string& parent_absolute_name) const { |
806 if (all_sessions_.empty() && active_jobs_.empty()) | 941 if (all_sessions_.empty() && active_jobs_.empty()) |
807 return; | 942 return; |
808 base::trace_event::MemoryAllocatorDump* factory_dump = | 943 base::trace_event::MemoryAllocatorDump* factory_dump = |
809 pmd->CreateAllocatorDump(parent_absolute_name + "/quic_stream_factory"); | 944 pmd->CreateAllocatorDump(parent_absolute_name + "/quic_stream_factory"); |
810 size_t memory_estimate = | 945 size_t memory_estimate = |
811 base::trace_event::EstimateMemoryUsage(all_sessions_) + | 946 base::trace_event::EstimateMemoryUsage(all_sessions_) + |
812 base::trace_event::EstimateMemoryUsage(active_sessions_) + | 947 base::trace_event::EstimateMemoryUsage(active_sessions_) + |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
927 return OK; | 1062 return OK; |
928 } | 1063 } |
929 } | 1064 } |
930 } | 1065 } |
931 | 1066 |
932 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ | 1067 // TODO(rtenneti): |task_runner_| is used by the Job. Initialize task_runner_ |
933 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. | 1068 // in the constructor after WebRequestActionWithThreadsTest.* tests are fixed. |
934 if (!task_runner_) | 1069 if (!task_runner_) |
935 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); | 1070 task_runner_ = base::ThreadTaskRunnerHandle::Get().get(); |
936 | 1071 |
| 1072 std::unique_ptr<QuicServerInfo> quic_server_info; |
| 1073 if (quic_server_info_factory_.get()) { |
| 1074 bool load_from_disk_cache = !disable_disk_cache_; |
| 1075 MaybeInitialize(); |
| 1076 if (!base::ContainsKey(quic_supported_servers_at_startup_, destination)) { |
| 1077 // If there is no entry for QUIC, consider that as a new server and |
| 1078 // don't wait for Cache thread to load the data for that server. |
| 1079 load_from_disk_cache = false; |
| 1080 } |
| 1081 if (load_from_disk_cache && CryptoConfigCacheIsEmpty(server_id)) |
| 1082 quic_server_info = quic_server_info_factory_->GetForServer(server_id); |
| 1083 } |
| 1084 |
937 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); | 1085 ignore_result(StartCertVerifyJob(server_id, cert_verify_flags, net_log)); |
938 | 1086 |
939 QuicSessionKey key(destination, server_id); | 1087 QuicSessionKey key(destination, server_id); |
940 std::unique_ptr<Job> job = base::MakeUnique<Job>( | 1088 std::unique_ptr<Job> job = base::MakeUnique<Job>( |
941 this, host_resolver_, key, WasQuicRecentlyBroken(server_id), | 1089 this, host_resolver_, key, WasQuicRecentlyBroken(server_id), |
942 cert_verify_flags, net_log); | 1090 cert_verify_flags, std::move(quic_server_info), net_log); |
943 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, | 1091 int rv = job->Run(base::Bind(&QuicStreamFactory::OnJobComplete, |
944 base::Unretained(this), job.get())); | 1092 base::Unretained(this), job.get())); |
945 if (rv == ERR_IO_PENDING) { | 1093 if (rv == ERR_IO_PENDING) { |
946 job_requests_map_[server_id].insert(request); | 1094 job_requests_map_[server_id].insert(request); |
947 Job* job_ptr = job.get(); | 1095 Job* job_ptr = job.get(); |
948 active_jobs_[server_id][job_ptr] = std::move(job); | 1096 active_jobs_[server_id][job_ptr] = std::move(job); |
949 return rv; | 1097 return rv; |
950 } | 1098 } |
951 if (rv == OK) { | 1099 if (rv == OK) { |
952 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() | 1100 // TODO(rtenneti): crbug.com/498823 - revert active_sessions_.empty() |
(...skipping 25 matching lines...) Expand all Loading... |
978 const QuicSessionKey& other) const { | 1126 const QuicSessionKey& other) const { |
979 return destination_.Equals(other.destination_) && | 1127 return destination_.Equals(other.destination_) && |
980 server_id_ == other.server_id_; | 1128 server_id_ == other.server_id_; |
981 } | 1129 } |
982 | 1130 |
983 size_t QuicStreamFactory::QuicSessionKey::EstimateMemoryUsage() const { | 1131 size_t QuicStreamFactory::QuicSessionKey::EstimateMemoryUsage() const { |
984 return base::trace_event::EstimateMemoryUsage(destination_) + | 1132 return base::trace_event::EstimateMemoryUsage(destination_) + |
985 EstimateServerIdMemoryUsage(server_id_); | 1133 EstimateServerIdMemoryUsage(server_id_); |
986 } | 1134 } |
987 | 1135 |
| 1136 void QuicStreamFactory::CreateAuxilaryJob(const QuicSessionKey& key, |
| 1137 int cert_verify_flags, |
| 1138 const NetLogWithSource& net_log) { |
| 1139 Job* aux_job = |
| 1140 new Job(this, host_resolver_, key, WasQuicRecentlyBroken(key.server_id()), |
| 1141 cert_verify_flags, nullptr, net_log); |
| 1142 active_jobs_[key.server_id()][aux_job] = base::WrapUnique(aux_job); |
| 1143 task_runner_->PostTask(FROM_HERE, |
| 1144 base::Bind(&QuicStreamFactory::Job::RunAuxilaryJob, |
| 1145 aux_job->GetWeakPtr())); |
| 1146 } |
| 1147 |
988 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, | 1148 bool QuicStreamFactory::OnResolution(const QuicSessionKey& key, |
989 const AddressList& address_list) { | 1149 const AddressList& address_list) { |
990 const QuicServerId& server_id(key.server_id()); | 1150 const QuicServerId& server_id(key.server_id()); |
991 DCHECK(!HasActiveSession(server_id)); | 1151 DCHECK(!HasActiveSession(server_id)); |
992 for (const IPEndPoint& address : address_list) { | 1152 for (const IPEndPoint& address : address_list) { |
993 if (!base::ContainsKey(ip_aliases_, address)) | 1153 if (!base::ContainsKey(ip_aliases_, address)) |
994 continue; | 1154 continue; |
995 | 1155 |
996 const SessionSet& sessions = ip_aliases_[address]; | 1156 const SessionSet& sessions = ip_aliases_[address]; |
997 for (QuicChromiumClientSession* session : sessions) { | 1157 for (QuicChromiumClientSession* session : sessions) { |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 require_confirmation_ = false; | 1636 require_confirmation_ = false; |
1477 } | 1637 } |
1478 } | 1638 } |
1479 | 1639 |
1480 return OK; | 1640 return OK; |
1481 } | 1641 } |
1482 | 1642 |
1483 int QuicStreamFactory::CreateSession( | 1643 int QuicStreamFactory::CreateSession( |
1484 const QuicSessionKey& key, | 1644 const QuicSessionKey& key, |
1485 int cert_verify_flags, | 1645 int cert_verify_flags, |
| 1646 std::unique_ptr<QuicServerInfo> server_info, |
1486 bool require_confirmation, | 1647 bool require_confirmation, |
1487 const AddressList& address_list, | 1648 const AddressList& address_list, |
1488 base::TimeTicks dns_resolution_start_time, | 1649 base::TimeTicks dns_resolution_start_time, |
1489 base::TimeTicks dns_resolution_end_time, | 1650 base::TimeTicks dns_resolution_end_time, |
1490 const NetLogWithSource& net_log, | 1651 const NetLogWithSource& net_log, |
1491 QuicChromiumClientSession** session) { | 1652 QuicChromiumClientSession** session) { |
1492 TRACE_EVENT0(kNetTracingCategory, "QuicStreamFactory::CreateSession"); | 1653 TRACE_EVENT0(kNetTracingCategory, "QuicStreamFactory::CreateSession"); |
1493 IPEndPoint addr = *address_list.begin(); | 1654 IPEndPoint addr = *address_list.begin(); |
1494 const QuicServerId& server_id = key.server_id(); | 1655 const QuicServerId& server_id = key.server_id(); |
1495 DatagramSocket::BindType bind_type = DatagramSocket::DEFAULT_BIND; | 1656 DatagramSocket::BindType bind_type = DatagramSocket::DEFAULT_BIND; |
1496 std::unique_ptr<DatagramClientSocket> socket( | 1657 std::unique_ptr<DatagramClientSocket> socket( |
1497 client_socket_factory_->CreateDatagramClientSocket( | 1658 client_socket_factory_->CreateDatagramClientSocket( |
1498 bind_type, RandIntCallback(), net_log.net_log(), net_log.source())); | 1659 bind_type, RandIntCallback(), net_log.net_log(), net_log.source())); |
1499 | 1660 |
1500 // Passing in kInvalidNetworkHandle binds socket to default network. | 1661 // Passing in kInvalidNetworkHandle binds socket to default network. |
1501 int rv = ConfigureSocket(socket.get(), addr, | 1662 int rv = ConfigureSocket(socket.get(), addr, |
1502 NetworkChangeNotifier::kInvalidNetworkHandle); | 1663 NetworkChangeNotifier::kInvalidNetworkHandle); |
1503 if (rv != OK) | 1664 if (rv != OK) |
1504 return rv; | 1665 return rv; |
1505 | 1666 |
1506 if (!helper_.get()) { | 1667 if (!helper_.get()) { |
1507 helper_.reset(new QuicChromiumConnectionHelper(clock_, random_generator_)); | 1668 helper_.reset(new QuicChromiumConnectionHelper(clock_, random_generator_)); |
1508 } | 1669 } |
1509 | 1670 |
1510 if (!alarm_factory_.get()) { | 1671 if (!alarm_factory_.get()) { |
1511 alarm_factory_.reset(new QuicChromiumAlarmFactory( | 1672 alarm_factory_.reset(new QuicChromiumAlarmFactory( |
1512 base::ThreadTaskRunnerHandle::Get().get(), clock_)); | 1673 base::ThreadTaskRunnerHandle::Get().get(), clock_)); |
1513 } | 1674 } |
1514 | |
1515 QuicConnectionId connection_id = random_generator_->RandUint64(); | 1675 QuicConnectionId connection_id = random_generator_->RandUint64(); |
1516 std::unique_ptr<QuicServerInfo> server_info; | |
1517 if (store_server_configs_in_properties_) { | |
1518 server_info = base::MakeUnique<PropertiesBasedQuicServerInfo>( | |
1519 server_id, http_server_properties_); | |
1520 } | |
1521 InitializeCachedStateInCryptoConfig(server_id, server_info, &connection_id); | 1676 InitializeCachedStateInCryptoConfig(server_id, server_info, &connection_id); |
1522 | 1677 |
1523 QuicChromiumPacketWriter* writer = new QuicChromiumPacketWriter(socket.get()); | 1678 QuicChromiumPacketWriter* writer = new QuicChromiumPacketWriter(socket.get()); |
1524 QuicConnection* connection = new QuicConnection( | 1679 QuicConnection* connection = new QuicConnection( |
1525 connection_id, QuicSocketAddress(QuicSocketAddressImpl(addr)), | 1680 connection_id, QuicSocketAddress(QuicSocketAddressImpl(addr)), |
1526 helper_.get(), alarm_factory_.get(), writer, true /* owns_writer */, | 1681 helper_.get(), alarm_factory_.get(), writer, true /* owns_writer */, |
1527 Perspective::IS_CLIENT, supported_versions_); | 1682 Perspective::IS_CLIENT, supported_versions_); |
1528 connection->set_ping_timeout(ping_timeout_); | 1683 connection->set_ping_timeout(ping_timeout_); |
1529 connection->SetMaxPacketLength(max_packet_length_); | 1684 connection->SetMaxPacketLength(max_packet_length_); |
1530 | 1685 |
1531 QuicConfig config = config_; | 1686 QuicConfig config = config_; |
1532 config.SetSocketReceiveBufferToSend(kQuicSocketReceiveBufferSize); | 1687 config.SetSocketReceiveBufferToSend(kQuicSocketReceiveBufferSize); |
1533 config.set_max_undecryptable_packets(kMaxUndecryptablePackets); | 1688 config.set_max_undecryptable_packets(kMaxUndecryptablePackets); |
1534 config.SetInitialSessionFlowControlWindowToSend( | 1689 config.SetInitialSessionFlowControlWindowToSend( |
1535 kQuicSessionMaxRecvWindowSize); | 1690 kQuicSessionMaxRecvWindowSize); |
1536 config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize); | 1691 config.SetInitialStreamFlowControlWindowToSend(kQuicStreamMaxRecvWindowSize); |
1537 config.SetBytesForConnectionIdToSend(0); | 1692 config.SetBytesForConnectionIdToSend(0); |
1538 ConfigureInitialRttEstimate(server_id, &config); | 1693 ConfigureInitialRttEstimate(server_id, &config); |
1539 | 1694 |
1540 if (force_hol_blocking_) | 1695 if (force_hol_blocking_) |
1541 config.SetForceHolBlocking(); | 1696 config.SetForceHolBlocking(); |
1542 | 1697 |
| 1698 if (quic_server_info_factory_.get() && !server_info) { |
| 1699 // Start the disk cache loading so that we can persist the newer QUIC server |
| 1700 // information and/or inform the disk cache that we have reused |
| 1701 // |server_info|. |
| 1702 server_info = quic_server_info_factory_->GetForServer(server_id); |
| 1703 server_info->Start(); |
| 1704 } |
| 1705 |
1543 // Use the factory to create a new socket performance watcher, and pass the | 1706 // Use the factory to create a new socket performance watcher, and pass the |
1544 // ownership to QuicChromiumClientSession. | 1707 // ownership to QuicChromiumClientSession. |
1545 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher; | 1708 std::unique_ptr<SocketPerformanceWatcher> socket_performance_watcher; |
1546 if (socket_performance_watcher_factory_) { | 1709 if (socket_performance_watcher_factory_) { |
1547 socket_performance_watcher = | 1710 socket_performance_watcher = |
1548 socket_performance_watcher_factory_->CreateSocketPerformanceWatcher( | 1711 socket_performance_watcher_factory_->CreateSocketPerformanceWatcher( |
1549 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); | 1712 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); |
1550 } | 1713 } |
1551 | 1714 |
1552 *session = new QuicChromiumClientSession( | 1715 *session = new QuicChromiumClientSession( |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1675 const std::unique_ptr<QuicServerInfo>& server_info, | 1838 const std::unique_ptr<QuicServerInfo>& server_info, |
1676 QuicConnectionId* connection_id) { | 1839 QuicConnectionId* connection_id) { |
1677 QuicCryptoClientConfig::CachedState* cached = | 1840 QuicCryptoClientConfig::CachedState* cached = |
1678 crypto_config_.LookupOrCreate(server_id); | 1841 crypto_config_.LookupOrCreate(server_id); |
1679 if (cached->has_server_designated_connection_id()) | 1842 if (cached->has_server_designated_connection_id()) |
1680 *connection_id = cached->GetNextServerDesignatedConnectionId(); | 1843 *connection_id = cached->GetNextServerDesignatedConnectionId(); |
1681 | 1844 |
1682 if (!cached->IsEmpty()) | 1845 if (!cached->IsEmpty()) |
1683 return; | 1846 return; |
1684 | 1847 |
1685 if (!server_info || !server_info->Load()) | 1848 // |server_info| will be NULL, if a non-empty server config already exists in |
| 1849 // the memory cache. |
| 1850 if (!server_info) |
1686 return; | 1851 return; |
1687 | 1852 |
| 1853 // TODO(rtenneti): Delete the following histogram after collecting stats. |
| 1854 // If the AlternativeServiceMap contained an entry for this host, check if |
| 1855 // the disk cache contained an entry for it. |
| 1856 if (base::ContainsKey(quic_supported_servers_at_startup_, |
| 1857 server_id.host_port_pair())) { |
| 1858 UMA_HISTOGRAM_BOOLEAN("Net.QuicServerInfo.ExpectConfigMissingFromDiskCache", |
| 1859 server_info->state().server_config.empty()); |
| 1860 } |
| 1861 |
1688 cached->Initialize(server_info->state().server_config, | 1862 cached->Initialize(server_info->state().server_config, |
1689 server_info->state().source_address_token, | 1863 server_info->state().source_address_token, |
1690 server_info->state().certs, server_info->state().cert_sct, | 1864 server_info->state().certs, server_info->state().cert_sct, |
1691 server_info->state().chlo_hash, | 1865 server_info->state().chlo_hash, |
1692 server_info->state().server_config_sig, clock_->WallNow(), | 1866 server_info->state().server_config_sig, clock_->WallNow(), |
1693 QuicWallTime::Zero()); | 1867 QuicWallTime::Zero()); |
1694 } | 1868 } |
1695 | 1869 |
| 1870 void QuicStreamFactory::MaybeInitialize() { |
| 1871 // We don't initialize data from HttpServerProperties in the constructor |
| 1872 // because HttpServerProperties has not yet initialized. We're guaranteed |
| 1873 // HttpServerProperties has been initialized by the first time a request is |
| 1874 // made. |
| 1875 if (has_initialized_data_) |
| 1876 return; |
| 1877 |
| 1878 has_initialized_data_ = true; |
| 1879 |
| 1880 // Query the proxy delegate for the default alternative proxy server. |
| 1881 ProxyServer default_alternative_proxy_server = |
| 1882 proxy_delegate_ ? proxy_delegate_->GetDefaultAlternativeProxy() |
| 1883 : ProxyServer(); |
| 1884 if (default_alternative_proxy_server.is_quic()) { |
| 1885 quic_supported_servers_at_startup_.insert( |
| 1886 default_alternative_proxy_server.host_port_pair()); |
| 1887 } |
| 1888 |
| 1889 for (const std::pair<const url::SchemeHostPort, AlternativeServiceInfoVector>& |
| 1890 key_value : http_server_properties_->alternative_service_map()) { |
| 1891 HostPortPair host_port_pair(key_value.first.host(), key_value.first.port()); |
| 1892 for (const AlternativeServiceInfo& alternative_service_info : |
| 1893 key_value.second) { |
| 1894 if (alternative_service_info.alternative_service.protocol == kProtoQUIC) { |
| 1895 quic_supported_servers_at_startup_.insert(host_port_pair); |
| 1896 break; |
| 1897 } |
| 1898 } |
| 1899 } |
| 1900 |
| 1901 if (http_server_properties_->max_server_configs_stored_in_properties() == 0) |
| 1902 return; |
| 1903 // Create a temporary QuicServerInfo object to deserialize and to populate the |
| 1904 // in-memory crypto server config cache in the MRU order. |
| 1905 std::unique_ptr<QuicServerInfo> server_info; |
| 1906 CompletionCallback callback; |
| 1907 // Get the list of servers to be deserialized first because WaitForDataReady |
| 1908 // touches quic_server_info_map. |
| 1909 const QuicServerInfoMap& quic_server_info_map = |
| 1910 http_server_properties_->quic_server_info_map(); |
| 1911 std::vector<QuicServerId> server_list; |
| 1912 for (const auto& key_value : quic_server_info_map) |
| 1913 server_list.push_back(key_value.first); |
| 1914 for (auto it = server_list.rbegin(); it != server_list.rend(); ++it) { |
| 1915 const QuicServerId& server_id = *it; |
| 1916 server_info = quic_server_info_factory_->GetForServer(server_id); |
| 1917 if (server_info->WaitForDataReady(callback) == OK) { |
| 1918 DVLOG(1) << "Initialized server config for: " << server_id.ToString(); |
| 1919 InitializeCachedStateInCryptoConfig(server_id, server_info, nullptr); |
| 1920 } |
| 1921 } |
| 1922 } |
| 1923 |
1696 void QuicStreamFactory::ProcessGoingAwaySession( | 1924 void QuicStreamFactory::ProcessGoingAwaySession( |
1697 QuicChromiumClientSession* session, | 1925 QuicChromiumClientSession* session, |
1698 const QuicServerId& server_id, | 1926 const QuicServerId& server_id, |
1699 bool session_was_active) { | 1927 bool session_was_active) { |
1700 if (!http_server_properties_) | 1928 if (!http_server_properties_) |
1701 return; | 1929 return; |
1702 | 1930 |
1703 const QuicConnectionStats& stats = session->connection()->GetStats(); | 1931 const QuicConnectionStats& stats = session->connection()->GetStats(); |
1704 const AlternativeService alternative_service(kProtoQUIC, | 1932 const AlternativeService alternative_service(kProtoQUIC, |
1705 server_id.host_port_pair()); | 1933 server_id.host_port_pair()); |
(...skipping 30 matching lines...) Expand all Loading... |
1736 // Since the session was active, there's no longer an | 1964 // Since the session was active, there's no longer an |
1737 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1965 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1738 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1966 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1739 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1967 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1740 // still race. | 1968 // still race. |
1741 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1969 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1742 alternative_service); | 1970 alternative_service); |
1743 } | 1971 } |
1744 | 1972 |
1745 } // namespace net | 1973 } // namespace net |
OLD | NEW |