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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 QuicSessionKey key_; | 345 QuicSessionKey key_; |
346 int cert_verify_flags_; | 346 int cert_verify_flags_; |
347 bool was_alternative_service_recently_broken_; | 347 bool was_alternative_service_recently_broken_; |
348 std::unique_ptr<QuicServerInfo> server_info_; | 348 std::unique_ptr<QuicServerInfo> server_info_; |
349 bool started_another_job_; | 349 bool started_another_job_; |
350 const BoundNetLog net_log_; | 350 const BoundNetLog net_log_; |
351 int num_sent_client_hellos_; | 351 int num_sent_client_hellos_; |
352 QuicChromiumClientSession* session_; | 352 QuicChromiumClientSession* session_; |
353 CompletionCallback callback_; | 353 CompletionCallback callback_; |
354 AddressList address_list_; | 354 AddressList address_list_; |
355 base::TimeTicks dns_resolution_start_time_; | |
356 base::TimeTicks dns_resolution_end_time_; | 355 base::TimeTicks dns_resolution_end_time_; |
357 base::WeakPtrFactory<Job> weak_factory_; | 356 base::WeakPtrFactory<Job> weak_factory_; |
358 DISALLOW_COPY_AND_ASSIGN(Job); | 357 DISALLOW_COPY_AND_ASSIGN(Job); |
359 }; | 358 }; |
360 | 359 |
361 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, | 360 QuicStreamFactory::Job::Job(QuicStreamFactory* factory, |
362 HostResolver* host_resolver, | 361 HostResolver* host_resolver, |
363 const QuicSessionKey& key, | 362 const QuicSessionKey& key, |
364 bool was_alternative_service_recently_broken, | 363 bool was_alternative_service_recently_broken, |
365 int cert_verify_flags, | 364 int cert_verify_flags, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 | 471 |
473 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { | 472 void QuicStreamFactory::Job::CancelWaitForDataReadyCallback() { |
474 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. | 473 // If we are waiting for WaitForDataReadyCallback, then cancel the callback. |
475 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) | 474 if (io_state_ != STATE_LOAD_SERVER_INFO_COMPLETE) |
476 return; | 475 return; |
477 server_info_->CancelWaitForDataReadyCallback(); | 476 server_info_->CancelWaitForDataReadyCallback(); |
478 OnIOComplete(OK); | 477 OnIOComplete(OK); |
479 } | 478 } |
480 | 479 |
481 int QuicStreamFactory::Job::DoResolveHost() { | 480 int QuicStreamFactory::Job::DoResolveHost() { |
482 dns_resolution_start_time_ = base::TimeTicks::Now(); | |
483 // Start loading the data now, and wait for it after we resolve the host. | 481 // Start loading the data now, and wait for it after we resolve the host. |
484 if (server_info_) | 482 if (server_info_) |
485 server_info_->Start(); | 483 server_info_->Start(); |
486 | 484 |
487 io_state_ = STATE_RESOLVE_HOST_COMPLETE; | 485 io_state_ = STATE_RESOLVE_HOST_COMPLETE; |
488 return host_resolver_->Resolve( | 486 return host_resolver_->Resolve( |
489 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, | 487 HostResolver::RequestInfo(key_.destination()), DEFAULT_PRIORITY, |
490 &address_list_, | 488 &address_list_, |
491 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), | 489 base::Bind(&QuicStreamFactory::Job::OnIOComplete, GetWeakPtr()), |
492 &request_, net_log_); | 490 &request_, net_log_); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 return ERR_CONNECTION_CLOSED; | 563 return ERR_CONNECTION_CLOSED; |
566 } | 564 } |
567 | 565 |
568 io_state_ = STATE_CONNECT; | 566 io_state_ = STATE_CONNECT; |
569 return OK; | 567 return OK; |
570 } | 568 } |
571 | 569 |
572 int QuicStreamFactory::Job::DoConnect() { | 570 int QuicStreamFactory::Job::DoConnect() { |
573 io_state_ = STATE_CONNECT_COMPLETE; | 571 io_state_ = STATE_CONNECT_COMPLETE; |
574 | 572 |
575 int rv = | 573 int rv = factory_->CreateSession( |
576 factory_->CreateSession(key_, cert_verify_flags_, std::move(server_info_), | 574 key_, cert_verify_flags_, std::move(server_info_), address_list_, |
577 address_list_, dns_resolution_start_time_, | 575 dns_resolution_end_time_, net_log_, &session_); |
578 dns_resolution_end_time_, net_log_, &session_); | |
579 if (rv != OK) { | 576 if (rv != OK) { |
580 DCHECK(rv != ERR_IO_PENDING); | 577 DCHECK(rv != ERR_IO_PENDING); |
581 DCHECK(!session_); | 578 DCHECK(!session_); |
582 return rv; | 579 return rv; |
583 } | 580 } |
584 | 581 |
585 if (!session_->connection()->connected()) | 582 if (!session_->connection()->connected()) |
586 return ERR_CONNECTION_CLOSED; | 583 return ERR_CONNECTION_CLOSED; |
587 | 584 |
588 session_->StartReading(); | 585 session_->StartReading(); |
(...skipping 1174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1763 } | 1760 } |
1764 | 1761 |
1765 return OK; | 1762 return OK; |
1766 } | 1763 } |
1767 | 1764 |
1768 int QuicStreamFactory::CreateSession( | 1765 int QuicStreamFactory::CreateSession( |
1769 const QuicSessionKey& key, | 1766 const QuicSessionKey& key, |
1770 int cert_verify_flags, | 1767 int cert_verify_flags, |
1771 std::unique_ptr<QuicServerInfo> server_info, | 1768 std::unique_ptr<QuicServerInfo> server_info, |
1772 const AddressList& address_list, | 1769 const AddressList& address_list, |
1773 base::TimeTicks dns_resolution_start_time, | |
1774 base::TimeTicks dns_resolution_end_time, | 1770 base::TimeTicks dns_resolution_end_time, |
1775 const BoundNetLog& net_log, | 1771 const BoundNetLog& net_log, |
1776 QuicChromiumClientSession** session) { | 1772 QuicChromiumClientSession** session) { |
1777 TRACE_EVENT0("net", "QuicStreamFactory::CreateSession"); | 1773 TRACE_EVENT0("net", "QuicStreamFactory::CreateSession"); |
1778 IPEndPoint addr = *address_list.begin(); | 1774 IPEndPoint addr = *address_list.begin(); |
1779 bool enable_port_selection = enable_port_selection_; | 1775 bool enable_port_selection = enable_port_selection_; |
1780 if (enable_port_selection && base::ContainsKey(gone_away_aliases_, key)) { | 1776 if (enable_port_selection && base::ContainsKey(gone_away_aliases_, key)) { |
1781 // Disable port selection when the server is going away. | 1777 // Disable port selection when the server is going away. |
1782 // There is no point in trying to return to the same server, if | 1778 // There is no point in trying to return to the same server, if |
1783 // that server is no longer handling requests. | 1779 // that server is no longer handling requests. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1856 socket_performance_watcher = | 1852 socket_performance_watcher = |
1857 socket_performance_watcher_factory_->CreateSocketPerformanceWatcher( | 1853 socket_performance_watcher_factory_->CreateSocketPerformanceWatcher( |
1858 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); | 1854 SocketPerformanceWatcherFactory::PROTOCOL_QUIC); |
1859 } | 1855 } |
1860 | 1856 |
1861 *session = new QuicChromiumClientSession( | 1857 *session = new QuicChromiumClientSession( |
1862 connection, std::move(socket), this, quic_crypto_client_stream_factory_, | 1858 connection, std::move(socket), this, quic_crypto_client_stream_factory_, |
1863 clock_.get(), transport_security_state_, std::move(server_info), | 1859 clock_.get(), transport_security_state_, std::move(server_info), |
1864 server_id, yield_after_packets_, yield_after_duration_, cert_verify_flags, | 1860 server_id, yield_after_packets_, yield_after_duration_, cert_verify_flags, |
1865 config, &crypto_config_, network_connection_.GetDescription(), | 1861 config, &crypto_config_, network_connection_.GetDescription(), |
1866 dns_resolution_start_time, dns_resolution_end_time, &push_promise_index_, | 1862 dns_resolution_end_time, &push_promise_index_, |
1867 base::ThreadTaskRunnerHandle::Get().get(), | 1863 base::ThreadTaskRunnerHandle::Get().get(), |
1868 std::move(socket_performance_watcher), net_log.net_log()); | 1864 std::move(socket_performance_watcher), net_log.net_log()); |
1869 | 1865 |
1870 all_sessions_[*session] = key; // owning pointer | 1866 all_sessions_[*session] = key; // owning pointer |
1871 writer->Initialize(*session, connection); | 1867 writer->Initialize(*session, connection); |
1872 | 1868 |
1873 (*session)->Initialize(); | 1869 (*session)->Initialize(); |
1874 bool closed_during_initialize = !base::ContainsKey(all_sessions_, *session) || | 1870 bool closed_during_initialize = !base::ContainsKey(all_sessions_, *session) || |
1875 !(*session)->connection()->connected(); | 1871 !(*session)->connection()->connected(); |
1876 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", | 1872 UMA_HISTOGRAM_BOOLEAN("Net.QuicSession.ClosedDuringInitializeSession", |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2061 // Since the session was active, there's no longer an | 2057 // Since the session was active, there's no longer an |
2062 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP | 2058 // HttpStreamFactoryImpl::Job running which can mark it broken, unless the TCP |
2063 // job also fails. So to avoid not using QUIC when we otherwise could, we mark | 2059 // job also fails. So to avoid not using QUIC when we otherwise could, we mark |
2064 // it as recently broken, which means that 0-RTT will be disabled but we'll | 2060 // it as recently broken, which means that 0-RTT will be disabled but we'll |
2065 // still race. | 2061 // still race. |
2066 http_server_properties_->MarkAlternativeServiceRecentlyBroken( | 2062 http_server_properties_->MarkAlternativeServiceRecentlyBroken( |
2067 alternative_service); | 2063 alternative_service); |
2068 } | 2064 } |
2069 | 2065 |
2070 } // namespace net | 2066 } // namespace net |
OLD | NEW |