File: http_stream_pool_tcp_based_attempt.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (99 lines) | stat: -rw-r--r-- 3,229 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef NET_HTTP_HTTP_STREAM_POOL_TCP_BASED_ATTEMPT_H_
#define NET_HTTP_HTTP_STREAM_POOL_TCP_BASED_ATTEMPT_H_

#include <memory>
#include <optional>

#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/types/expected.h"
#include "base/values.h"
#include "net/base/completion_once_callback.h"
#include "net/base/ip_endpoint.h"
#include "net/base/tracing.h"
#include "net/http/http_stream_pool.h"
#include "net/socket/stream_attempt.h"
#include "net/socket/stream_socket_close_reason.h"
#include "net/socket/tls_stream_attempt.h"

namespace net {

// Represents a TCP based attempt.
class HttpStreamPool::TcpBasedAttempt : public TlsStreamAttempt::Delegate {
 public:
  TcpBasedAttempt(AttemptManager* manager,
                  bool using_tls,
                  IPEndPoint ip_endpoint);

  TcpBasedAttempt(const TcpBasedAttempt&) = delete;
  TcpBasedAttempt& operator=(const TcpBasedAttempt&) = delete;

  ~TcpBasedAttempt() override;

  void Start();

  void SetCancelReason(StreamSocketCloseReason reason);

  StreamAttempt* attempt() { return attempt_.get(); }

  base::TimeTicks start_time() const { return start_time_; }
  base::TimeTicks ssl_config_wait_start_time() const {
    return ssl_config_wait_start_time_;
  }

  const IPEndPoint& ip_endpoint() const { return attempt_->ip_endpoint(); }

  bool is_slow() const { return is_slow_; }

  // Set to true when the attempt is aborted. When true, the attempt will fail
  // but not be considered as an actual failure.
  bool is_aborted() const { return is_aborted_; }

  // TlsStreamAttempt::Delegate implementation:
  void OnTcpHandshakeComplete() override;
  int WaitForSSLConfigReady(CompletionOnceCallback callback) override;
  base::expected<SSLConfig, TlsStreamAttempt::GetSSLConfigError> GetSSLConfig()
      override;

  bool IsWaitingSSLConfig() const {
    return !ssl_config_waiting_callback_.is_null();
  }

  // Transfers `ssl_config_waiting_callback_` when `this` is waiting for
  // SSLConfig.
  std::optional<CompletionOnceCallback> MaybeTakeSSLConfigWaitingCallback();

  base::Value::Dict GetInfoAsValue() const;

 private:
  void OnAttemptSlow();
  void OnAttemptComplete(int rv);

  const raw_ptr<AttemptManager> manager_;
  const perfetto::Track track_;
  const perfetto::Flow flow_;
  std::unique_ptr<StreamAttempt> attempt_;
  base::TimeTicks start_time_;
  std::optional<int> result_;
  std::optional<StreamSocketCloseReason> cancel_reason_;
  // Timer to start a next attempt. When fired, `this` is treated as a slow
  // attempt but `this` is not timed out yet.
  base::OneShotTimer slow_timer_;
  // Set to true when `slow_timer_` is fired. See the comment of `slow_timer_`.
  bool is_slow_ = false;
  // Set to true when `this` and `attempt_` should abort. Currently used to
  // handle ECH failure.
  bool is_aborted_ = false;
  base::TimeTicks ssl_config_wait_start_time_;
  CompletionOnceCallback ssl_config_waiting_callback_;

  base::WeakPtrFactory<TcpBasedAttempt> weak_ptr_factory_{this};
};

}  // namespace net

#endif  // NET_HTTP_HTTP_STREAM_POOL_TCP_BASED_ATTEMPT_H_