1 // Copyright 2024 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef NET_HTTP_HTTP_STREAM_POOL_QUIC_TASK_H_ 6 #define NET_HTTP_HTTP_STREAM_POOL_QUIC_TASK_H_ 7 8 #include <memory> 9 #include <optional> 10 11 #include "base/memory/raw_ptr.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/values.h" 14 #include "net/base/ip_endpoint.h" 15 #include "net/dns/host_resolver.h" 16 #include "net/http/http_stream_pool.h" 17 #include "net/quic/quic_session_attempt.h" 18 #include "net/quic/quic_session_pool.h" 19 #include "net/third_party/quiche/src/quiche/quic/core/quic_versions.h" 20 21 namespace net { 22 23 class HttpStreamKey; 24 class QuicSessionAliasKey; 25 26 // Handles QUIC session attempts for HttpStreamPool::AttemptManager. Owned by an 27 // AttemptManager. 28 class HttpStreamPool::QuicTask : public QuicSessionAttempt::Delegate { 29 public: 30 // `manager` must outlive `this`. 31 QuicTask(AttemptManager* manager, quic::ParsedQuicVersion quic_version); 32 33 QuicTask(const QuicTask&) = delete; 34 QuicTask& operator=(const QuicTask&) = delete; 35 36 ~QuicTask() override; 37 38 // Attempts QUIC session(s). Looks up available QUIC endpoints from 39 // `manager_`'s service endpoints results and `quic_version_`. 40 void MaybeAttempt(); 41 42 // QuicSessionAttempt::Delegate implementation. 43 QuicSessionPool* GetQuicSessionPool() override; 44 const QuicSessionAliasKey& GetKey() override; 45 const NetLogWithSource& GetNetLog() override; 46 47 // Retrieves information on the current state of `this` as a base::Value. 48 base::Value::Dict GetInfoAsValue() const; 49 50 // Returns the first non-pending result of a QUIC session attempt start, if 51 // any. Never returns ERR_IO_PENDING. start_result()52 std::optional<int> start_result() const { return start_result_; } 53 54 private: 55 const HttpStreamKey& stream_key() const; 56 57 HostResolver::ServiceEndpointRequest* service_endpoint_request(); 58 59 QuicSessionPool* quic_session_pool(); 60 61 // Returns a QUIC endpoint to make a connection attempt. See the comments in 62 // QuicSessionPool::SelectQuicVersion() for the criteria to select a QUIC 63 // endpoint. 64 std::optional<QuicEndpoint> GetQuicEndpointToAttempt(); 65 std::optional<QuicEndpoint> GetQuicEndpointFromServiceEndpoint( 66 const ServiceEndpoint& service_endpoint, 67 bool svcb_optional); 68 std::optional<IPEndPoint> GetPreferredIPEndPoint( 69 const std::vector<IPEndPoint>& ip_endpoints); 70 71 void OnSessionAttemptComplete(int rv); 72 73 const raw_ptr<AttemptManager> manager_; 74 const quic::ParsedQuicVersion quic_version_; 75 const NetLogWithSource net_log_; 76 77 std::optional<int> start_result_; 78 79 // TODO(crbug.com/346835898): Support multiple attempts. 80 std::unique_ptr<QuicSessionAttempt> session_attempt_; 81 82 base::WeakPtrFactory<QuicTask> weak_ptr_factory_{this}; 83 }; 84 85 } // namespace net 86 87 #endif // NET_HTTP_HTTP_STREAM_POOL_QUIC_TASK_H_ 88