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