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 <openssl/aead.h> | 7 #include <openssl/aead.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <tuple> | 10 #include <tuple> |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 QuicSessionKey key_; | 333 QuicSessionKey key_; |
334 int cert_verify_flags_; | 334 int cert_verify_flags_; |
335 bool was_alternative_service_recently_broken_; | 335 bool was_alternative_service_recently_broken_; |
336 std::unique_ptr<QuicServerInfo> server_info_; | 336 std::unique_ptr<QuicServerInfo> server_info_; |
337 bool started_another_job_; | 337 bool started_another_job_; |
338 const BoundNetLog net_log_; | 338 const BoundNetLog net_log_; |
339 int num_sent_client_hellos_; | 339 int num_sent_client_hellos_; |
340 QuicChromiumClientSession* session_; | 340 QuicChromiumClientSession* session_; |
341 CompletionCallback callback_; | 341 CompletionCallback callback_; |
342 AddressList address_list_; | 342 AddressList address_list_; |
| 343 base::TimeTicks dns_resolution_start_time_; |
343 base::TimeTicks dns_resolution_end_time_; | 344 base::TimeTicks dns_resolution_end_time_; |
344 base::WeakPtrFactory<Job> weak_factory_; | 345 base::WeakPtrFactory<Job> weak_factory_; |
345 DISALLOW_COPY_AND_ASSIGN(Job); | 346 DISALLOW_COPY_AND_ASSIGN(Job); |
346 }; | 347 }; |
347 | 348 |
348 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 349 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
349 HostResolver* host_resolver, | 350 HostResolver* host_resolver, |
350 const QuicSessionKey& key, | 351 const QuicSessionKey& key, |
351 bool was_alternative_service_recently_broken, | 352 bool was_alternative_service_recently_broken, |
352 int cert_verify_flags, | 353 int cert_verify_flags, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
459 | 460 |
460 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { | 461 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { |
461 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. | 462 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. |
462 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) | 463 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) |
463 return; | 464 return; |
464 server_info_->CancelWaitForDataReadyCallback(); | 465 server_info_->CancelWaitForDataReadyCallback(); |
465 OnIOComplete(OK); | 466 OnIOComplete(OK); |
466 } | 467 } |
467 | 468 |
468 int QuicStreamFactory::Job::DoResolveHost() { | 469 int QuicStreamFactory::Job::DoResolveHost() { |
| 470 dns_resolution_start_time_ = base::TimeTicks::Now(); |
469 // Start loading the data now, and wait for it after we resolve the host. | 471 // Start loading the data now, and wait for it after we resolve the host. |
470 if (server_info_) | 472 if (server_info_) |
471 server_info_->Start(); | 473 server_info_->Start(); |
472 | 474 |
473 io_state_ = STATE_RESOLVE_HOST_COMPLETE; | 475 io_state_ = STATE_RESOLVE_HOST_COMPLETE; |
474 return host_resolver_->Resolve( | 476 return host_resolver_->Resolve( |
475 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, | 477 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, |
476 &address_list_, | 478 &address_list_, |
477 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), | 479 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), |
478 &request_, net_log_); | 480 &request_, net_log_); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 return ERR_CONNECTION_CLOSED; | 553 return ERR_CONNECTION_CLOSED; |
552 } | 554 } |
553 | 555 |
554 io_state_ = STATE_CONNECT; | 556 io_state_ = STATE_CONNECT; |
555 return OK; | 557 return OK; |
556 } | 558 } |
557 | 559 |
558 int QuicStreamFactory::Job::DoConnect() { | 560 int QuicStreamFactory::Job::DoConnect() { |
559 io_state_ = STATE_CONNECT_COMPLETE; | 561 io_state_ = STATE_CONNECT_COMPLETE; |
560 | 562 |
561 int rv = factory_->CreateSession( | 563 int rv = |
562 key_, cert_verify_flags_, std::move(server_info_), address_list_, | 564 factory_->CreateSession(key_, cert_verify_flags_, std::move(server_info_), |
563 dns_resolution_end_time_, net_log_, &session_); | 565 address_list_, dns_resolution_start_time_, |
| 566 dns_resolution_end_time_, net_log_, &session_); |
564 if (rv != OK) { | 567 if (rv != OK) { |
565 DCHECK(rv != ERR_IO_PENDING); | 568 DCHECK(rv != ERR_IO_PENDING); |
566 DCHECK(!session_); | 569 DCHECK(!session_); |
567 return rv; | 570 return rv; |
568 } | 571 } |
569 | 572 |
570 if (!session_->connection()->connected()) | 573 if (!session_->connection()->connected()) |
571 return ERR_CONNECTION_CLOSED; | 574 return ERR_CONNECTION_CLOSED; |
572 | 575 |
573 session_->StartReading(); | 576 session_->StartReading(); |
(...skipping 996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1570 } | 1573 } |
1571 | 1574 |
1572 return OK; | 1575 return OK; |
1573 } | 1576 } |
1574 | 1577 |
1575 int QuicStreamFactory::CreateSession( | 1578 int QuicStreamFactory::CreateSession( |
1576 const QuicSessionKey& key, | 1579 const QuicSessionKey& key, |
1577 int cert_verify_flags, | 1580 int cert_verify_flags, |
1578 std::unique_ptr<QuicServerInfo> server_info, | 1581 std::unique_ptr<QuicServerInfo> server_info, |
1579 const AddressList& address_list, | 1582 const AddressList& address_list, |
| 1583 base::TimeTicks dns_resolution_start_time, |
1580 base::TimeTicks dns_resolution_end_time, | 1584 base::TimeTicks dns_resolution_end_time, |
1581 const BoundNetLog& net_log, | 1585 const BoundNetLog& net_log, |
1582 QuicChromiumClientSession** session) { | 1586 QuicChromiumClientSession** session) { |
1583 TRACE_EVENT0("net", "QuicStreamFactory::CreateSession"); | 1587 TRACE_EVENT0("net", "QuicStreamFactory::CreateSession"); |
1584 IPEndPoint addr = *address_list.begin(); | 1588 IPEndPoint addr = *address_list.begin(); |
1585 bool enable_port_selection = enable_port_selection_; | 1589 bool enable_port_selection = enable_port_selection_; |
1586 if (enable_port_selection && base::ContainsKey(gone_away_aliases_, key)) { | 1590 if (enable_port_selection && base::ContainsKey(gone_away_aliases_, key)) { |
1587 // Disable port selection when the server is going away. | 1591 // Disable port selection when the server is going away. |
1588 // There is no point in trying to return to the same server, if | 1592 // There is no point in trying to return to the same server, if |
1589 // that server is no longer handling requests. | 1593 // that server is no longer handling requests. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 socket_performance_watcher = | 1666 socket_performance_watcher = |
1663 socket_performance_watcher_factory_->CreateSocketPerformanceWatcher( | 1667 socket_performance_watcher_factory_->CreateSocketPerformanceWatcher( |
1664 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); | 1668 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); |
1665 } | 1669 } |
1666 | 1670 |
1667 *session = new QuicChromiumClientSession( | 1671 *session = new QuicChromiumClientSession( |
1668 connection, std::move(socket), this, quic_crypto_client_stream_factory_, | 1672 connection, std::move(socket), this, quic_crypto_client_stream_factory_, |
1669 clock_.get(), transport_security_state_, std::move(server_info), | 1673 clock_.get(), transport_security_state_, std::move(server_info), |
1670 server_id, yield_after_packets_, yield_after_duration_, cert_verify_flags, | 1674 server_id, yield_after_packets_, yield_after_duration_, cert_verify_flags, |
1671 config, &crypto_config_, network_connection_.GetDescription(), | 1675 config, &crypto_config_, network_connection_.GetDescription(), |
1672 dns_resolution_end_time, &push_promise_index_, task_runner_, | 1676 dns_resolution_start_time, dns_resolution_end_time, &push_promise_index_, |
1673 std::move(socket_performance_watcher), net_log.net_log()); | 1677 task_runner_, std::move(socket_performance_watcher), net_log.net_log()); |
1674 | 1678 |
1675 all_sessions_[*session] = key; // owning pointer | 1679 all_sessions_[*session] = key; // owning pointer |
1676 writer->set_delegate(*session); | 1680 writer->set_delegate(*session); |
1677 | 1681 |
1678 (*session)->Initialize(); | 1682 (*session)->Initialize(); |
1679 bool closed_during_initialize = !base::ContainsKey(all_sessions_, *session) || | 1683 bool closed_during_initialize = !base::ContainsKey(all_sessions_, *session) || |
1680 !(*session)->connection()->connected(); | 1684 !(*session)->connection()->connected(); |
1681 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", | 1685 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", |
1682 closed_during_initialize); | 1686 closed_during_initialize); |
1683 if (closed_during_initialize) { | 1687 if (closed_during_initialize) { |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 // Since the session was active, there's no longer an | 1870 // Since the session was active, there's no longer an |
1867 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 1871 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
1868 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 1872 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
1869 // it as recently broken, which means that 0-RTT will be disabled but we'll | 1873 // it as recently broken, which means that 0-RTT will be disabled but we'll |
1870 // still race. | 1874 // still race. |
1871 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 1875 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
1872 alternative_service); | 1876 alternative_service); |
1873 } | 1877 } |
1874 | 1878 |
1875 } // namespace net | 1879 } // namespace net |
OLD | NEW |